From f368e4be688937181903183004592c87eb73fa6d Mon Sep 17 00:00:00 2001 From: "Yuki Sonoda (Yugui)" Date: Wed, 16 Jul 2014 21:55:24 +0900 Subject: [PATCH] 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