Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events corev1: adding eventTime initialization #80222

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions staging/src/k8s.io/client-go/tools/record/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ func (recorder *recorderImpl) makeEvent(ref *v1.ObjectReference, annotations map
InvolvedObject: *ref,
Reason: reason,
Message: message,
EventTime: (metav1.MicroTime)(t),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires changing unit tests too.

FirstTimestamp: t,
LastTimestamp: t,
Count: 1,
Expand Down
1 change: 1 addition & 0 deletions staging/src/k8s.io/client-go/tools/record/events_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func (e *EventAggregator) EventAggregate(newEvent *v1.Event) (*v1.Event, string)
Namespace: newEvent.Namespace,
},
Count: 1,
EventTime: (metav1.MicroTime)(now),
FirstTimestamp: now,
InvolvedObject: newEvent.InvolvedObject,
LastTimestamp: now,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func makeEvent(reason, message string, involvedObject v1.ObjectReference) v1.Eve
Host: "kublet.node1",
},
Count: 1,
EventTime: (metav1.MicroTime)(eventTime),
FirstTimestamp: eventTime,
LastTimestamp: eventTime,
Type: v1.EventTypeNormal,
Expand Down Expand Up @@ -102,6 +103,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
}
actualFirstTimestamp := recvEvent.FirstTimestamp
actualLastTimestamp := recvEvent.LastTimestamp
actualEventTime := recvEvent.EventTime
if actualFirstTimestamp.Equal(&actualLastTimestamp) {
if expectCompression {
t.Errorf("%v - FirstTimestamp (%q) and LastTimestamp (%q) must be different to indicate event compression happened, but were the same. Actual Event: %#v", messagePrefix, actualFirstTimestamp, actualLastTimestamp, recvEvent)
Expand All @@ -114,6 +116,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
// Temp clear time stamps for comparison because actual values don't matter for comparison
recvEvent.FirstTimestamp = expectedEvent.FirstTimestamp
recvEvent.LastTimestamp = expectedEvent.LastTimestamp
recvEvent.EventTime = expectedEvent.EventTime
// Check that name has the right prefix.
if n, en := recvEvent.Name, expectedEvent.Name; !strings.HasPrefix(n, en) {
t.Errorf("%v - Name '%v' does not contain prefix '%v'", messagePrefix, n, en)
Expand All @@ -124,6 +127,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
}
recvEvent.FirstTimestamp = actualFirstTimestamp
recvEvent.LastTimestamp = actualLastTimestamp
recvEvent.EventTime = actualEventTime
return actualEvent, nil
}

Expand Down Expand Up @@ -240,6 +244,7 @@ func TestEventCorrelator(t *testing.T) {
now := metav1.NewTime(clock.Now())
event.FirstTimestamp = now
event.LastTimestamp = now
testInput.newEvent.EventTime = (metav1.MicroTime)(now)
result, err := correlator.EventCorrelate(&event)
if err != nil {
t.Errorf("scenario %v: unexpected error playing back prevEvents %v", testScenario, err)
Expand All @@ -254,6 +259,7 @@ func TestEventCorrelator(t *testing.T) {
now := metav1.NewTime(clock.Now())
testInput.newEvent.FirstTimestamp = now
testInput.newEvent.LastTimestamp = now
testInput.newEvent.EventTime = (metav1.MicroTime)(now)
result, err := correlator.EventCorrelate(&testInput.newEvent)
if err != nil {
t.Errorf("scenario %v: unexpected error correlating input event %v", testScenario, err)
Expand Down