mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Fix golint for pkg/probe
This change adds comments to exported things and renames the tcp, http, and exec probe interfaces to just be Prober within their namespace. Issue #68026
This commit is contained in:
parent
426ef9d349
commit
b971c3e200
@ -250,10 +250,6 @@ pkg/master/tunneler
|
|||||||
pkg/printers
|
pkg/printers
|
||||||
pkg/printers/internalversion
|
pkg/printers/internalversion
|
||||||
pkg/printers/storage
|
pkg/printers/storage
|
||||||
pkg/probe
|
|
||||||
pkg/probe/exec
|
|
||||||
pkg/probe/http
|
|
||||||
pkg/probe/tcp
|
|
||||||
pkg/proxy
|
pkg/proxy
|
||||||
pkg/proxy/apis/config
|
pkg/proxy/apis/config
|
||||||
pkg/proxy/apis/config/v1alpha1
|
pkg/proxy/apis/config/v1alpha1
|
||||||
|
@ -46,13 +46,13 @@ const maxProbeRetries = 3
|
|||||||
|
|
||||||
// Prober helps to check the liveness/readiness of a container.
|
// Prober helps to check the liveness/readiness of a container.
|
||||||
type prober struct {
|
type prober struct {
|
||||||
exec execprobe.ExecProber
|
exec execprobe.Prober
|
||||||
// probe types needs different httprobe instances so they don't
|
// probe types needs different httprobe instances so they don't
|
||||||
// share a connection pool which can cause collsions to the
|
// share a connection pool which can cause collsions to the
|
||||||
// same host:port and transient failures. See #49740.
|
// same host:port and transient failures. See #49740.
|
||||||
readinessHttp httprobe.HTTPProber
|
readinessHttp httprobe.Prober
|
||||||
livenessHttp httprobe.HTTPProber
|
livenessHttp httprobe.Prober
|
||||||
tcp tcprobe.TCPProber
|
tcp tcprobe.Prober
|
||||||
runner kubecontainer.ContainerCommandRunner
|
runner kubecontainer.ContainerCommandRunner
|
||||||
|
|
||||||
refManager *kubecontainer.RefManager
|
refManager *kubecontainer.RefManager
|
||||||
|
@ -23,16 +23,21 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New() ExecProber {
|
// New creates a Prober.
|
||||||
|
func New() Prober {
|
||||||
return execProber{}
|
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)
|
Probe(e exec.Cmd) (probe.Result, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type execProber struct{}
|
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) {
|
func (pr execProber) Probe(e exec.Cmd) (probe.Result, string, error) {
|
||||||
data, err := e.CombinedOutput()
|
data, err := e.CombinedOutput()
|
||||||
glog.V(4).Infof("Exec probe response: %q", string(data))
|
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 ok {
|
||||||
if exit.ExitStatus() == 0 {
|
if exit.ExitStatus() == 0 {
|
||||||
return probe.Success, string(data), nil
|
return probe.Success, string(data), nil
|
||||||
} else {
|
|
||||||
return probe.Failure, string(data), nil
|
|
||||||
}
|
}
|
||||||
|
return probe.Failure, string(data), nil
|
||||||
}
|
}
|
||||||
return probe.Unknown, "", err
|
return probe.Unknown, "", err
|
||||||
}
|
}
|
||||||
|
@ -31,18 +31,20 @@ import (
|
|||||||
"github.com/golang/glog"
|
"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}
|
tlsConfig := &tls.Config{InsecureSkipVerify: true}
|
||||||
return NewWithTLSConfig(tlsConfig)
|
return NewWithTLSConfig(tlsConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWithTLSConfig takes tls config as parameter.
|
// 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})
|
transport := utilnet.SetTransportDefaults(&http.Transport{TLSClientConfig: config, DisableKeepAlives: true})
|
||||||
return httpProber{transport}
|
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)
|
Probe(url *url.URL, headers http.Header, timeout time.Duration) (probe.Result, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,12 +52,13 @@ type httpProber struct {
|
|||||||
transport *http.Transport
|
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) {
|
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})
|
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)
|
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 successful (i.e. 400 > code >= 200), it returns Success.
|
||||||
// If the HTTP response code is unsuccessful or HTTP communication fails, it returns Failure.
|
// 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.
|
// 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)
|
req, err := http.NewRequest("GET", url.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Convert errors into failures to catch timeouts.
|
// Convert errors into failures to catch timeouts.
|
||||||
|
@ -16,10 +16,14 @@ limitations under the License.
|
|||||||
|
|
||||||
package probe
|
package probe
|
||||||
|
|
||||||
|
// Result is a string used to handle the results for probing container readiness/livenss
|
||||||
type Result string
|
type Result string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// Success Result
|
||||||
Success Result = "success"
|
Success Result = "success"
|
||||||
|
// Failure Result
|
||||||
Failure Result = "failure"
|
Failure Result = "failure"
|
||||||
|
// Unknown Result
|
||||||
Unknown Result = "unknown"
|
Unknown Result = "unknown"
|
||||||
)
|
)
|
||||||
|
@ -26,16 +26,19 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New() TCPProber {
|
// New creates Prober.
|
||||||
|
func New() Prober {
|
||||||
return tcpProber{}
|
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)
|
Probe(host string, port int, timeout time.Duration) (probe.Result, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tcpProber struct{}
|
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) {
|
func (pr tcpProber) Probe(host string, port int, timeout time.Duration) (probe.Result, string, error) {
|
||||||
return DoTCPProbe(net.JoinHostPort(host, strconv.Itoa(port)), timeout)
|
return DoTCPProbe(net.JoinHostPort(host, strconv.Itoa(port)), timeout)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ type Server struct {
|
|||||||
EnableHTTPS bool
|
EnableHTTPS bool
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
Validate ValidatorFn
|
Validate ValidatorFn
|
||||||
Prober httpprober.HTTPProber
|
Prober httpprober.Prober
|
||||||
Once sync.Once
|
Once sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user