Refactor HealthCheck to take podUUID arguments

PodState is going away (won't have podUUID anymore)
pull/6/head
Clayton Coleman 2014-10-08 11:19:46 -04:00
parent eea77a1449
commit 95cb2e3eb3
10 changed files with 17 additions and 17 deletions

View File

@ -43,11 +43,11 @@ func IsExitError(err error) bool {
return ok return ok
} }
func (e *ExecHealthChecker) HealthCheck(podFullName string, currentState api.PodState, container api.Container) (Status, error) { func (e *ExecHealthChecker) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error) {
if container.LivenessProbe.Exec == nil { if container.LivenessProbe.Exec == nil {
return Unknown, fmt.Errorf("Missing exec parameters") return Unknown, fmt.Errorf("Missing exec parameters")
} }
data, err := e.runner.RunInContainer(podFullName, currentState.Manifest.UUID, container.Name, container.LivenessProbe.Exec.Command) data, err := e.runner.RunInContainer(podFullName, podUUID, container.Name, container.LivenessProbe.Exec.Command)
glog.V(1).Infof("container %s failed health check: %s", podFullName, string(data)) glog.V(1).Infof("container %s failed health check: %s", podFullName, string(data))
if err != nil { if err != nil {
if IsExitError(err) { if IsExitError(err) {

View File

@ -70,7 +70,7 @@ func TestExec(t *testing.T) {
for _, test := range tests { for _, test := range tests {
fake.out = test.output fake.out = test.output
fake.err = test.err fake.err = test.err
status, err := checker.HealthCheck("test", api.PodState{}, api.Container{LivenessProbe: test.probe}) status, err := checker.HealthCheck("test", "", api.PodState{}, api.Container{LivenessProbe: test.probe})
if status != test.expectedStatus { if status != test.expectedStatus {
t.Errorf("expected %v, got %v", test.expectedStatus, status) t.Errorf("expected %v, got %v", test.expectedStatus, status)
} }

View File

@ -35,7 +35,7 @@ const (
// HealthChecker defines an abstract interface for checking container health. // HealthChecker defines an abstract interface for checking container health.
type HealthChecker interface { type HealthChecker interface {
HealthCheck(podFullName string, currentState api.PodState, container api.Container) (Status, error) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error)
CanCheck(probe *api.LivenessProbe) bool CanCheck(probe *api.LivenessProbe) bool
} }
@ -78,13 +78,13 @@ func (m *muxHealthChecker) findCheckerFor(probe *api.LivenessProbe) HealthChecke
// HealthCheck delegates the health-checking of the container to one of the bundled implementations. // HealthCheck delegates the health-checking of the container to one of the bundled implementations.
// If there is no health checker that can check container it returns Unknown, nil. // If there is no health checker that can check container it returns Unknown, nil.
func (m *muxHealthChecker) HealthCheck(podFullName string, currentState api.PodState, container api.Container) (Status, error) { func (m *muxHealthChecker) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error) {
checker := m.findCheckerFor(container.LivenessProbe) checker := m.findCheckerFor(container.LivenessProbe)
if checker == nil { if checker == nil {
glog.Warningf("Failed to find health checker for %s %+v", container.Name, container.LivenessProbe) glog.Warningf("Failed to find health checker for %s %+v", container.Name, container.LivenessProbe)
return Unknown, nil return Unknown, nil
} }
return checker.HealthCheck(podFullName, currentState, container) return checker.HealthCheck(podFullName, podUUID, currentState, container)
} }
func (m *muxHealthChecker) CanCheck(probe *api.LivenessProbe) bool { func (m *muxHealthChecker) CanCheck(probe *api.LivenessProbe) bool {

View File

@ -67,7 +67,7 @@ func TestHealthChecker(t *testing.T) {
}, },
} }
hc := NewHealthChecker() hc := NewHealthChecker()
health, err := hc.HealthCheck("test", api.PodState{}, container) health, err := hc.HealthCheck("test", "", api.PodState{}, container)
if err != nil && tt.health != Unknown { if err != nil && tt.health != Unknown {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
@ -129,7 +129,7 @@ func TestMuxHealthChecker(t *testing.T) {
} }
container.LivenessProbe.HTTPGet.Port = util.NewIntOrStringFromString(port) container.LivenessProbe.HTTPGet.Port = util.NewIntOrStringFromString(port)
container.LivenessProbe.HTTPGet.Host = host container.LivenessProbe.HTTPGet.Host = host
health, err := mc.HealthCheck("test", api.PodState{}, container) health, err := mc.HealthCheck("test", "", api.PodState{}, container)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }

View File

@ -98,7 +98,7 @@ func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error) {
} }
// HealthCheck checks if the container is healthy by trying sending HTTP Get requests to the container. // HealthCheck checks if the container is healthy by trying sending HTTP Get requests to the container.
func (h *HTTPHealthChecker) HealthCheck(podFullName string, currentState api.PodState, container api.Container) (Status, error) { func (h *HTTPHealthChecker) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error) {
host, port, path, err := getURLParts(currentState, container) host, port, path, err := getURLParts(currentState, container)
if err != nil { if err != nil {
return Unknown, err return Unknown, err

View File

@ -123,7 +123,7 @@ func TestHTTPHealthChecker(t *testing.T) {
params.Port = util.NewIntOrStringFromString(port) params.Port = util.NewIntOrStringFromString(port)
params.Host = host params.Host = host
} }
health, err := hc.HealthCheck("test", api.PodState{PodIP: host}, container) health, err := hc.HealthCheck("test", "", api.PodState{PodIP: host}, container)
if test.health == Unknown && err == nil { if test.health == Unknown && err == nil {
t.Errorf("Expected error") t.Errorf("Expected error")
} }

View File

@ -74,7 +74,7 @@ func DoTCPCheck(addr string) (Status, error) {
return Healthy, nil return Healthy, nil
} }
func (t *TCPHealthChecker) HealthCheck(podFullName string, currentState api.PodState, container api.Container) (Status, error) { func (t *TCPHealthChecker) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error) {
host, port, err := getTCPAddrParts(currentState, container) host, port, err := getTCPAddrParts(currentState, container)
if err != nil { if err != nil {
return Unknown, err return Unknown, err

View File

@ -100,7 +100,7 @@ func TestTcpHealthChecker(t *testing.T) {
if params != nil && test.expectedStatus == Healthy { if params != nil && test.expectedStatus == Healthy {
params.Port = util.NewIntOrStringFromString(port) params.Port = util.NewIntOrStringFromString(port)
} }
status, err := checker.HealthCheck("test", api.PodState{PodIP: host}, container) status, err := checker.HealthCheck("test", "", api.PodState{PodIP: host}, container)
if status != test.expectedStatus { if status != test.expectedStatus {
t.Errorf("expected: %v, got: %v", test.expectedStatus, status) t.Errorf("expected: %v, got: %v", test.expectedStatus, status)
} }

View File

@ -490,7 +490,7 @@ func (kl *Kubelet) syncPod(pod *Pod, dockerContainers dockertools.DockerContaine
return err return err
} }
podState := api.PodState{Manifest: api.ContainerManifest{UUID: uuid}} podState := api.PodState{}
info, err := kl.GetPodInfo(podFullName, uuid) info, err := kl.GetPodInfo(podFullName, uuid)
if err != nil { if err != nil {
glog.Errorf("Unable to get pod with name %s and uuid %s info, health checks may be invalid.", glog.Errorf("Unable to get pod with name %s and uuid %s info, health checks may be invalid.",
@ -510,7 +510,7 @@ func (kl *Kubelet) syncPod(pod *Pod, dockerContainers dockertools.DockerContaine
// look for changes in the container. // look for changes in the container.
if hash == 0 || hash == expectedHash { if hash == 0 || hash == expectedHash {
// TODO: This should probably be separated out into a separate goroutine. // TODO: This should probably be separated out into a separate goroutine.
healthy, err := kl.healthy(podFullName, podState, container, dockerContainer) healthy, err := kl.healthy(podFullName, uuid, podState, container, dockerContainer)
if err != nil { if err != nil {
glog.V(1).Infof("health check errored: %v", err) glog.V(1).Infof("health check errored: %v", err)
containersToKeep[containerID] = empty{} containersToKeep[containerID] = empty{}
@ -828,7 +828,7 @@ func (kl *Kubelet) GetMachineInfo() (*info.MachineInfo, error) {
return cc.MachineInfo() return cc.MachineInfo()
} }
func (kl *Kubelet) healthy(podFullName string, currentState api.PodState, container api.Container, dockerContainer *docker.APIContainers) (health.Status, error) { func (kl *Kubelet) healthy(podFullName, podUUID string, currentState api.PodState, container api.Container, dockerContainer *docker.APIContainers) (health.Status, 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 health.Healthy, nil return health.Healthy, nil
@ -839,7 +839,7 @@ func (kl *Kubelet) healthy(podFullName string, currentState api.PodState, contai
if kl.healthChecker == nil { if kl.healthChecker == nil {
return health.Healthy, nil return health.Healthy, nil
} }
return kl.healthChecker.HealthCheck(podFullName, currentState, container) return kl.healthChecker.HealthCheck(podFullName, podUUID, currentState, container)
} }
// Returns logs of current machine. // Returns logs of current machine.

View File

@ -506,7 +506,7 @@ func TestSyncPodDeletesDuplicate(t *testing.T) {
type FalseHealthChecker struct{} type FalseHealthChecker struct{}
func (f *FalseHealthChecker) HealthCheck(podFullName string, state api.PodState, container api.Container) (health.Status, error) { func (f *FalseHealthChecker) HealthCheck(podFullName, podUUID string, state api.PodState, container api.Container) (health.Status, error) {
return health.Unhealthy, nil return health.Unhealthy, nil
} }