diff --git a/hack/.golint_failures b/hack/.golint_failures index d3fb821d71..55af91ab71 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -264,10 +264,6 @@ pkg/master/tunneler pkg/printers pkg/printers/internalversion pkg/printers/storage -pkg/probe -pkg/probe/exec -pkg/probe/http -pkg/probe/tcp pkg/proxy pkg/proxy/apis/config pkg/proxy/apis/config/v1alpha1 diff --git a/pkg/kubelet/prober/prober.go b/pkg/kubelet/prober/prober.go index d81ee8f377..77cea64603 100644 --- a/pkg/kubelet/prober/prober.go +++ b/pkg/kubelet/prober/prober.go @@ -46,13 +46,13 @@ const maxProbeRetries = 3 // Prober helps to check the liveness/readiness of a container. type prober struct { - exec execprobe.ExecProber + exec execprobe.Prober // probe types needs different httprobe instances so they don't // share a connection pool which can cause collsions to the // same host:port and transient failures. See #49740. - readinessHttp httprobe.HTTPProber - livenessHttp httprobe.HTTPProber - tcp tcprobe.TCPProber + readinessHttp httprobe.Prober + livenessHttp httprobe.Prober + tcp tcprobe.Prober runner kubecontainer.ContainerCommandRunner refManager *kubecontainer.RefManager diff --git a/pkg/probe/exec/exec.go b/pkg/probe/exec/exec.go index 817492a609..5901e35a6a 100644 --- a/pkg/probe/exec/exec.go +++ b/pkg/probe/exec/exec.go @@ -23,16 +23,21 @@ import ( "github.com/golang/glog" ) -func New() ExecProber { +// New creates a Prober. +func New() Prober { return execProber{} } -type ExecProber interface { +// Prober is an interface defining the Probe object for container readiness/liveness checks. +type Prober interface { Probe(e exec.Cmd) (probe.Result, string, error) } type execProber struct{} +// Probe executes a command to check the liveness/readiness of container +// from executing a command. Returns the Result status, command output, and +// errors if any. func (pr execProber) Probe(e exec.Cmd) (probe.Result, string, error) { data, err := e.CombinedOutput() glog.V(4).Infof("Exec probe response: %q", string(data)) @@ -41,9 +46,8 @@ func (pr execProber) Probe(e exec.Cmd) (probe.Result, string, error) { if ok { if exit.ExitStatus() == 0 { return probe.Success, string(data), nil - } else { - return probe.Failure, string(data), nil } + return probe.Failure, string(data), nil } return probe.Unknown, "", err } diff --git a/pkg/probe/http/http.go b/pkg/probe/http/http.go index b9821be05f..11bbddfa8b 100644 --- a/pkg/probe/http/http.go +++ b/pkg/probe/http/http.go @@ -31,18 +31,20 @@ import ( "github.com/golang/glog" ) -func New() HTTPProber { +// New creates Prober that will skip TLS verification while probing. +func New() Prober { tlsConfig := &tls.Config{InsecureSkipVerify: true} return NewWithTLSConfig(tlsConfig) } // NewWithTLSConfig takes tls config as parameter. -func NewWithTLSConfig(config *tls.Config) HTTPProber { +func NewWithTLSConfig(config *tls.Config) Prober { transport := utilnet.SetTransportDefaults(&http.Transport{TLSClientConfig: config, DisableKeepAlives: true}) return httpProber{transport} } -type HTTPProber interface { +// Prober is an interface that defines the Probe function for doing HTTP readiness/liveness checks. +type Prober interface { Probe(url *url.URL, headers http.Header, timeout time.Duration) (probe.Result, string, error) } @@ -50,12 +52,13 @@ type httpProber struct { transport *http.Transport } -// Probe returns a ProbeRunner capable of running an http check. +// Probe returns a ProbeRunner capable of running an HTTP check. func (pr httpProber) Probe(url *url.URL, headers http.Header, timeout time.Duration) (probe.Result, string, error) { return DoHTTPProbe(url, headers, &http.Client{Timeout: timeout, Transport: pr.transport}) } -type HTTPGetInterface interface { +// GetHTTPInterface is an interface for making HTTP requests, that returns a response and error. +type GetHTTPInterface interface { Do(req *http.Request) (*http.Response, error) } @@ -63,7 +66,7 @@ type HTTPGetInterface interface { // If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Success. // If the HTTP response code is unsuccessful or HTTP communication fails, it returns Failure. // This is exported because some other packages may want to do direct HTTP probes. -func DoHTTPProbe(url *url.URL, headers http.Header, client HTTPGetInterface) (probe.Result, string, error) { +func DoHTTPProbe(url *url.URL, headers http.Header, client GetHTTPInterface) (probe.Result, string, error) { req, err := http.NewRequest("GET", url.String(), nil) if err != nil { // Convert errors into failures to catch timeouts. diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index ebbb607c46..d57bf43874 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -16,10 +16,14 @@ limitations under the License. package probe +// Result is a string used to handle the results for probing container readiness/livenss type Result string const ( + // Success Result Success Result = "success" + // Failure Result Failure Result = "failure" + // Unknown Result Unknown Result = "unknown" ) diff --git a/pkg/probe/tcp/tcp.go b/pkg/probe/tcp/tcp.go index cce3be9935..cf18eb1a5b 100644 --- a/pkg/probe/tcp/tcp.go +++ b/pkg/probe/tcp/tcp.go @@ -26,16 +26,19 @@ import ( "github.com/golang/glog" ) -func New() TCPProber { +// New creates Prober. +func New() Prober { return tcpProber{} } -type TCPProber interface { +// Prober is an interface that defines the Probe function for doing TCP readiness/liveness checks. +type Prober interface { Probe(host string, port int, timeout time.Duration) (probe.Result, string, error) } type tcpProber struct{} +// Probe returns a ProbeRunner capable of running an TCP check. func (pr tcpProber) Probe(host string, port int, timeout time.Duration) (probe.Result, string, error) { return DoTCPProbe(net.JoinHostPort(host, strconv.Itoa(port)), timeout) } diff --git a/pkg/registry/core/componentstatus/validator.go b/pkg/registry/core/componentstatus/validator.go index ae5ff62be6..09c0f6a34c 100644 --- a/pkg/registry/core/componentstatus/validator.go +++ b/pkg/registry/core/componentstatus/validator.go @@ -45,7 +45,7 @@ type Server struct { EnableHTTPS bool TLSConfig *tls.Config Validate ValidatorFn - Prober httpprober.HTTPProber + Prober httpprober.Prober Once sync.Once }