diff --git a/pkg/healthz/doc.go b/pkg/healthz/doc.go new file mode 100644 index 0000000000..16414f578d --- /dev/null +++ b/pkg/healthz/doc.go @@ -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 diff --git a/pkg/healthz/healthz.go b/pkg/healthz/healthz.go new file mode 100644 index 0000000000..8ae6b97f73 --- /dev/null +++ b/pkg/healthz/healthz.go @@ -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")) +} diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 263f6c89f8..5bf45fcd0c 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -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" @@ -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)), diff --git a/pkg/kubelet/kubelet_server.go b/pkg/kubelet/kubelet_server.go index 0e6d7cc8fb..adfc13e283 100644 --- a/pkg/kubelet/kubelet_server.go +++ b/pkg/kubelet/kubelet_server.go @@ -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. @@ -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) } }