From f368e4be688937181903183004592c87eb73fa6d Mon Sep 17 00:00:00 2001 From: "Yuki Sonoda (Yugui)" Date: Wed, 16 Jul 2014 21:55:24 +0900 Subject: [PATCH 1/5] Fixes golint errors in pkg/health --- pkg/health/health.go | 12 +++++++++--- pkg/health/health_check.go | 4 ++++ pkg/health/health_check_test.go | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/health/health.go b/pkg/health/health.go index 9d986d36771..e7a87283047 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -22,18 +22,25 @@ import ( "github.com/golang/glog" ) +// Status is a enum type which describes a health status of a container. type Status int +// These are the valid values of type Status. const ( Healthy Status = iota Unhealthy Unknown ) +// HTTPGetInterface is an abstract interface for testability. It abstracts the interface of http.Client.Get. type HTTPGetInterface interface { Get(url string) (*http.Response, error) } +// Check checks if GET request to the url succeeds. +// If the HTTP response code is successful, it returns Healthy. +// If the HTTP response code is unsuccessful, it returns Unhealthy. +// And it return Unknown and err if the HTTP communication itself fails. func Check(url string, client HTTPGetInterface) (Status, error) { res, err := client.Get(url) if res.Body != nil { @@ -44,8 +51,7 @@ func Check(url string, client HTTPGetInterface) (Status, error) { } if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest { return Healthy, nil - } else { - glog.V(1).Infof("Health check failed for %s, Response: %v", url, *res) - return Unhealthy, nil } + glog.V(1).Infof("Health check failed for %s, Response: %v", url, *res) + return Unhealthy, nil } diff --git a/pkg/health/health_check.go b/pkg/health/health_check.go index 695559e755c..50318e3648b 100644 --- a/pkg/health/health_check.go +++ b/pkg/health/health_check.go @@ -25,6 +25,7 @@ import ( "github.com/golang/glog" ) +// HealthChecker hides implementation details of how to check if the container is healthy. type HealthChecker interface { HealthCheck(container api.Container) (Status, error) } @@ -45,6 +46,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) (Status, error) { checker, ok := m.checkers[container.LivenessProbe.Type] if !ok || checker == nil { @@ -69,6 +72,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) (Status, error) { params := container.LivenessProbe.HTTPGet if params == nil { diff --git a/pkg/health/health_check_test.go b/pkg/health/health_check_test.go index 17dc3612466..51aa607770d 100644 --- a/pkg/health/health_check_test.go +++ b/pkg/health/health_check_test.go @@ -23,6 +23,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" ) +// fakeHTTPClient is a face implementation of HTTPGetInterface. type fakeHTTPClient struct { req string res http.Response From 1395b0fbf0b3b0e4980675613d441d1b889622cc Mon Sep 17 00:00:00 2001 From: "Yuki Sonoda (Yugui)" Date: Wed, 16 Jul 2014 21:55:39 +0900 Subject: [PATCH 2/5] Fixes golint errors in pkg/healthz --- pkg/healthz/healthz.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/healthz/healthz.go b/pkg/healthz/healthz.go index 1f71bb88579..7671fed52c9 100644 --- a/pkg/healthz/healthz.go +++ b/pkg/healthz/healthz.go @@ -30,6 +30,7 @@ func handleHealthz(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok")) } +// InstallHandler registers a handler for health checking on the path "/healthz" to mux. func InstallHandler(mux *http.ServeMux) { mux.HandleFunc("/healthz", handleHealthz) } From df9da65939fda9370cdc47ff90e32fe4d4c0dfb4 Mon Sep 17 00:00:00 2001 From: "Yuki Sonoda (Yugui)" Date: Wed, 16 Jul 2014 22:05:06 +0900 Subject: [PATCH 3/5] Rename a function according to go convention --- pkg/health/health_check.go | 4 ++-- pkg/kubelet/kubelet.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/health/health_check.go b/pkg/health/health_check.go index 50318e3648b..c693d065d32 100644 --- a/pkg/health/health_check.go +++ b/pkg/health/health_check.go @@ -30,8 +30,8 @@ type HealthChecker interface { HealthCheck(container api.Container) (Status, error) } -// MakeHealthChecker creates a new HealthChecker. -func MakeHealthChecker() HealthChecker { +// NewHealthChecker creates a new HealthChecker which supports multiple types of liveness probes. +func NewHealthChecker() HealthChecker { return &MuxHealthChecker{ checkers: map[string]HealthChecker{ "http": &HTTPHealthChecker{ diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 24c2c62cf20..04cda521468 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -139,7 +139,7 @@ func (kl *Kubelet) RunKubelet(dockerEndpoint, configPath, manifestURL, etcdServe } go util.Forever(func() { s.ListenAndServe() }, 0) } - kl.HealthChecker = health.MakeHealthChecker() + kl.HealthChecker = health.NewHealthChecker() kl.syncLoop(updateChannel, kl) } From 5e31ca3b275b6c0ab2a42fa1d270fef15d08945d Mon Sep 17 00:00:00 2001 From: Yuki Yugui Sonoda Date: Thu, 17 Jul 2014 12:27:58 +0900 Subject: [PATCH 4/5] Correct godoc messages according to review comments --- pkg/health/health.go | 9 ++++----- pkg/health/health_check.go | 3 ++- pkg/health/health_check_test.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/health/health.go b/pkg/health/health.go index e7a87283047..7ea0faf1b25 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -22,10 +22,9 @@ import ( "github.com/golang/glog" ) -// Status is a enum type which describes a health status of a container. type Status int -// These are the valid values of type Status. +// Status takes only one of values of these constants. const ( Healthy Status = iota Unhealthy @@ -37,10 +36,10 @@ type HTTPGetInterface interface { Get(url string) (*http.Response, error) } -// Check checks if GET request to the url succeeds. -// If the HTTP response code is successful, it returns Healthy. +// Check checks if a GET request to the url succeeds. +// If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Healthy. // If the HTTP response code is unsuccessful, it returns Unhealthy. -// And it return Unknown and err if the HTTP communication itself fails. +// It returns Unknown and err if the HTTP communication itself fails. func Check(url string, client HTTPGetInterface) (Status, error) { res, err := client.Get(url) if res.Body != nil { diff --git a/pkg/health/health_check.go b/pkg/health/health_check.go index c693d065d32..ba97f8efcae 100644 --- a/pkg/health/health_check.go +++ b/pkg/health/health_check.go @@ -25,7 +25,7 @@ import ( "github.com/golang/glog" ) -// HealthChecker hides implementation details of how to check if the container is healthy. +// HealthChecker defines an abstract interface for checking container health. type HealthChecker interface { HealthCheck(container api.Container) (Status, error) } @@ -48,6 +48,7 @@ type MuxHealthChecker struct { // HealthCheck delegates the health-checking of the container to one of the bundled implementations. // It chooses an implementation according to container.LivenessProbe.Type. +// If there is no matching healthc checker it returns Unknown, nil. func (m *MuxHealthChecker) HealthCheck(container api.Container) (Status, error) { checker, ok := m.checkers[container.LivenessProbe.Type] if !ok || checker == nil { diff --git a/pkg/health/health_check_test.go b/pkg/health/health_check_test.go index 51aa607770d..4f4be7293c7 100644 --- a/pkg/health/health_check_test.go +++ b/pkg/health/health_check_test.go @@ -23,7 +23,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" ) -// fakeHTTPClient is a face implementation of HTTPGetInterface. +// fakeHTTPClient is a fake implementation of HTTPGetInterface. type fakeHTTPClient struct { req string res http.Response From e0d749f9524c7d3e09efc15d70705a10fb975f65 Mon Sep 17 00:00:00 2001 From: Yuki Yugui Sonoda Date: Fri, 18 Jul 2014 14:13:55 +0900 Subject: [PATCH 5/5] fix typo --- pkg/health/health_check.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/health/health_check.go b/pkg/health/health_check.go index ba97f8efcae..8820b92c5fd 100644 --- a/pkg/health/health_check.go +++ b/pkg/health/health_check.go @@ -48,7 +48,7 @@ type MuxHealthChecker struct { // HealthCheck delegates the health-checking of the container to one of the bundled implementations. // It chooses an implementation according to container.LivenessProbe.Type. -// If there is no matching healthc checker it returns Unknown, nil. +// If there is no matching health checker it returns Unknown, nil. func (m *MuxHealthChecker) HealthCheck(container api.Container) (Status, error) { checker, ok := m.checkers[container.LivenessProbe.Type] if !ok || checker == nil {