Remove internal PodState in favor of internal PodStatus object

This commit is contained in:
Clayton Coleman 2014-12-12 17:15:54 -05:00
parent 787b5c488a
commit dadb8431c4
12 changed files with 26 additions and 50 deletions

View File

@ -435,25 +435,6 @@ type RestartPolicy struct {
Never *RestartPolicyNever `json:"never,omitempty"` Never *RestartPolicyNever `json:"never,omitempty"`
} }
// PodState is the state of a pod, used as either input (desired state) or output (current state).
type PodState struct {
Manifest ContainerManifest `json:"manifest,omitempty"`
Status PodPhase `json:"status,omitempty"`
// A human readable message indicating details about why the pod is in this state.
Message string `json:"message,omitempty"`
Host string `json:"host,omitempty"`
HostIP string `json:"hostIP,omitempty"`
PodIP string `json:"podIP,omitempty"`
// The key of this map is the *name* of the container within the manifest; it has one
// entry per container in the manifest. The value of this map is currently the output
// of `docker inspect`. This output format is *not* final and should not be relied
// upon.
// TODO: Make real decisions about what our info should look like. Re-enable fuzz test
// when we have done this.
Info PodInfo `json:"info,omitempty"`
}
// PodList is a list of Pods. // PodList is a list of Pods.
type PodList struct { type PodList struct {
TypeMeta `json:",inline"` TypeMeta `json:",inline"`

View File

@ -348,11 +348,6 @@ func validateRestartPolicy(restartPolicy *api.RestartPolicy) errs.ValidationErro
return allErrors return allErrors
} }
func ValidatePodState(podState *api.PodState) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList(ValidateManifest(&podState.Manifest)).Prefix("manifest")
return allErrs
}
// ValidatePod tests if required fields in the pod are set. // ValidatePod tests if required fields in the pod are set.
func ValidatePod(pod *api.Pod) errs.ValidationErrorList { func ValidatePod(pod *api.Pod) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{} allErrs := errs.ValidationErrorList{}

View File

@ -38,7 +38,7 @@ func NewExecHealthChecker(runner CommandRunner) HealthChecker {
return &ExecHealthChecker{runner} return &ExecHealthChecker{runner}
} }
func (e *ExecHealthChecker) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error) { func (e *ExecHealthChecker) HealthCheck(podFullName, podUUID string, status api.PodStatus, 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")
} }

View File

@ -67,7 +67,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.PodStatus{}, 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, podUUID string, currentState api.PodState, container api.Container) (Status, error) HealthCheck(podFullName, podUUID string, status api.PodStatus, 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, podUUID string, currentState api.PodState, container api.Container) (Status, error) { func (m *muxHealthChecker) HealthCheck(podFullName, podUUID string, status api.PodStatus, 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, podUUID, currentState, container) return checker.HealthCheck(podFullName, podUUID, status, container)
} }
func (m *muxHealthChecker) CanCheck(probe *api.LivenessProbe) bool { func (m *muxHealthChecker) CanCheck(probe *api.LivenessProbe) bool {

View File

@ -68,7 +68,7 @@ func TestHealthChecker(t *testing.T) {
}, },
} }
hc := NewHealthChecker() hc := NewHealthChecker()
health, err := hc.HealthCheck("test", "", api.PodState{}, container) health, err := hc.HealthCheck("test", "", api.PodStatus{}, 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)
} }
@ -131,7 +131,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.PodStatus{}, container)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }

View File

@ -44,7 +44,7 @@ func NewHTTPHealthChecker(client *http.Client) HealthChecker {
} }
// getURLParts parses the components of the target URL. For testability. // getURLParts parses the components of the target URL. For testability.
func getURLParts(currentState api.PodState, container api.Container) (string, int, string, error) { func getURLParts(status api.PodStatus, container api.Container) (string, int, string, error) {
params := container.LivenessProbe.HTTPGet params := container.LivenessProbe.HTTPGet
if params == nil { if params == nil {
return "", -1, "", fmt.Errorf("no HTTP parameters specified: %v", container) return "", -1, "", fmt.Errorf("no HTTP parameters specified: %v", container)
@ -70,7 +70,7 @@ func getURLParts(currentState api.PodState, container api.Container) (string, in
if len(params.Host) > 0 { if len(params.Host) > 0 {
host = params.Host host = params.Host
} else { } else {
host = currentState.PodIP host = status.PodIP
} }
return host, port, params.Path, nil return host, port, params.Path, nil
@ -105,8 +105,8 @@ 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, podUUID string, currentState api.PodState, container api.Container) (Status, error) { func (h *HTTPHealthChecker) HealthCheck(podFullName, podUUID string, status api.PodStatus, container api.Container) (Status, error) {
host, port, path, err := getURLParts(currentState, container) host, port, path, err := getURLParts(status, container)
if err != nil { if err != nil {
return Unknown, err return Unknown, err
} }

View File

@ -46,7 +46,7 @@ func TestGetURLParts(t *testing.T) {
} }
for _, test := range testCases { for _, test := range testCases {
state := api.PodState{PodIP: "127.0.0.1"} state := api.PodStatus{PodIP: "127.0.0.1"}
container := api.Container{ container := api.Container{
Ports: []api.Port{{Name: "found", HostPort: 93}}, Ports: []api.Port{{Name: "found", HostPort: 93}},
LivenessProbe: &api.LivenessProbe{ LivenessProbe: &api.LivenessProbe{
@ -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.PodStatus{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

@ -29,7 +29,7 @@ import (
type TCPHealthChecker struct{} type TCPHealthChecker struct{}
// getTCPAddrParts parses the components of a TCP connection address. For testability. // getTCPAddrParts parses the components of a TCP connection address. For testability.
func getTCPAddrParts(currentState api.PodState, container api.Container) (string, int, error) { func getTCPAddrParts(status api.PodStatus, container api.Container) (string, int, error) {
params := container.LivenessProbe.TCPSocket params := container.LivenessProbe.TCPSocket
if params == nil { if params == nil {
return "", -1, fmt.Errorf("error, no TCP parameters specified: %v", container) return "", -1, fmt.Errorf("error, no TCP parameters specified: %v", container)
@ -51,11 +51,11 @@ func getTCPAddrParts(currentState api.PodState, container api.Container) (string
if port == -1 { if port == -1 {
return "", -1, fmt.Errorf("unknown port: %v", params.Port) return "", -1, fmt.Errorf("unknown port: %v", params.Port)
} }
if len(currentState.PodIP) == 0 { if len(status.PodIP) == 0 {
return "", -1, fmt.Errorf("no host specified.") return "", -1, fmt.Errorf("no host specified.")
} }
return currentState.PodIP, port, nil return status.PodIP, port, nil
} }
// DoTCPCheck checks that a TCP socket to the address can be opened. // DoTCPCheck checks that a TCP socket to the address can be opened.
@ -74,8 +74,8 @@ func DoTCPCheck(addr string) (Status, error) {
return Healthy, nil return Healthy, nil
} }
func (t *TCPHealthChecker) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error) { func (t *TCPHealthChecker) HealthCheck(podFullName, podUUID string, status api.PodStatus, container api.Container) (Status, error) {
host, port, err := getTCPAddrParts(currentState, container) host, port, err := getTCPAddrParts(status, container)
if err != nil { if err != nil {
return Unknown, err return Unknown, err
} }

View File

@ -44,7 +44,7 @@ func TestGetTCPAddrParts(t *testing.T) {
} }
for _, test := range testCases { for _, test := range testCases {
state := api.PodState{PodIP: "1.2.3.4"} state := api.PodStatus{PodIP: "1.2.3.4"}
container := api.Container{ container := api.Container{
Ports: []api.Port{{Name: "found", HostPort: 93}}, Ports: []api.Port{{Name: "found", HostPort: 93}},
LivenessProbe: &api.LivenessProbe{ LivenessProbe: &api.LivenessProbe{
@ -101,7 +101,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.PodStatus{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

@ -703,14 +703,14 @@ func (kl *Kubelet) syncPod(pod *api.BoundPod, dockerContainers dockertools.Docke
return err return err
} }
podState := api.PodState{} podStatus := api.PodStatus{}
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", podFullName, uuid) glog.Errorf("Unable to get pod with name %s and uuid %s info, health checks may be invalid", podFullName, uuid)
} }
netInfo, found := info[networkContainerName] netInfo, found := info[networkContainerName]
if found { if found {
podState.PodIP = netInfo.PodIP podStatus.PodIP = netInfo.PodIP
} }
for _, container := range pod.Spec.Containers { for _, container := range pod.Spec.Containers {
@ -722,7 +722,7 @@ func (kl *Kubelet) syncPod(pod *api.BoundPod, dockerContainers dockertools.Docke
// 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, uuid, podState, container, dockerContainer) healthy, err := kl.healthy(podFullName, uuid, podStatus, 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{}
@ -1042,7 +1042,7 @@ func (kl *Kubelet) GetPodInfo(podFullName, uuid string) (api.PodInfo, error) {
return dockertools.GetDockerPodInfo(kl.dockerClient, manifest, podFullName, uuid) return dockertools.GetDockerPodInfo(kl.dockerClient, manifest, podFullName, uuid)
} }
func (kl *Kubelet) healthy(podFullName, podUUID string, currentState api.PodState, container api.Container, dockerContainer *docker.APIContainers) (health.Status, error) { func (kl *Kubelet) healthy(podFullName, podUUID string, status api.PodStatus, 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
@ -1053,7 +1053,7 @@ func (kl *Kubelet) healthy(podFullName, podUUID string, currentState api.PodStat
if kl.healthChecker == nil { if kl.healthChecker == nil {
return health.Healthy, nil return health.Healthy, nil
} }
return kl.healthChecker.HealthCheck(podFullName, podUUID, currentState, container) return kl.healthChecker.HealthCheck(podFullName, podUUID, status, container)
} }
// Returns logs of current machine. // Returns logs of current machine.

View File

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