mirror of https://github.com/k3s-io/k3s
Merge pull request #419 from brendandburns/health
Add a /healthz handler to the kubelet serverpull/6/head
commit
fa7e5f4cf4
|
@ -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
|
|
@ -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"))
|
||||
}
|
|
@ -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)),
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue