diff --git a/pkg/api/types.go b/pkg/api/types.go index 920a7ee8da7..ec8542cd671 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -953,18 +953,18 @@ type Event struct { // Required. The object that this event is about. InvolvedObject ObjectReference `json:"involvedObject,omitempty"` - // Should be a short, machine understandable string that describes the current status + // Should be a short, machine understandable string that describes the current condition // of the referred object. This should not give the reason for being in this state. - // Examples: "running", "cantStart", "cantSchedule", "deleted". - // It's OK for components to make up statuses to report here, but the same string should - // always be used for the same status. + // Examples: "Running", "CantStart", "CantSchedule", "Deleted". + // It's OK for components to make up conditions to report here, but the same string should + // always be used for the same conditions. // TODO: define a way of making sure these are consistent and don't collide. // TODO: provide exact specification for format. - Status string `json:"status,omitempty"` + Condition string `json:"condition,omitempty"` // Optional; this should be a short, machine understandable string that gives the reason - // for the transition into the object's current status. For example, if ObjectStatus is - // "cantStart", StatusReason might be "imageNotFound". + // for the transition into the object's current condition. For example, if ObjectCondition is + // "CantStart", StatusReason might be "ImageNotFound". // TODO: provide exact specification for format. Reason string `json:"reason,omitempty"` diff --git a/pkg/api/v1beta1/conversion.go b/pkg/api/v1beta1/conversion.go index 3116c159f66..8fde109d9b3 100644 --- a/pkg/api/v1beta1/conversion.go +++ b/pkg/api/v1beta1/conversion.go @@ -34,6 +34,10 @@ func init() { newer.Scheme.AddStructFieldConversion(newer.ObjectMeta{}, "ObjectMeta", TypeMeta{}, "TypeMeta") newer.Scheme.AddStructFieldConversion(newer.ListMeta{}, "ListMeta", TypeMeta{}, "TypeMeta") + // TODO: scope this to a specific type once that becomes available and remove the Event conversion functions below + // newer.Scheme.AddStructFieldConversion(string(""), "Status", string(""), "Condition") + // newer.Scheme.AddStructFieldConversion(string(""), "Condition", string(""), "Status") + newer.Scheme.AddConversionFuncs( // TypeMeta must be split into two objects func(in *newer.TypeMeta, out *TypeMeta, s conversion.Scope) error { @@ -521,5 +525,36 @@ func init() { out.FieldPath = in.FieldPath return nil }, + + // Event Status -> Condition + // TODO: remove this when it becomes possible to specify a field name conversion on a specific type + func(in *newer.Event, out *Event, s conversion.Scope) error { + if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { + return err + } + if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil { + return err + } + out.Status = in.Condition + out.Reason = in.Reason + out.Message = in.Message + out.Source = in.Source + out.Timestamp = in.Timestamp + return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0) + }, + func(in *Event, out *newer.Event, s conversion.Scope) error { + if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { + return err + } + if err := s.Convert(&in.TypeMeta, &out.ObjectMeta, 0); err != nil { + return err + } + out.Condition = in.Status + out.Reason = in.Reason + out.Message = in.Message + out.Source = in.Source + out.Timestamp = in.Timestamp + return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0) + }, ) } diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index 9a76e2ac324..6c0a390d5a4 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -776,7 +776,7 @@ type Event struct { // Should be a short, machine understandable string that describes the current status // of the referred object. This should not give the reason for being in this state. - // Examples: "running", "cantStart", "cantSchedule", "deleted". + // Examples: "Running", "CantStart", "CantSchedule", "Deleted". // It's OK for components to make up statuses to report here, but the same string should // always be used for the same status. // TODO: define a way of making sure these are consistent and don't collide. @@ -785,7 +785,7 @@ type Event struct { // Optional; this should be a short, machine understandable string that gives the reason // for the transition into the object's current status. For example, if ObjectStatus is - // "cantStart", StatusReason might be "imageNotFound". + // "CantStart", Reason might be "ImageNotFound". // TODO: provide exact specification for format. Reason string `json:"reason,omitempty" description:"short, machine understandable string that gives the reason for the transition into the object's current status"` diff --git a/pkg/api/v1beta2/conversion.go b/pkg/api/v1beta2/conversion.go index 9faa062fad3..20c6ab794f2 100644 --- a/pkg/api/v1beta2/conversion.go +++ b/pkg/api/v1beta2/conversion.go @@ -34,6 +34,10 @@ func init() { newer.Scheme.AddStructFieldConversion(newer.ObjectMeta{}, "ObjectMeta", TypeMeta{}, "TypeMeta") newer.Scheme.AddStructFieldConversion(newer.ListMeta{}, "ListMeta", TypeMeta{}, "TypeMeta") + // TODO: scope this to a specific type once that becomes available and remove the Event conversion functions below + // newer.Scheme.AddStructFieldConversion(string(""), "Status", string(""), "Condition") + // newer.Scheme.AddStructFieldConversion(string(""), "Condition", string(""), "Status") + newer.Scheme.AddConversionFuncs( // TypeMeta must be split into two objects func(in *newer.TypeMeta, out *TypeMeta, s conversion.Scope) error { @@ -439,5 +443,36 @@ func init() { out.FieldPath = in.FieldPath return nil }, + + // Event Status -> Condition + // TODO: remove this when it becomes possible to specify a field name conversion on a specific type + func(in *newer.Event, out *Event, s conversion.Scope) error { + if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { + return err + } + if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil { + return err + } + out.Status = in.Condition + out.Reason = in.Reason + out.Message = in.Message + out.Source = in.Source + out.Timestamp = in.Timestamp + return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0) + }, + func(in *Event, out *newer.Event, s conversion.Scope) error { + if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { + return err + } + if err := s.Convert(&in.TypeMeta, &out.ObjectMeta, 0); err != nil { + return err + } + out.Condition = in.Status + out.Reason = in.Reason + out.Message = in.Message + out.Source = in.Source + out.Timestamp = in.Timestamp + return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0) + }, ) } diff --git a/pkg/api/v1beta2/types.go b/pkg/api/v1beta2/types.go index bb2b4ad9352..1ec2afb5f41 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -751,7 +751,7 @@ type Event struct { // Should be a short, machine understandable string that describes the current status // of the referred object. This should not give the reason for being in this state. - // Examples: "running", "cantStart", "cantSchedule", "deleted". + // Examples: "Running", "CantStart", "CantSchedule", "Deleted". // It's OK for components to make up statuses to report here, but the same string should // always be used for the same status. // TODO: define a way of making sure these are consistent and don't collide. @@ -760,7 +760,7 @@ type Event struct { // Optional; this should be a short, machine understandable string that gives the reason // for the transition into the object's current status. For example, if ObjectStatus is - // "cantStart", StatusReason might be "imageNotFound". + // "CantStart", Reason might be "ImageNotFound". // TODO: provide exact specification for format. Reason string `json:"reason,omitempty" description:"short, machine understandable string that gives the reason for the transition into the object's current status"` diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index 57dd78c6398..62c33ad89ce 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -973,18 +973,18 @@ type Event struct { // Required. The object that this event is about. InvolvedObject ObjectReference `json:"involvedObject,omitempty"` - // Should be a short, machine understandable string that describes the current status + // Should be a short, machine understandable string that describes the current condition // of the referred object. This should not give the reason for being in this state. // Examples: "Running", "CantStart", "CantSchedule", "Deleted". - // It's OK for components to make up statuses to report here, but the same string should - // always be used for the same status. + // It's OK for components to make up conditions to report here, but the same string should + // always be used for the same conditions. // TODO: define a way of making sure these are consistent and don't collide. // TODO: provide exact specification for format. Condition string `json:"condition,omitempty"` // Optional; this should be a short, machine understandable string that gives the reason - // for the transition into the object's current status. For example, if ObjectStatus is - // "cantStart", StatusReason might be "imageNotFound". + // for the transition into the object's current condition. For example, if ObjectCondition is + // "CantStart", StatusReason might be "ImageNotFound". // TODO: provide exact specification for format. Reason string `json:"reason,omitempty"` diff --git a/pkg/client/events_test.go b/pkg/client/events_test.go index 37829adf70d..d21c606a2d5 100644 --- a/pkg/client/events_test.go +++ b/pkg/client/events_test.go @@ -62,7 +62,8 @@ func TestEventCreate(t *testing.T) { } timeStamp := util.Now() event := &api.Event{ - Status: "running", + //namespace: namespace{"default"}, + Condition: "Running", InvolvedObject: *objReference, Timestamp: timeStamp, } @@ -97,7 +98,7 @@ func TestEventGet(t *testing.T) { } timeStamp := util.Now() event := &api.Event{ - Status: "running", + Condition: "Running", InvolvedObject: *objReference, Timestamp: timeStamp, } @@ -135,7 +136,7 @@ func TestEventList(t *testing.T) { eventList := &api.EventList{ Items: []api.Event{ { - Status: "running", + Condition: "Running", InvolvedObject: *objReference, Timestamp: timeStamp, }, diff --git a/pkg/client/record/event.go b/pkg/client/record/event.go index bd941ae4515..d86aee0340b 100644 --- a/pkg/client/record/event.go +++ b/pkg/client/record/event.go @@ -89,7 +89,7 @@ func StartRecording(recorder EventRecorder, sourceName string) watch.Interface { // return value can be ignored or used to stop logging, if desired. func StartLogging(logf func(format string, args ...interface{})) watch.Interface { return GetEvents(func(e *api.Event) { - logf("Event(%#v): status: '%v', reason: '%v' %v", e.InvolvedObject, e.Status, e.Reason, e.Message) + logf("Event(%#v): status: '%v', reason: '%v' %v", e.InvolvedObject, e.Condition, e.Reason, e.Message) }) } @@ -123,17 +123,17 @@ var events = watch.NewBroadcaster(queueLen) // Event constructs an event from the given information and puts it in the queue for sending. // 'object' is the object this event is about. Event will make a reference-- or you may also // pass a reference to the object directly. -// 'status' is the new status of the object. 'reason' is the reason it now has this status. -// Both 'status' and 'reason' should be short and unique; they will be used to automate +// 'condition' is the new condition of the object. 'reason' is the reason it now has this status. +// Both 'condition' and 'reason' should be short and unique; they will be used to automate // handling of events, so imagine people writing switch statements to handle them. You want to // make that easy. // 'message' is intended to be human readable. // // The resulting event will be created in the same namespace as the reference object. -func Event(object runtime.Object, status, reason, message string) { +func Event(object runtime.Object, condition, reason, message string) { ref, err := api.GetReference(object) if err != nil { - glog.Errorf("Could not construct reference to: '%#v' due to: '%v'. Will not report event: '%v' '%v' '%v'", object, err, status, reason, message) + glog.Errorf("Could not construct reference to: '%#v' due to: '%v'. Will not report event: '%v' '%v' '%v'", object, err, condition, reason, message) return } t := util.Now() @@ -144,7 +144,7 @@ func Event(object runtime.Object, status, reason, message string) { Namespace: ref.Namespace, }, InvolvedObject: *ref, - Status: status, + Condition: condition, Reason: reason, Message: message, Timestamp: t, diff --git a/pkg/client/record/event_test.go b/pkg/client/record/event_test.go index 32e3b637e55..bf2a62abf5d 100644 --- a/pkg/client/record/event_test.go +++ b/pkg/client/record/event_test.go @@ -69,8 +69,8 @@ func TestEventf(t *testing.T) { }{ { obj: testRef, - status: "running", - reason: "started", + status: "Running", + reason: "Started", messageFmt: "some verbose message: %v", elements: []interface{}{1}, expect: &api.Event{ @@ -86,17 +86,17 @@ func TestEventf(t *testing.T) { APIVersion: "v1beta1", FieldPath: "desiredState.manifest.containers[2]", }, - Status: "running", - Reason: "started", - Message: "some verbose message: 1", - Source: "eventTest", + Condition: "Running", + Reason: "Started", + Message: "some verbose message: 1", + Source: "eventTest", }, - expectLog: `Event(api.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:"desiredState.manifest.containers[2]"}): status: 'running', reason: 'started' some verbose message: 1`, + expectLog: `Event(api.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:"desiredState.manifest.containers[2]"}): status: 'Running', reason: 'Started' some verbose message: 1`, }, { obj: testPod, - status: "running", - reason: "started", + status: "Running", + reason: "Started", messageFmt: "some verbose message: %v", elements: []interface{}{1}, expect: &api.Event{ @@ -111,12 +111,12 @@ func TestEventf(t *testing.T) { UID: "bar", APIVersion: "v1beta1", }, - Status: "running", - Reason: "started", - Message: "some verbose message: 1", - Source: "eventTest", + Condition: "Running", + Reason: "Started", + Message: "some verbose message: 1", + Source: "eventTest", }, - expectLog: `Event(api.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:""}): status: 'running', reason: 'started' some verbose message: 1`, + expectLog: `Event(api.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:""}): status: 'Running', reason: 'Started' some verbose message: 1`, }, } diff --git a/pkg/kubecfg/resource_printer.go b/pkg/kubecfg/resource_printer.go index cea32df1684..01837bfe904 100644 --- a/pkg/kubecfg/resource_printer.go +++ b/pkg/kubecfg/resource_printer.go @@ -143,7 +143,7 @@ var replicationControllerColumns = []string{"Name", "Image(s)", "Selector", "Rep var serviceColumns = []string{"Name", "Labels", "Selector", "IP", "Port"} var minionColumns = []string{"Minion identifier", "Labels"} var statusColumns = []string{"Status"} -var eventColumns = []string{"Name", "Kind", "Status", "Reason", "Message"} +var eventColumns = []string{"Name", "Kind", "Condition", "Reason", "Message"} // addDefaultHandlers adds print handlers for default Kubernetes types. func (h *HumanReadablePrinter) addDefaultHandlers() { @@ -272,7 +272,7 @@ func printEvent(event *api.Event, w io.Writer) error { w, "%s\t%s\t%s\t%s\t%s\n", event.InvolvedObject.Name, event.InvolvedObject.Kind, - event.Status, + event.Condition, event.Reason, event.Message, ) diff --git a/pkg/kubectl/describe.go b/pkg/kubectl/describe.go index 66d363ca226..028f6503dfe 100644 --- a/pkg/kubectl/describe.go +++ b/pkg/kubectl/describe.go @@ -205,10 +205,10 @@ func describeEvents(el *api.EventList, w io.Writer) { return } sort.Sort(sortableEvents(el.Items)) - fmt.Fprint(w, "Events:\nFrom\tSubobjectPath\tStatus\tReason\tMessage\n") + fmt.Fprint(w, "Events:\nFrom\tSubobjectPath\tCondition\tReason\tMessage\n") for _, e := range el.Items { fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n", - e.Source, e.InvolvedObject.FieldPath, e.Status, e.Reason, e.Message) + e.Source, e.InvolvedObject.FieldPath, e.Condition, e.Reason, e.Message) } } diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index 6af374784cb..acd1ea237f8 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -191,7 +191,7 @@ var replicationControllerColumns = []string{"NAME", "IMAGE(S)", "SELECTOR", "REP var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT"} var minionColumns = []string{"NAME", "LABELS"} var statusColumns = []string{"STATUS"} -var eventColumns = []string{"NAME", "KIND", "STATUS", "REASON", "MESSAGE"} +var eventColumns = []string{"NAME", "KIND", "CONDITION", "REASON", "MESSAGE"} // addDefaultHandlers adds print handlers for default Kubernetes types. func (h *HumanReadablePrinter) addDefaultHandlers() { @@ -320,7 +320,7 @@ func printEvent(event *api.Event, w io.Writer) error { w, "%s\t%s\t%s\t%s\t%s\n", event.InvolvedObject.Name, event.InvolvedObject.Kind, - event.Status, + event.Condition, event.Reason, event.Message, ) diff --git a/pkg/registry/event/rest.go b/pkg/registry/event/rest.go index 1346691c96c..8ca30daa46f 100644 --- a/pkg/registry/event/rest.go +++ b/pkg/registry/event/rest.go @@ -106,7 +106,8 @@ func (rs *REST) getAttrs(obj runtime.Object) (objLabels, objFields labels.Set, e "involvedObject.apiVersion": event.InvolvedObject.APIVersion, "involvedObject.resourceVersion": fmt.Sprintf("%s", event.InvolvedObject.ResourceVersion), "involvedObject.fieldPath": event.InvolvedObject.FieldPath, - "status": event.Status, + "condition": event.Condition, + "status": event.Condition, // TODO: remove me when we version fields "reason": event.Reason, "source": event.Source, }, nil diff --git a/pkg/registry/event/rest_test.go b/pkg/registry/event/rest_test.go index 095813c6edb..cb9557e3fff 100644 --- a/pkg/registry/event/rest_test.go +++ b/pkg/registry/event/rest_test.go @@ -143,9 +143,9 @@ func TestRESTgetAttrs(t *testing.T) { ResourceVersion: "0", FieldPath: "", }, - Status: "tested", - Reason: "forTesting", - Source: "test", + Condition: "Tested", + Reason: "ForTesting", + Source: "test", } label, field, err := rest.getAttrs(eventA) if err != nil { @@ -162,8 +162,9 @@ func TestRESTgetAttrs(t *testing.T) { "involvedObject.apiVersion": testapi.Version(), "involvedObject.resourceVersion": "0", "involvedObject.fieldPath": "", - "status": "tested", - "reason": "forTesting", + "condition": "Tested", + "status": "Tested", + "reason": "ForTesting", "source": "test", } if e, a := expect, field; !reflect.DeepEqual(e, a) { @@ -196,8 +197,8 @@ func TestRESTList(t *testing.T) { ResourceVersion: "0", FieldPath: "", }, - Status: "tested", - Reason: "forTesting", + Condition: "Tested", + Reason: "ForTesting", } eventB := &api.Event{ InvolvedObject: api.ObjectReference{ @@ -208,8 +209,8 @@ func TestRESTList(t *testing.T) { ResourceVersion: "0", FieldPath: "", }, - Status: "tested", - Reason: "forTesting", + Condition: "Tested", + Reason: "ForTesting", } eventC := &api.Event{ InvolvedObject: api.ObjectReference{ @@ -220,13 +221,13 @@ func TestRESTList(t *testing.T) { ResourceVersion: "0", FieldPath: "", }, - Status: "untested", - Reason: "forTesting", + Condition: "Untested", + Reason: "ForTesting", } reg.ObjectList = &api.EventList{ Items: []api.Event{*eventA, *eventB, *eventC}, } - got, err := rest.List(api.NewContext(), labels.Everything(), labels.Set{"status": "tested"}.AsSelector()) + got, err := rest.List(api.NewContext(), labels.Everything(), labels.Set{"status": "Tested"}.AsSelector()) if err != nil { t.Fatalf("Unexpected error %v", err) } @@ -248,8 +249,8 @@ func TestRESTWatch(t *testing.T) { ResourceVersion: "0", FieldPath: "", }, - Status: "tested", - Reason: "forTesting", + Condition: "Tested", + Reason: "ForTesting", } reg, rest := NewTestREST() wi, err := rest.Watch(api.NewContext(), labels.Everything(), labels.Everything(), "0")