Merge pull request #68582 from jonfriesen/master

Fixes golint for pkg/probe
pull/58/head
k8s-ci-robot 2018-10-09 21:14:46 -07:00 committed by GitHub
commit 85a8f97cb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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.

View File

@ -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"
)

View File

@ -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)
}

View File

@ -45,7 +45,7 @@ type Server struct {
EnableHTTPS bool
TLSConfig *tls.Config
Validate ValidatorFn
Prober httpprober.HTTPProber
Prober httpprober.Prober
Once sync.Once
}