refactor pkg/probe ProbeRunners to interfaces and move global probers into kubelet field for testability
This commit is contained in:
@@ -28,12 +28,16 @@ import (
|
||||
const defaultHealthyOutput = "ok"
|
||||
|
||||
func New() ExecProber {
|
||||
return ExecProber{}
|
||||
return execProber{}
|
||||
}
|
||||
|
||||
type ExecProber struct{}
|
||||
type ExecProber interface {
|
||||
Probe(e uexec.Cmd) (probe.Result, error)
|
||||
}
|
||||
|
||||
func (pr ExecProber) Probe(e uexec.Cmd) (probe.Result, error) {
|
||||
type execProber struct{}
|
||||
|
||||
func (pr execProber) Probe(e uexec.Cmd) (probe.Result, error) {
|
||||
data, err := e.CombinedOutput()
|
||||
glog.V(4).Infof("health check response: %s", string(data))
|
||||
if err != nil {
|
||||
|
@@ -30,15 +30,19 @@ import (
|
||||
|
||||
func New() HTTPProber {
|
||||
transport := &http.Transport{}
|
||||
return HTTPProber{transport}
|
||||
return httpProber{transport}
|
||||
}
|
||||
|
||||
type HTTPProber struct {
|
||||
type HTTPProber interface {
|
||||
Probe(host string, port int, path string, timeout time.Duration) (probe.Result, error)
|
||||
}
|
||||
|
||||
type httpProber struct {
|
||||
transport *http.Transport
|
||||
}
|
||||
|
||||
// Probe returns a ProbeRunner capable of running an http check.
|
||||
func (pr *HTTPProber) Probe(host string, port int, path string, timeout time.Duration) (probe.Result, error) {
|
||||
func (pr httpProber) Probe(host string, port int, path string, timeout time.Duration) (probe.Result, error) {
|
||||
return DoHTTPProbe(formatURL(host, port, path), &http.Client{Timeout: timeout, Transport: pr.transport})
|
||||
}
|
||||
|
||||
|
@@ -27,12 +27,16 @@ import (
|
||||
)
|
||||
|
||||
func New() TCPProber {
|
||||
return TCPProber{}
|
||||
return tcpProber{}
|
||||
}
|
||||
|
||||
type TCPProber struct{}
|
||||
type TCPProber interface {
|
||||
Probe(host string, port int, timeout time.Duration) (probe.Result, error)
|
||||
}
|
||||
|
||||
func (pr TCPProber) Probe(host string, port int, timeout time.Duration) (probe.Result, error) {
|
||||
type tcpProber struct{}
|
||||
|
||||
func (pr tcpProber) Probe(host string, port int, timeout time.Duration) (probe.Result, error) {
|
||||
return DoTCPProbe(net.JoinHostPort(host, strconv.Itoa(port)), timeout)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user