Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes golint for pkg/probe #68582

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions hack/.golint_failures
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,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
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions pkg/probe/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/probe/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,42 @@ 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)
}

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

// DoHTTPProbe checks if a GET request to the url succeeds.
// 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.
Expand Down
4 changes: 4 additions & 0 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
7 changes: 5 additions & 2 deletions pkg/probe/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/core/componentstatus/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Server struct {
EnableHTTPS bool
TLSConfig *tls.Config
Validate ValidatorFn
Prober httpprober.HTTPProber
Prober httpprober.Prober
Once sync.Once
}

Expand Down