Skip to content

Commit

Permalink
Merge pull request kubernetes#419 from brendandburns/health
Browse files Browse the repository at this point in the history
Add a /healthz handler to the kubelet server
  • Loading branch information
lavalamp committed Jul 15, 2014
2 parents dcbb309 + ae17912 commit fa7e5f4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
20 changes: 20 additions & 0 deletions pkg/healthz/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package healthz implements basic http server health checking.
// Usage:
// import _ "healthz" registers a handler on the path '/healthz', that serves 200s
package healthz
31 changes: 31 additions & 0 deletions pkg/healthz/healthz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package healthz

import (
"net/http"
)

func init() {
http.HandleFunc("/healthz", handleHealthz)
}

func handleHealthz(w http.ResponseWriter, r *http.Request) {
// TODO Support user supplied health functions too.
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
}
6 changes: 4 additions & 2 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/coreos/go-etcd/etcd"
Expand Down Expand Up @@ -145,8 +146,9 @@ func (kl *Kubelet) RunKubelet(dockerEndpoint, configPath, manifestURL, etcdServe
if address != "" {
glog.Infof("Starting to listen on %s:%d", address, port)
handler := KubeletServer{
Kubelet: kl,
UpdateChannel: updateChannel,
Kubelet: kl,
UpdateChannel: updateChannel,
DelegateHandler: http.DefaultServeMux,
}
s := &http.Server{
Addr: net.JoinHostPort(address, strconv.FormatUint(uint64(port), 10)),
Expand Down
7 changes: 4 additions & 3 deletions pkg/kubelet/kubelet_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ import (

// KubeletServer is a http.Handler which exposes kubelet functionality over HTTP.
type KubeletServer struct {
Kubelet kubeletInterface
UpdateChannel chan<- manifestUpdate
Kubelet kubeletInterface
UpdateChannel chan<- manifestUpdate
DelegateHandler http.Handler
}

// kubeletInterface contains all the kubelet methods required by the server.
Expand Down Expand Up @@ -105,7 +106,7 @@ func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
case strings.HasPrefix(u.Path, "/stats"):
s.serveStats(w, req)
default:
http.Error(w, "Not found.", http.StatusNotFound)
s.DelegateHandler.ServeHTTP(w, req)
}
}

Expand Down

0 comments on commit fa7e5f4

Please sign in to comment.