diff --git a/cmd/kubelet/kubelet.go b/cmd/kubelet/kubelet.go index 91e69938bb9..fc558d68f17 100644 --- a/cmd/kubelet/kubelet.go +++ b/cmd/kubelet/kubelet.go @@ -27,6 +27,7 @@ import ( "os/exec" "time" + _ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/coreos/go-etcd/etcd" diff --git a/pkg/kubelet/health_check.go b/pkg/kubelet/health_check.go index 62a015df08d..f784b13979a 100644 --- a/pkg/kubelet/health_check.go +++ b/pkg/kubelet/health_check.go @@ -25,14 +25,17 @@ import ( "github.com/golang/glog" ) +// HealthCheckStatus is an enum type which describes a status of health check. type HealthCheckStatus int +// These are the valid values of HealthCheckStatus. const ( CheckHealthy HealthCheckStatus = 0 CheckUnhealthy HealthCheckStatus = 1 CheckUnknown HealthCheckStatus = 2 ) +// HealthChecker hides implementation details of checking health of containers. type HealthChecker interface { HealthCheck(container api.Container) (HealthCheckStatus, error) } @@ -57,6 +60,8 @@ type MuxHealthChecker struct { checkers map[string]HealthChecker } +// HealthCheck delegates the health-checking of the container to one of the bundled implementations. +// It chooses an implementation according to container.LivenessProbe.Type. func (m *MuxHealthChecker) HealthCheck(container api.Container) (HealthCheckStatus, error) { checker, ok := m.checkers[container.LivenessProbe.Type] if !ok || checker == nil { @@ -81,6 +86,7 @@ func (h *HTTPHealthChecker) findPort(container api.Container, portName string) i return -1 } +// HealthCheck checks if the container is healthy by trying sending HTTP Get requests to the container. func (h *HTTPHealthChecker) HealthCheck(container api.Container) (HealthCheckStatus, error) { params := container.LivenessProbe.HTTPGet if params == nil { diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index ac4ab99ef47..9a89f129931 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -34,7 +34,6 @@ 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,7 +144,7 @@ func (kl *Kubelet) RunKubelet(dockerEndpoint, configPath, manifestURL, etcdServe } if address != "" { glog.Infof("Starting to listen on %s:%d", address, port) - handler := KubeletServer{ + handler := Server{ Kubelet: kl, UpdateChannel: updateChannel, DelegateHandler: http.DefaultServeMux, diff --git a/pkg/kubelet/kubelet_server.go b/pkg/kubelet/kubelet_server.go index adfc13e283e..8dfd68bb909 100644 --- a/pkg/kubelet/kubelet_server.go +++ b/pkg/kubelet/kubelet_server.go @@ -31,8 +31,8 @@ import ( "gopkg.in/v1/yaml" ) -// KubeletServer is a http.Handler which exposes kubelet functionality over HTTP. -type KubeletServer struct { +// Server is a http.Handler which exposes kubelet functionality over HTTP. +type Server struct { Kubelet kubeletInterface UpdateChannel chan<- manifestUpdate DelegateHandler http.Handler @@ -46,11 +46,11 @@ type kubeletInterface interface { GetPodInfo(name string) (api.PodInfo, error) } -func (s *KubeletServer) error(w http.ResponseWriter, err error) { +func (s *Server) error(w http.ResponseWriter, err error) { http.Error(w, fmt.Sprintf("Internal Error: %v", err), http.StatusInternalServerError) } -func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { +func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { defer apiserver.MakeLogged(req, &w).Log() u, err := url.ParseRequestURI(req.RequestURI) @@ -110,7 +110,7 @@ func (s *KubeletServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { } } -func (s *KubeletServer) serveStats(w http.ResponseWriter, req *http.Request) { +func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) { // /stats// components := strings.Split(strings.TrimPrefix(path.Clean(req.URL.Path), "/"), "/") var stats *api.ContainerStats