diff --git a/pkg/api/types.go b/pkg/api/types.go index 5c828b267aa..b1bda3540c2 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -694,6 +694,9 @@ type Event struct { // Optional. The component reporting this event. Should be a short machine understandable string. // TODO: provide exact specification for format. Source string `json:"source,omitempty" yaml:"source,omitempty"` + + // The time at which the client recorded the event. (Time of server receipt is in TypeMeta.) + Timestamp util.Time `json:"timestamp,omitempty" yaml:"timestamp,omitempty"` } // EventList is a list of events. diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index 468dde2c1db..76530043069 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -710,6 +710,9 @@ type Event struct { // Optional. The component reporting this event. Should be a short machine understandable string. // TODO: provide exact specification for format. Source string `json:"source,omitempty" yaml:"source,omitempty"` + + // The time at which the client recorded the event. (Time of server receipt is in TypeMeta.) + Timestamp util.Time `json:"timestamp,omitempty" yaml:"timestamp,omitempty"` } // EventList is a list of events. diff --git a/pkg/api/v1beta2/types.go b/pkg/api/v1beta2/types.go index 6375c0450ad..4807660e695 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -685,6 +685,9 @@ type Event struct { // Optional. The component reporting this event. Should be a short machine understandable string. // TODO: provide exact specification for format. Source string `json:"source,omitempty" yaml:"source,omitempty"` + + // The time at which the client recorded the event. (Time of server receipt is in TypeMeta.) + Timestamp util.Time `json:"timestamp,omitempty" yaml:"timestamp,omitempty"` } // EventList is a list of events. diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index 23016bd7c98..dd239d6136d 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -912,6 +912,9 @@ type Event struct { // Optional. The component reporting this event. Should be a short machine understandable string. // TODO: provide exact specification for format. Source string `json:"source,omitempty" yaml:"source,omitempty"` + + // The time at which the client recorded the event. (Time of server receipt is in TypeMeta.) + Timestamp util.Time `json:"timestamp,omitempty" yaml:"timestamp,omitempty"` } // EventList is a list of events. diff --git a/pkg/client/record/event.go b/pkg/client/record/event.go index a160d6ae26d..eec64a09361 100644 --- a/pkg/client/record/event.go +++ b/pkg/client/record/event.go @@ -108,6 +108,7 @@ func Event(object runtime.Object, fieldPath, status, reason, message string) { Status: status, Reason: reason, Message: message, + Timestamp: util.Now(), } events.Action(watch.Added, e) diff --git a/pkg/client/record/event_test.go b/pkg/client/record/event_test.go index 5babef0b389..c0f1e10b21c 100644 --- a/pkg/client/record/event_test.go +++ b/pkg/client/record/event_test.go @@ -84,12 +84,18 @@ func TestEventf(t *testing.T) { for _, item := range table { called := make(chan struct{}) testEvents := testEventRecorder{ - OnEvent: func(a *api.Event) (*api.Event, error) { - if e := item.expect; !reflect.DeepEqual(e, a) { + OnEvent: func(event *api.Event) (*api.Event, error) { + a := *event + // Just check that the timestamp was set. + if a.Timestamp.IsZero() { + t.Errorf("timestamp wasn't set") + } + a.Timestamp = item.expect.Timestamp + if e, a := item.expect, &a; !reflect.DeepEqual(e, a) { t.Errorf("diff: %s", util.ObjectDiff(e, a)) } called <- struct{}{} - return a, nil + return event, nil }, } recorder := record.StartRecording(&testEvents, "eventTest")