Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandburns committed Jul 15, 2014
1 parent 9f99767 commit ae17912
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 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
11 changes: 4 additions & 7 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 All @@ -58,10 +59,6 @@ func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
switch {
case u.Path == "/healthz":
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
return
case u.Path == "/container" || u.Path == "/containers":
defer req.Body.Close()
data, err := ioutil.ReadAll(req.Body)
Expand Down Expand Up @@ -109,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 ae17912

Please sign in to comment.