mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	rename probe.Status to probe.Result.
This commit is contained in:
		@@ -96,7 +96,7 @@ func (fakeKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.Pod
 | 
				
			|||||||
	return r, nil
 | 
						return r, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (fakeKubeletClient) HealthCheck(host string) (probe.Status, error) {
 | 
					func (fakeKubeletClient) HealthCheck(host string) (probe.Result, error) {
 | 
				
			||||||
	return probe.Success, nil
 | 
						return probe.Success, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,7 @@ type validator struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: can this use pkg/probe/http
 | 
					// TODO: can this use pkg/probe/http
 | 
				
			||||||
func (s *Server) check(client httpGet) (probe.Status, string, error) {
 | 
					func (s *Server) check(client httpGet) (probe.Result, string, error) {
 | 
				
			||||||
	resp, err := client.Get("http://" + net.JoinHostPort(s.Addr, strconv.Itoa(s.Port)) + s.Path)
 | 
						resp, err := client.Get("http://" + net.JoinHostPort(s.Addr, strconv.Itoa(s.Port)) + s.Path)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return probe.Unknown, "", err
 | 
							return probe.Unknown, "", err
 | 
				
			||||||
@@ -66,7 +66,7 @@ func (s *Server) check(client httpGet) (probe.Status, string, error) {
 | 
				
			|||||||
type ServerStatus struct {
 | 
					type ServerStatus struct {
 | 
				
			||||||
	Component  string       `json:"component,omitempty"`
 | 
						Component  string       `json:"component,omitempty"`
 | 
				
			||||||
	Health     string       `json:"health,omitempty"`
 | 
						Health     string       `json:"health,omitempty"`
 | 
				
			||||||
	HealthCode probe.Status `json:"healthCode,omitempty"`
 | 
						HealthCode probe.Result `json:"healthCode,omitempty"`
 | 
				
			||||||
	Msg        string       `json:"msg,omitempty"`
 | 
						Msg        string       `json:"msg,omitempty"`
 | 
				
			||||||
	Err        string       `json:"err,omitempty"`
 | 
						Err        string       `json:"err,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,7 +54,7 @@ func TestValidate(t *testing.T) {
 | 
				
			|||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		err            error
 | 
							err            error
 | 
				
			||||||
		data           string
 | 
							data           string
 | 
				
			||||||
		expectedStatus probe.Status
 | 
							expectedStatus probe.Result
 | 
				
			||||||
		code           int
 | 
							code           int
 | 
				
			||||||
		expectErr      bool
 | 
							expectErr      bool
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,7 +41,7 @@ type KubeletClient interface {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// KubeletHealthchecker is an interface for healthchecking kubelets
 | 
					// KubeletHealthchecker is an interface for healthchecking kubelets
 | 
				
			||||||
type KubeletHealthChecker interface {
 | 
					type KubeletHealthChecker interface {
 | 
				
			||||||
	HealthCheck(host string) (probe.Status, error)
 | 
						HealthCheck(host string) (probe.Result, error)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// PodInfoGetter is an interface for things that can get information about a pod's containers.
 | 
					// PodInfoGetter is an interface for things that can get information about a pod's containers.
 | 
				
			||||||
@@ -134,7 +134,7 @@ func (c *HTTPKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.
 | 
				
			|||||||
	return status, nil
 | 
						return status, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *HTTPKubeletClient) HealthCheck(host string) (probe.Status, error) {
 | 
					func (c *HTTPKubeletClient) HealthCheck(host string) (probe.Result, error) {
 | 
				
			||||||
	return httprobe.DoHTTPProbe(fmt.Sprintf("%s/healthz", c.url(host)), c.Client)
 | 
						return httprobe.DoHTTPProbe(fmt.Sprintf("%s/healthz", c.url(host)), c.Client)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -148,6 +148,6 @@ func (c FakeKubeletClient) GetPodStatus(host, podNamespace string, podID string)
 | 
				
			|||||||
	return api.PodStatusResult{}, errors.New("Not Implemented")
 | 
						return api.PodStatusResult{}, errors.New("Not Implemented")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c FakeKubeletClient) HealthCheck(host string) (probe.Status, error) {
 | 
					func (c FakeKubeletClient) HealthCheck(host string) (probe.Result, error) {
 | 
				
			||||||
	return probe.Unknown, errors.New("Not Implemented")
 | 
						return probe.Unknown, errors.New("Not Implemented")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -102,7 +102,7 @@ func (m *FakeNodeHandler) Update(node *api.Node) (*api.Node, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// FakeKubeletClient is a fake implementation of KubeletClient.
 | 
					// FakeKubeletClient is a fake implementation of KubeletClient.
 | 
				
			||||||
type FakeKubeletClient struct {
 | 
					type FakeKubeletClient struct {
 | 
				
			||||||
	Status probe.Status
 | 
						Status probe.Result
 | 
				
			||||||
	Err    error
 | 
						Err    error
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -110,7 +110,7 @@ func (c *FakeKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.
 | 
				
			|||||||
	return api.PodStatusResult{}, errors.New("Not Implemented")
 | 
						return api.PodStatusResult{}, errors.New("Not Implemented")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *FakeKubeletClient) HealthCheck(host string) (probe.Status, error) {
 | 
					func (c *FakeKubeletClient) HealthCheck(host string) (probe.Result, error) {
 | 
				
			||||||
	return c.Status, c.Err
 | 
						return c.Status, c.Err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1446,7 +1446,7 @@ func (kl *Kubelet) GetPodStatus(podFullName string, uid types.UID) (api.PodStatu
 | 
				
			|||||||
	return podStatus, err
 | 
						return podStatus, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (kl *Kubelet) probeLiveness(podFullName string, podUID types.UID, status api.PodStatus, container api.Container, dockerContainer *docker.APIContainers) (healthStatus probe.Status, err error) {
 | 
					func (kl *Kubelet) probeLiveness(podFullName string, podUID types.UID, status api.PodStatus, container api.Container, dockerContainer *docker.APIContainers) (healthStatus probe.Result, err error) {
 | 
				
			||||||
	// Give the container 60 seconds to start up.
 | 
						// Give the container 60 seconds to start up.
 | 
				
			||||||
	if container.LivenessProbe == nil {
 | 
						if container.LivenessProbe == nil {
 | 
				
			||||||
		return probe.Success, nil
 | 
							return probe.Success, nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,7 @@ var (
 | 
				
			|||||||
	tcprober   = tcprobe.New()
 | 
						tcprober   = tcprobe.New()
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (kl *Kubelet) probeContainer(p *api.Probe, podFullName string, podUID types.UID, status api.PodStatus, container api.Container) (probe.Status, error) {
 | 
					func (kl *Kubelet) probeContainer(p *api.Probe, podFullName string, podUID types.UID, status api.PodStatus, container api.Container) (probe.Result, error) {
 | 
				
			||||||
	var timeout time.Duration
 | 
						var timeout time.Duration
 | 
				
			||||||
	secs := container.LivenessProbe.TimeoutSeconds
 | 
						secs := container.LivenessProbe.TimeoutSeconds
 | 
				
			||||||
	if secs > 0 {
 | 
						if secs > 0 {
 | 
				
			||||||
@@ -47,7 +47,6 @@ func (kl *Kubelet) probeContainer(p *api.Probe, podFullName string, podUID types
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		timeout = 1 * time.Second
 | 
							timeout = 1 * time.Second
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if p.Exec != nil {
 | 
						if p.Exec != nil {
 | 
				
			||||||
		return execprober.Probe(kl.newExecInContainer(podFullName, podUID, container))
 | 
							return execprober.Probe(kl.newExecInContainer(podFullName, podUID, container))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,7 +33,7 @@ func New() ExecProber {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type ExecProber struct{}
 | 
					type ExecProber struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (pr ExecProber) Probe(e uexec.Cmd) (probe.Status, error) {
 | 
					func (pr ExecProber) Probe(e uexec.Cmd) (probe.Result, error) {
 | 
				
			||||||
	data, err := e.CombinedOutput()
 | 
						data, err := e.CombinedOutput()
 | 
				
			||||||
	glog.V(4).Infof("health check response: %s", string(data))
 | 
						glog.V(4).Infof("health check response: %s", string(data))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,7 +35,7 @@ func (f *FakeCmd) CombinedOutput() ([]byte, error) {
 | 
				
			|||||||
func (f *FakeCmd) SetDir(dir string) {}
 | 
					func (f *FakeCmd) SetDir(dir string) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type healthCheckTest struct {
 | 
					type healthCheckTest struct {
 | 
				
			||||||
	expectedStatus probe.Status
 | 
						expectedStatus probe.Result
 | 
				
			||||||
	expectError    bool
 | 
						expectError    bool
 | 
				
			||||||
	output         []byte
 | 
						output         []byte
 | 
				
			||||||
	err            error
 | 
						err            error
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,7 +38,7 @@ type HTTPProber struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Probe returns a ProbeRunner capable of running an http check.
 | 
					// Probe returns a ProbeRunner capable of running an http check.
 | 
				
			||||||
func (pr *HTTPProber) Probe(host string, port int, path string, timeout time.Duration) (probe.Status, 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})
 | 
						return DoHTTPProbe(formatURL(host, port, path), &http.Client{Timeout: timeout, Transport: pr.transport})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -50,7 +50,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 string, client HTTPGetInterface) (probe.Status, error) {
 | 
					func DoHTTPProbe(url string, client HTTPGetInterface) (probe.Result, error) {
 | 
				
			||||||
	res, err := client.Get(url)
 | 
						res, err := client.Get(url)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		glog.V(1).Infof("HTTP probe error: %v", err)
 | 
							glog.V(1).Infof("HTTP probe error: %v", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,7 +54,7 @@ func TestHTTPProbeChecker(t *testing.T) {
 | 
				
			|||||||
	prober := New()
 | 
						prober := New()
 | 
				
			||||||
	testCases := []struct {
 | 
						testCases := []struct {
 | 
				
			||||||
		handler func(w http.ResponseWriter)
 | 
							handler func(w http.ResponseWriter)
 | 
				
			||||||
		health  probe.Status
 | 
							health  probe.Result
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		// The probe will be filled in below.  This is primarily testing that an HTTP GET happens.
 | 
							// The probe will be filled in below.  This is primarily testing that an HTTP GET happens.
 | 
				
			||||||
		{handleReq(http.StatusOK), probe.Success},
 | 
							{handleReq(http.StatusOK), probe.Success},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,16 +16,16 @@ limitations under the License.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package probe
 | 
					package probe
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Status int
 | 
					type Result int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Status values must be one of these constants.
 | 
					// Status values must be one of these constants.
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	Success Status = iota
 | 
						Success Result = iota
 | 
				
			||||||
	Failure
 | 
						Failure
 | 
				
			||||||
	Unknown
 | 
						Unknown
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s Status) String() string {
 | 
					func (s Result) String() string {
 | 
				
			||||||
	switch s {
 | 
						switch s {
 | 
				
			||||||
	case Success:
 | 
						case Success:
 | 
				
			||||||
		return "success"
 | 
							return "success"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,7 @@ func New() TCPProber {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type TCPProber struct{}
 | 
					type TCPProber struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (pr TCPProber) Probe(host string, port int, timeout time.Duration) (probe.Status, error) {
 | 
					func (pr TCPProber) Probe(host string, port int, timeout time.Duration) (probe.Result, error) {
 | 
				
			||||||
	return DoTCPProbe(net.JoinHostPort(host, strconv.Itoa(port)), timeout)
 | 
						return DoTCPProbe(net.JoinHostPort(host, strconv.Itoa(port)), timeout)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -40,7 +40,7 @@ func (pr TCPProber) Probe(host string, port int, timeout time.Duration) (probe.S
 | 
				
			|||||||
// If the socket can be opened, it returns Success
 | 
					// If the socket can be opened, it returns Success
 | 
				
			||||||
// If the socket fails to open, it returns Failure.
 | 
					// If the socket fails to open, it returns Failure.
 | 
				
			||||||
// This is exported because some other packages may want to do direct TCP probes.
 | 
					// This is exported because some other packages may want to do direct TCP probes.
 | 
				
			||||||
func DoTCPProbe(addr string, timeout time.Duration) (probe.Status, error) {
 | 
					func DoTCPProbe(addr string, timeout time.Duration) (probe.Result, error) {
 | 
				
			||||||
	conn, err := net.DialTimeout("tcp", addr, timeout)
 | 
						conn, err := net.DialTimeout("tcp", addr, timeout)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return probe.Failure, nil
 | 
							return probe.Failure, nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,7 +31,7 @@ import (
 | 
				
			|||||||
func TestTcpHealthChecker(t *testing.T) {
 | 
					func TestTcpHealthChecker(t *testing.T) {
 | 
				
			||||||
	prober := New()
 | 
						prober := New()
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		expectedStatus probe.Status
 | 
							expectedStatus probe.Result
 | 
				
			||||||
		usePort        bool
 | 
							usePort        bool
 | 
				
			||||||
		expectError    bool
 | 
							expectError    bool
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user