From 8159c8fd25c5da3700f42de82fc3b801729446af Mon Sep 17 00:00:00 2001 From: markturansky Date: Fri, 21 Nov 2014 14:04:32 -0500 Subject: [PATCH] Refactor PodCondition to PodPhase --- cmd/e2e/e2e.go | 4 ++-- pkg/api/latest/latest_test.go | 4 ++-- pkg/api/serialization_test.go | 4 ++-- pkg/api/types.go | 16 ++++++++-------- pkg/api/v1beta1/conversion.go | 14 +++++++------- pkg/api/v1beta2/conversion.go | 14 +++++++------- pkg/api/v1beta3/types.go | 14 +++++++------- pkg/api/validation/schema_test.go | 4 ++-- pkg/client/client_test.go | 10 +++++----- pkg/controller/replication_controller.go | 4 ++-- pkg/kubecfg/resource_printer.go | 2 +- pkg/kubectl/describe.go | 4 ++-- pkg/kubectl/resource_printer.go | 2 +- pkg/registry/etcd/etcd.go | 2 +- pkg/registry/pod/rest.go | 10 +++++----- pkg/registry/pod/rest_test.go | 6 +++--- 16 files changed, 57 insertions(+), 57 deletions(-) diff --git a/cmd/e2e/e2e.go b/cmd/e2e/e2e.go index c79112d20f..b00beeec41 100644 --- a/cmd/e2e/e2e.go +++ b/cmd/e2e/e2e.go @@ -46,10 +46,10 @@ func waitForPodRunning(c *client.Client, id string) { glog.Warningf("Get pod failed: %v", err) continue } - if pod.Status.Condition == api.PodRunning { + if pod.Status.Phase == api.PodRunning { break } - glog.Infof("Waiting for pod status to be running (%s)", pod.Status.Condition) + glog.Infof("Waiting for pod status to be running (%s)", pod.Status.Phase) } } diff --git a/pkg/api/latest/latest_test.go b/pkg/api/latest/latest_test.go index 3e5648598c..3f2b2c309b 100644 --- a/pkg/api/latest/latest_test.go +++ b/pkg/api/latest/latest_test.go @@ -71,8 +71,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs( j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10) j.FieldPath = c.RandString() }, - func(j *internal.PodCondition, c fuzz.Continue) { - statuses := []internal.PodCondition{internal.PodPending, internal.PodRunning, internal.PodFailed} + func(j *internal.PodPhase, c fuzz.Continue) { + statuses := []internal.PodPhase{internal.PodPending, internal.PodRunning, internal.PodFailed} *j = statuses[c.Rand.Intn(len(statuses))] }, func(j *internal.ReplicationControllerSpec, c fuzz.Continue) { diff --git a/pkg/api/serialization_test.go b/pkg/api/serialization_test.go index 6fba25f17d..ac230c4306 100644 --- a/pkg/api/serialization_test.go +++ b/pkg/api/serialization_test.go @@ -86,8 +86,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs( j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10) j.SelfLink = c.RandString() }, - func(j *api.PodCondition, c fuzz.Continue) { - statuses := []api.PodCondition{api.PodPending, api.PodRunning, api.PodFailed} + func(j *api.PodPhase, c fuzz.Continue) { + statuses := []api.PodPhase{api.PodPending, api.PodRunning, api.PodFailed} *j = statuses[c.Rand.Intn(len(statuses))] }, func(j *api.ReplicationControllerSpec, c fuzz.Continue) { diff --git a/pkg/api/types.go b/pkg/api/types.go index 278f76b808..5ed942e19d 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -337,24 +337,24 @@ type Lifecycle struct { // The below types are used by kube_client and api_server. -// PodCondition is a label for the condition of a pod at the current time. -type PodCondition string +// PodPhase is a label for the condition of a pod at the current time. +type PodPhase string // These are the valid statuses of pods. const ( // PodPending means the pod has been accepted by the system, but one or more of the containers // has not been started. This includes time before being bound to a node, as well as time spent // pulling images onto the host. - PodPending PodCondition = "Pending" + PodPending PodPhase = "Pending" // PodRunning means the pod has been bound to a node and all of the containers have been started. // At least one container is still running or is in the process of being restarted. - PodRunning PodCondition = "Running" + PodRunning PodPhase = "Running" // PodSucceeded means that all containers in the pod have voluntarily terminated // with a container exit code of 0, and the system is not going to restart any of these containers. - PodSucceeded PodCondition = "Succeeded" + PodSucceeded PodPhase = "Succeeded" // PodFailed means that all containers in the pod have terminated, and at least one container has // terminated in a failure (exited with a non-zero exit code or was stopped by the system). - PodFailed PodCondition = "Failed" + PodFailed PodPhase = "Failed" ) type ContainerStateWaiting struct { @@ -422,7 +422,7 @@ type RestartPolicy struct { // 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" yaml:"manifest,omitempty"` - Status PodCondition `json:"status,omitempty" yaml:"status,omitempty"` + Status PodPhase `json:"status,omitempty" yaml:"status,omitempty"` // A human readable message indicating details about why the pod is in this state. Message string `json:"message,omitempty" yaml:"message,omitempty"` Host string `json:"host,omitempty" yaml:"host,omitempty"` @@ -458,7 +458,7 @@ type PodSpec struct { // PodStatus represents information about the status of a pod. Status may trail the actual // state of a system. type PodStatus struct { - Condition PodCondition `json:"condition,omitempty" yaml:"condition,omitempty"` + Phase PodPhase `json:"phase,omitempty" yaml:"phase,omitempty"` // Host is the name of the node that this Pod is currently bound to, or empty if no // assignment has been done. diff --git a/pkg/api/v1beta1/conversion.go b/pkg/api/v1beta1/conversion.go index 35d23d30ad..d25942c79c 100644 --- a/pkg/api/v1beta1/conversion.go +++ b/pkg/api/v1beta1/conversion.go @@ -161,7 +161,7 @@ func init() { }, func(in *newer.PodStatus, out *PodState, s conversion.Scope) error { - if err := s.Convert(&in.Condition, &out.Status, 0); err != nil { + if err := s.Convert(&in.Phase, &out.Status, 0); err != nil { return err } if err := s.Convert(&in.Info, &out.Info, 0); err != nil { @@ -173,7 +173,7 @@ func init() { return nil }, func(in *PodState, out *newer.PodStatus, s conversion.Scope) error { - if err := s.Convert(&in.Status, &out.Condition, 0); err != nil { + if err := s.Convert(&in.Status, &out.Phase, 0); err != nil { return err } if err := s.Convert(&in.Info, &out.Info, 0); err != nil { @@ -186,8 +186,8 @@ func init() { return nil }, - // Convert all to the new PodCondition constants - func(in *newer.PodCondition, out *PodStatus, s conversion.Scope) error { + // Convert all to the new PodPhase constants + func(in *newer.PodPhase, out *PodStatus, s conversion.Scope) error { switch *in { case "": *out = "" @@ -200,13 +200,13 @@ func init() { case newer.PodFailed: *out = PodTerminated default: - return errors.New("The string provided is not a valid PodCondition constant value") + return errors.New("The string provided is not a valid PodPhase constant value") } return nil }, - func(in *PodStatus, out *newer.PodCondition, s conversion.Scope) error { + func(in *PodStatus, out *newer.PodPhase, s conversion.Scope) error { switch *in { case "": *out = "" @@ -218,7 +218,7 @@ func init() { // Older API versions did not contain enough info to map to PodSucceeded *out = newer.PodFailed default: - return errors.New("The string provided is not a valid PodCondition constant value") + return errors.New("The string provided is not a valid PodPhase constant value") } return nil }, diff --git a/pkg/api/v1beta2/conversion.go b/pkg/api/v1beta2/conversion.go index 0688a1726b..e0fabcc924 100644 --- a/pkg/api/v1beta2/conversion.go +++ b/pkg/api/v1beta2/conversion.go @@ -90,8 +90,8 @@ func init() { return s.Convert(&in.Annotations, &out.Annotations, 0) }, - // Convert all to the new PodCondition constants - func(in *newer.PodCondition, out *PodStatus, s conversion.Scope) error { + // Convert all to the new PodPhase constants + func(in *newer.PodPhase, out *PodStatus, s conversion.Scope) error { switch *in { case "": *out = "" @@ -104,13 +104,13 @@ func init() { case newer.PodFailed: *out = PodTerminated default: - return errors.New("The string provided is not a valid PodCondition constant value") + return errors.New("The string provided is not a valid PodPhase constant value") } return nil }, - func(in *PodStatus, out *newer.PodCondition, s conversion.Scope) error { + func(in *PodStatus, out *newer.PodPhase, s conversion.Scope) error { switch *in { case "": *out = "" @@ -122,7 +122,7 @@ func init() { // Older API versions did not contain enough info to map to PodSucceeded *out = newer.PodFailed default: - return errors.New("The string provided is not a valid PodCondition constant value") + return errors.New("The string provided is not a valid PodPhase constant value") } return nil }, @@ -279,7 +279,7 @@ func init() { }, func(in *newer.PodStatus, out *PodState, s conversion.Scope) error { - if err := s.Convert(&in.Condition, &out.Status, 0); err != nil { + if err := s.Convert(&in.Phase, &out.Status, 0); err != nil { return err } if err := s.Convert(&in.Info, &out.Info, 0); err != nil { @@ -291,7 +291,7 @@ func init() { return nil }, func(in *PodState, out *newer.PodStatus, s conversion.Scope) error { - if err := s.Convert(&in.Status, &out.Condition, 0); err != nil { + if err := s.Convert(&in.Status, &out.Phase, 0); err != nil { return err } if err := s.Convert(&in.Info, &out.Info, 0); err != nil { diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index bdd8243851..92b982114d 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -366,24 +366,24 @@ type Lifecycle struct { PreStop *Handler `json:"preStop,omitempty" yaml:"preStop,omitempty"` } -// PodCondition is a label for the condition of a pod at the current time. -type PodCondition string +// PodPhase is a label for the condition of a pod at the current time. +type PodPhase string // These are the valid states of pods. const ( // PodPending means the pod has been accepted by the system, but one or more of the containers // has not been started. This includes time before being bound to a node, as well as time spent // pulling images onto the host. - PodPending PodCondition = "Pending" + PodPending PodPhase = "Pending" // PodRunning means the pod has been bound to a node and all of the containers have been started. // At least one container is still running or is in the process of being restarted. - PodRunning PodCondition = "Running" + PodRunning PodPhase = "Running" // PodSucceeded means that all containers in the pod have voluntarily terminated // with a container exit code of 0, and the system is not going to restart any of these containers. - PodSucceeded PodCondition = "Succeeded" + PodSucceeded PodPhase = "Succeeded" // PodFailed means that all containers in the pod have terminated, and at least one container has // terminated in a failure (exited with a non-zero exit code or was stopped by the system). - PodFailed PodCondition = "Failed" + PodFailed PodPhase = "Failed" ) type ContainerStateWaiting struct { @@ -456,7 +456,7 @@ type PodSpec struct { // PodStatus represents information about the status of a pod. Status may trail the actual // state of a system. type PodStatus struct { - Condition PodCondition `json:"condition,omitempty" yaml:"condition,omitempty"` + Phase PodPhase `json:"phase,omitempty" yaml:"phase,omitempty"` // A human readable message indicating details about why the pod is in this state. Message string `json:"message,omitempty" yaml:"message,omitempty"` diff --git a/pkg/api/validation/schema_test.go b/pkg/api/validation/schema_test.go index e44f1190e7..446a4a38db 100644 --- a/pkg/api/validation/schema_test.go +++ b/pkg/api/validation/schema_test.go @@ -88,8 +88,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs( j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10) j.SelfLink = c.RandString() }, - func(j *api.PodCondition, c fuzz.Continue) { - statuses := []api.PodCondition{api.PodPending, api.PodRunning, api.PodFailed} + func(j *api.PodPhase, c fuzz.Continue) { + statuses := []api.PodPhase{api.PodPending, api.PodRunning, api.PodFailed} *j = statuses[c.Rand.Intn(len(statuses))] }, func(j *api.ReplicationControllerSpec, c fuzz.Continue) { diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index e4365d4dd3..0049c77c6b 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -173,7 +173,7 @@ func TestListPods(t *testing.T) { Items: []api.Pod{ { Status: api.PodStatus{ - Condition: api.PodRunning, + Phase: api.PodRunning, }, ObjectMeta: api.ObjectMeta{ Labels: map[string]string{ @@ -206,7 +206,7 @@ func TestListPodsLabels(t *testing.T) { Items: []api.Pod{ { Status: api.PodStatus{ - Condition: api.PodRunning, + Phase: api.PodRunning, }, ObjectMeta: api.ObjectMeta{ Labels: map[string]string{ @@ -234,7 +234,7 @@ func TestGetPod(t *testing.T) { StatusCode: 200, Body: &api.Pod{ Status: api.PodStatus{ - Condition: api.PodRunning, + Phase: api.PodRunning, }, ObjectMeta: api.ObjectMeta{ Labels: map[string]string{ @@ -261,7 +261,7 @@ func TestDeletePod(t *testing.T) { func TestCreatePod(t *testing.T) { requestPod := &api.Pod{ Status: api.PodStatus{ - Condition: api.PodRunning, + Phase: api.PodRunning, }, ObjectMeta: api.ObjectMeta{ Labels: map[string]string{ @@ -292,7 +292,7 @@ func TestUpdatePod(t *testing.T) { }, }, Status: api.PodStatus{ - Condition: api.PodRunning, + Phase: api.PodRunning, }, } c := &testClient{ diff --git a/pkg/controller/replication_controller.go b/pkg/controller/replication_controller.go index 0fdae06b17..114db54880 100644 --- a/pkg/controller/replication_controller.go +++ b/pkg/controller/replication_controller.go @@ -143,8 +143,8 @@ func (rm *ReplicationManager) watchControllers(resourceVersion *string) { func (rm *ReplicationManager) filterActivePods(pods []api.Pod) []api.Pod { var result []api.Pod for _, value := range pods { - if api.PodSucceeded != value.Status.Condition && - api.PodFailed != value.Status.Condition { + if api.PodSucceeded != value.Status.Phase && + api.PodFailed != value.Status.Phase { result = append(result, value) } } diff --git a/pkg/kubecfg/resource_printer.go b/pkg/kubecfg/resource_printer.go index 1b44531735..15c086ebf9 100644 --- a/pkg/kubecfg/resource_printer.go +++ b/pkg/kubecfg/resource_printer.go @@ -204,7 +204,7 @@ func printPod(pod *api.Pod, w io.Writer) error { _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", pod.Name, makeImageList(pod.Spec), podHostString(pod.Status.Host, pod.Status.HostIP), - labels.Set(pod.Labels), pod.Status.Condition) + labels.Set(pod.Labels), pod.Status.Phase) return err } diff --git a/pkg/kubectl/describe.go b/pkg/kubectl/describe.go index 59b57085c3..7c5f1da9f8 100644 --- a/pkg/kubectl/describe.go +++ b/pkg/kubectl/describe.go @@ -93,7 +93,7 @@ func (d *PodDescriber) Describe(namespace, name string) (string, error) { fmt.Fprintf(out, "Image(s):\t%s\n", makeImageList(spec)) fmt.Fprintf(out, "Host:\t%s\n", pod.Status.Host+"/"+pod.Status.HostIP) fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(pod.Labels)) - fmt.Fprintf(out, "Status:\t%s\n", string(pod.Status.Condition)) + fmt.Fprintf(out, "Status:\t%s\n", string(pod.Status.Phase)) fmt.Fprintf(out, "Replication Controllers:\t%s\n", getReplicationControllersForLabels(rc, labels.Set(pod.Labels))) if events != nil { describeEvents(events, out) @@ -247,7 +247,7 @@ func getPodStatusForReplicationController(c client.PodInterface, controller *api return } for _, pod := range rcPods.Items { - switch pod.Status.Condition { + switch pod.Status.Phase { case api.PodRunning: running++ case api.PodPending: diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index f91d54b1ea..530c2d301e 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -243,7 +243,7 @@ func printPod(pod *api.Pod, w io.Writer) error { _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", pod.Name, firstImage, podHostString(pod.Status.Host, pod.Status.HostIP), - labels.Set(pod.Labels), pod.Status.Condition) + labels.Set(pod.Labels), pod.Status.Phase) if err != nil { return err } diff --git a/pkg/registry/etcd/etcd.go b/pkg/registry/etcd/etcd.go index a5dcea616e..5720c6883d 100644 --- a/pkg/registry/etcd/etcd.go +++ b/pkg/registry/etcd/etcd.go @@ -159,7 +159,7 @@ func makeContainerKey(machine string) string { // CreatePod creates a pod based on a specification. func (r *Registry) CreatePod(ctx api.Context, pod *api.Pod) error { // Set current status to "Waiting". - pod.Status.Condition = api.PodPending + pod.Status.Phase = api.PodPending pod.Status.Host = "" key, err := makePodKey(ctx, pod.Name) if err != nil { diff --git a/pkg/registry/pod/rest.go b/pkg/registry/pod/rest.go index 4137e1e7d2..c3c14b6006 100644 --- a/pkg/registry/pod/rest.go +++ b/pkg/registry/pod/rest.go @@ -129,7 +129,7 @@ func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) { if err != nil { return pod, err } - pod.Status.Condition = status + pod.Status.Phase = status } if pod.Status.Host != "" { pod.Status.HostIP = rs.getInstanceIP(pod.Status.Host) @@ -143,11 +143,11 @@ func (rs *REST) podToSelectableFields(pod *api.Pod) labels.Set { // see https://github.com/GoogleCloudPlatform/kubernetes/pull/2503 var olderPodStatus v1beta1.PodStatus - api.Scheme.Convert(pod.Status.Condition, &olderPodStatus) + api.Scheme.Convert(pod.Status.Phase, &olderPodStatus) return labels.Set{ "name": pod.Name, - "Status.Condition": string(pod.Status.Condition), + "Status.Phase": string(pod.Status.Phase), "Status.Host": pod.Status.Host, "DesiredState.Status": string(olderPodStatus), "DesiredState.Host": pod.Status.Host, @@ -173,7 +173,7 @@ func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Obj if err != nil { return pod, err } - pod.Status.Condition = status + pod.Status.Phase = status if pod.Status.Host != "" { pod.Status.HostIP = rs.getInstanceIP(pod.Status.Host) } @@ -274,7 +274,7 @@ func getInstanceIPFromCloud(cloud cloudprovider.Interface, host string) string { return addr.String() } -func getPodStatus(pod *api.Pod, minions client.MinionInterface) (api.PodCondition, error) { +func getPodStatus(pod *api.Pod, minions client.MinionInterface) (api.PodPhase, error) { if pod.Status.Host == "" { return api.PodPending, nil } diff --git a/pkg/registry/pod/rest_test.go b/pkg/registry/pod/rest_test.go index fdf434ba75..cb06b8f63f 100644 --- a/pkg/registry/pod/rest_test.go +++ b/pkg/registry/pod/rest_test.go @@ -205,7 +205,7 @@ func TestListPodListSelection(t *testing.T) { Status: api.PodStatus{Host: "barhost"}, }, { ObjectMeta: api.ObjectMeta{Name: "baz"}, - Status: api.PodStatus{Condition: "bazstatus"}, + Status: api.PodStatus{Phase: "bazstatus"}, }, { ObjectMeta: api.ObjectMeta{ Name: "qux", @@ -236,7 +236,7 @@ func TestListPodListSelection(t *testing.T) { label: "label=qux", expectedIDs: util.NewStringSet("qux"), }, { - field: "Status.Condition=bazstatus", + field: "Status.Phase=bazstatus", expectedIDs: util.NewStringSet("baz"), }, { field: "Status.Host=barhost", @@ -400,7 +400,7 @@ func TestMakePodStatus(t *testing.T) { tests := []struct { pod *api.Pod - status api.PodCondition + status api.PodPhase test string }{ {&api.Pod{Spec: desiredState, Status: currentState}, api.PodPending, "waiting"},