Refactor PodCondition to PodPhase

This commit is contained in:
markturansky 2014-11-21 14:04:32 -05:00
parent 9f5ebef3d8
commit 8159c8fd25
16 changed files with 57 additions and 57 deletions

View File

@ -46,10 +46,10 @@ func waitForPodRunning(c *client.Client, id string) {
glog.Warningf("Get pod failed: %v", err) glog.Warningf("Get pod failed: %v", err)
continue continue
} }
if pod.Status.Condition == api.PodRunning { if pod.Status.Phase == api.PodRunning {
break 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)
} }
} }

View File

@ -71,8 +71,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10) j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
j.FieldPath = c.RandString() j.FieldPath = c.RandString()
}, },
func(j *internal.PodCondition, c fuzz.Continue) { func(j *internal.PodPhase, c fuzz.Continue) {
statuses := []internal.PodCondition{internal.PodPending, internal.PodRunning, internal.PodFailed} statuses := []internal.PodPhase{internal.PodPending, internal.PodRunning, internal.PodFailed}
*j = statuses[c.Rand.Intn(len(statuses))] *j = statuses[c.Rand.Intn(len(statuses))]
}, },
func(j *internal.ReplicationControllerSpec, c fuzz.Continue) { func(j *internal.ReplicationControllerSpec, c fuzz.Continue) {

View File

@ -86,8 +86,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10) j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
j.SelfLink = c.RandString() j.SelfLink = c.RandString()
}, },
func(j *api.PodCondition, c fuzz.Continue) { func(j *api.PodPhase, c fuzz.Continue) {
statuses := []api.PodCondition{api.PodPending, api.PodRunning, api.PodFailed} statuses := []api.PodPhase{api.PodPending, api.PodRunning, api.PodFailed}
*j = statuses[c.Rand.Intn(len(statuses))] *j = statuses[c.Rand.Intn(len(statuses))]
}, },
func(j *api.ReplicationControllerSpec, c fuzz.Continue) { func(j *api.ReplicationControllerSpec, c fuzz.Continue) {

View File

@ -337,24 +337,24 @@ type Lifecycle struct {
// The below types are used by kube_client and api_server. // 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. // PodPhase is a label for the condition of a pod at the current time.
type PodCondition string type PodPhase string
// These are the valid statuses of pods. // These are the valid statuses of pods.
const ( const (
// PodPending means the pod has been accepted by the system, but one or more of the containers // 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 // has not been started. This includes time before being bound to a node, as well as time spent
// pulling images onto the host. // 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. // 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. // 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 // 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. // 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 // 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). // 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 { 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). // PodState is the state of a pod, used as either input (desired state) or output (current state).
type PodState struct { type PodState struct {
Manifest ContainerManifest `json:"manifest,omitempty" yaml:"manifest,omitempty"` 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. // A human readable message indicating details about why the pod is in this state.
Message string `json:"message,omitempty" yaml:"message,omitempty"` Message string `json:"message,omitempty" yaml:"message,omitempty"`
Host string `json:"host,omitempty" yaml:"host,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 // PodStatus represents information about the status of a pod. Status may trail the actual
// state of a system. // state of a system.
type PodStatus struct { 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 // Host is the name of the node that this Pod is currently bound to, or empty if no
// assignment has been done. // assignment has been done.

View File

@ -161,7 +161,7 @@ func init() {
}, },
func(in *newer.PodStatus, out *PodState, s conversion.Scope) error { 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 return err
} }
if err := s.Convert(&in.Info, &out.Info, 0); err != nil { if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
@ -173,7 +173,7 @@ func init() {
return nil return nil
}, },
func(in *PodState, out *newer.PodStatus, s conversion.Scope) error { 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 return err
} }
if err := s.Convert(&in.Info, &out.Info, 0); err != nil { if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
@ -186,8 +186,8 @@ func init() {
return nil return nil
}, },
// Convert all to the new PodCondition constants // Convert all to the new PodPhase constants
func(in *newer.PodCondition, out *PodStatus, s conversion.Scope) error { func(in *newer.PodPhase, out *PodStatus, s conversion.Scope) error {
switch *in { switch *in {
case "": case "":
*out = "" *out = ""
@ -200,13 +200,13 @@ func init() {
case newer.PodFailed: case newer.PodFailed:
*out = PodTerminated *out = PodTerminated
default: 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 return nil
}, },
func(in *PodStatus, out *newer.PodCondition, s conversion.Scope) error { func(in *PodStatus, out *newer.PodPhase, s conversion.Scope) error {
switch *in { switch *in {
case "": case "":
*out = "" *out = ""
@ -218,7 +218,7 @@ func init() {
// Older API versions did not contain enough info to map to PodSucceeded // Older API versions did not contain enough info to map to PodSucceeded
*out = newer.PodFailed *out = newer.PodFailed
default: 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 return nil
}, },

View File

@ -90,8 +90,8 @@ func init() {
return s.Convert(&in.Annotations, &out.Annotations, 0) return s.Convert(&in.Annotations, &out.Annotations, 0)
}, },
// Convert all to the new PodCondition constants // Convert all to the new PodPhase constants
func(in *newer.PodCondition, out *PodStatus, s conversion.Scope) error { func(in *newer.PodPhase, out *PodStatus, s conversion.Scope) error {
switch *in { switch *in {
case "": case "":
*out = "" *out = ""
@ -104,13 +104,13 @@ func init() {
case newer.PodFailed: case newer.PodFailed:
*out = PodTerminated *out = PodTerminated
default: 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 return nil
}, },
func(in *PodStatus, out *newer.PodCondition, s conversion.Scope) error { func(in *PodStatus, out *newer.PodPhase, s conversion.Scope) error {
switch *in { switch *in {
case "": case "":
*out = "" *out = ""
@ -122,7 +122,7 @@ func init() {
// Older API versions did not contain enough info to map to PodSucceeded // Older API versions did not contain enough info to map to PodSucceeded
*out = newer.PodFailed *out = newer.PodFailed
default: 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 return nil
}, },
@ -279,7 +279,7 @@ func init() {
}, },
func(in *newer.PodStatus, out *PodState, s conversion.Scope) error { 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 return err
} }
if err := s.Convert(&in.Info, &out.Info, 0); err != nil { if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
@ -291,7 +291,7 @@ func init() {
return nil return nil
}, },
func(in *PodState, out *newer.PodStatus, s conversion.Scope) error { 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 return err
} }
if err := s.Convert(&in.Info, &out.Info, 0); err != nil { if err := s.Convert(&in.Info, &out.Info, 0); err != nil {

View File

@ -366,24 +366,24 @@ type Lifecycle struct {
PreStop *Handler `json:"preStop,omitempty" yaml:"preStop,omitempty"` PreStop *Handler `json:"preStop,omitempty" yaml:"preStop,omitempty"`
} }
// PodCondition is a label for the condition of a pod at the current time. // PodPhase is a label for the condition of a pod at the current time.
type PodCondition string type PodPhase string
// These are the valid states of pods. // These are the valid states of pods.
const ( const (
// PodPending means the pod has been accepted by the system, but one or more of the containers // 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 // has not been started. This includes time before being bound to a node, as well as time spent
// pulling images onto the host. // 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. // 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. // 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 // 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. // 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 // 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). // 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 { type ContainerStateWaiting struct {
@ -456,7 +456,7 @@ type PodSpec struct {
// PodStatus represents information about the status of a pod. Status may trail the actual // PodStatus represents information about the status of a pod. Status may trail the actual
// state of a system. // state of a system.
type PodStatus struct { 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. // A human readable message indicating details about why the pod is in this state.
Message string `json:"message,omitempty" yaml:"message,omitempty"` Message string `json:"message,omitempty" yaml:"message,omitempty"`

View File

@ -88,8 +88,8 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10) j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
j.SelfLink = c.RandString() j.SelfLink = c.RandString()
}, },
func(j *api.PodCondition, c fuzz.Continue) { func(j *api.PodPhase, c fuzz.Continue) {
statuses := []api.PodCondition{api.PodPending, api.PodRunning, api.PodFailed} statuses := []api.PodPhase{api.PodPending, api.PodRunning, api.PodFailed}
*j = statuses[c.Rand.Intn(len(statuses))] *j = statuses[c.Rand.Intn(len(statuses))]
}, },
func(j *api.ReplicationControllerSpec, c fuzz.Continue) { func(j *api.ReplicationControllerSpec, c fuzz.Continue) {

View File

@ -173,7 +173,7 @@ func TestListPods(t *testing.T) {
Items: []api.Pod{ Items: []api.Pod{
{ {
Status: api.PodStatus{ Status: api.PodStatus{
Condition: api.PodRunning, Phase: api.PodRunning,
}, },
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
@ -206,7 +206,7 @@ func TestListPodsLabels(t *testing.T) {
Items: []api.Pod{ Items: []api.Pod{
{ {
Status: api.PodStatus{ Status: api.PodStatus{
Condition: api.PodRunning, Phase: api.PodRunning,
}, },
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
@ -234,7 +234,7 @@ func TestGetPod(t *testing.T) {
StatusCode: 200, StatusCode: 200,
Body: &api.Pod{ Body: &api.Pod{
Status: api.PodStatus{ Status: api.PodStatus{
Condition: api.PodRunning, Phase: api.PodRunning,
}, },
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
@ -261,7 +261,7 @@ func TestDeletePod(t *testing.T) {
func TestCreatePod(t *testing.T) { func TestCreatePod(t *testing.T) {
requestPod := &api.Pod{ requestPod := &api.Pod{
Status: api.PodStatus{ Status: api.PodStatus{
Condition: api.PodRunning, Phase: api.PodRunning,
}, },
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: map[string]string{ Labels: map[string]string{
@ -292,7 +292,7 @@ func TestUpdatePod(t *testing.T) {
}, },
}, },
Status: api.PodStatus{ Status: api.PodStatus{
Condition: api.PodRunning, Phase: api.PodRunning,
}, },
} }
c := &testClient{ c := &testClient{

View File

@ -143,8 +143,8 @@ func (rm *ReplicationManager) watchControllers(resourceVersion *string) {
func (rm *ReplicationManager) filterActivePods(pods []api.Pod) []api.Pod { func (rm *ReplicationManager) filterActivePods(pods []api.Pod) []api.Pod {
var result []api.Pod var result []api.Pod
for _, value := range pods { for _, value := range pods {
if api.PodSucceeded != value.Status.Condition && if api.PodSucceeded != value.Status.Phase &&
api.PodFailed != value.Status.Condition { api.PodFailed != value.Status.Phase {
result = append(result, value) result = append(result, value)
} }
} }

View File

@ -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", _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
pod.Name, makeImageList(pod.Spec), pod.Name, makeImageList(pod.Spec),
podHostString(pod.Status.Host, pod.Status.HostIP), podHostString(pod.Status.Host, pod.Status.HostIP),
labels.Set(pod.Labels), pod.Status.Condition) labels.Set(pod.Labels), pod.Status.Phase)
return err return err
} }

View File

@ -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, "Image(s):\t%s\n", makeImageList(spec))
fmt.Fprintf(out, "Host:\t%s\n", pod.Status.Host+"/"+pod.Status.HostIP) 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, "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))) fmt.Fprintf(out, "Replication Controllers:\t%s\n", getReplicationControllersForLabels(rc, labels.Set(pod.Labels)))
if events != nil { if events != nil {
describeEvents(events, out) describeEvents(events, out)
@ -247,7 +247,7 @@ func getPodStatusForReplicationController(c client.PodInterface, controller *api
return return
} }
for _, pod := range rcPods.Items { for _, pod := range rcPods.Items {
switch pod.Status.Condition { switch pod.Status.Phase {
case api.PodRunning: case api.PodRunning:
running++ running++
case api.PodPending: case api.PodPending:

View File

@ -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", _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
pod.Name, firstImage, pod.Name, firstImage,
podHostString(pod.Status.Host, pod.Status.HostIP), podHostString(pod.Status.Host, pod.Status.HostIP),
labels.Set(pod.Labels), pod.Status.Condition) labels.Set(pod.Labels), pod.Status.Phase)
if err != nil { if err != nil {
return err return err
} }

View File

@ -159,7 +159,7 @@ func makeContainerKey(machine string) string {
// CreatePod creates a pod based on a specification. // CreatePod creates a pod based on a specification.
func (r *Registry) CreatePod(ctx api.Context, pod *api.Pod) error { func (r *Registry) CreatePod(ctx api.Context, pod *api.Pod) error {
// Set current status to "Waiting". // Set current status to "Waiting".
pod.Status.Condition = api.PodPending pod.Status.Phase = api.PodPending
pod.Status.Host = "" pod.Status.Host = ""
key, err := makePodKey(ctx, pod.Name) key, err := makePodKey(ctx, pod.Name)
if err != nil { if err != nil {

View File

@ -129,7 +129,7 @@ func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
if err != nil { if err != nil {
return pod, err return pod, err
} }
pod.Status.Condition = status pod.Status.Phase = status
} }
if pod.Status.Host != "" { if pod.Status.Host != "" {
pod.Status.HostIP = rs.getInstanceIP(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 // see https://github.com/GoogleCloudPlatform/kubernetes/pull/2503
var olderPodStatus v1beta1.PodStatus var olderPodStatus v1beta1.PodStatus
api.Scheme.Convert(pod.Status.Condition, &olderPodStatus) api.Scheme.Convert(pod.Status.Phase, &olderPodStatus)
return labels.Set{ return labels.Set{
"name": pod.Name, "name": pod.Name,
"Status.Condition": string(pod.Status.Condition), "Status.Phase": string(pod.Status.Phase),
"Status.Host": pod.Status.Host, "Status.Host": pod.Status.Host,
"DesiredState.Status": string(olderPodStatus), "DesiredState.Status": string(olderPodStatus),
"DesiredState.Host": pod.Status.Host, "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 { if err != nil {
return pod, err return pod, err
} }
pod.Status.Condition = status pod.Status.Phase = status
if pod.Status.Host != "" { if pod.Status.Host != "" {
pod.Status.HostIP = rs.getInstanceIP(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() 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 == "" { if pod.Status.Host == "" {
return api.PodPending, nil return api.PodPending, nil
} }

View File

@ -205,7 +205,7 @@ func TestListPodListSelection(t *testing.T) {
Status: api.PodStatus{Host: "barhost"}, Status: api.PodStatus{Host: "barhost"},
}, { }, {
ObjectMeta: api.ObjectMeta{Name: "baz"}, ObjectMeta: api.ObjectMeta{Name: "baz"},
Status: api.PodStatus{Condition: "bazstatus"}, Status: api.PodStatus{Phase: "bazstatus"},
}, { }, {
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "qux", Name: "qux",
@ -236,7 +236,7 @@ func TestListPodListSelection(t *testing.T) {
label: "label=qux", label: "label=qux",
expectedIDs: util.NewStringSet("qux"), expectedIDs: util.NewStringSet("qux"),
}, { }, {
field: "Status.Condition=bazstatus", field: "Status.Phase=bazstatus",
expectedIDs: util.NewStringSet("baz"), expectedIDs: util.NewStringSet("baz"),
}, { }, {
field: "Status.Host=barhost", field: "Status.Host=barhost",
@ -400,7 +400,7 @@ func TestMakePodStatus(t *testing.T) {
tests := []struct { tests := []struct {
pod *api.Pod pod *api.Pod
status api.PodCondition status api.PodPhase
test string test string
}{ }{
{&api.Pod{Spec: desiredState, Status: currentState}, api.PodPending, "waiting"}, {&api.Pod{Spec: desiredState, Status: currentState}, api.PodPending, "waiting"},