Commit aee3c5ae authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #47973 from sjenning/include-obj-fieldpath-event-key

Automatic merge from submit-queue include object fieldpath in event key Fixes https://github.com/kubernetes/kubernetes/issues/47692 #47462 exposed a bug where `getEventKey()` only keys on event fields that are common at the pod level. Events generated by different containers in the same pod will yield identical event keys. This results in events with the same message from different containers in a pod being aggregated in error. This wasn't a problem before as the event message contained container specific information and thus didn't produce the same event key. @derekwaynecarr @dhilipkumars @dchen1107
parents d2309e2a fbcb0562
...@@ -49,6 +49,7 @@ func getEventKey(event *v1.Event) string { ...@@ -49,6 +49,7 @@ func getEventKey(event *v1.Event) string {
event.InvolvedObject.Kind, event.InvolvedObject.Kind,
event.InvolvedObject.Namespace, event.InvolvedObject.Namespace,
event.InvolvedObject.Name, event.InvolvedObject.Name,
event.InvolvedObject.FieldPath,
string(event.InvolvedObject.UID), string(event.InvolvedObject.UID),
event.InvolvedObject.APIVersion, event.InvolvedObject.APIVersion,
event.Type, event.Type,
......
...@@ -35,6 +35,7 @@ func makeObjectReference(kind, name, namespace string) v1.ObjectReference { ...@@ -35,6 +35,7 @@ func makeObjectReference(kind, name, namespace string) v1.ObjectReference {
Namespace: namespace, Namespace: namespace,
UID: "C934D34AFB20242", UID: "C934D34AFB20242",
APIVersion: "version", APIVersion: "version",
FieldPath: "spec.containers{mycontainer}",
} }
} }
...@@ -171,7 +172,10 @@ func TestEventCorrelator(t *testing.T) { ...@@ -171,7 +172,10 @@ func TestEventCorrelator(t *testing.T) {
duplicateEvent := makeEvent("duplicate", "me again", makeObjectReference("Pod", "my-pod", "my-ns")) duplicateEvent := makeEvent("duplicate", "me again", makeObjectReference("Pod", "my-pod", "my-ns"))
uniqueEvent := makeEvent("unique", "snowflake", makeObjectReference("Pod", "my-pod", "my-ns")) uniqueEvent := makeEvent("unique", "snowflake", makeObjectReference("Pod", "my-pod", "my-ns"))
similarEvent := makeEvent("similar", "similar message", makeObjectReference("Pod", "my-pod", "my-ns")) similarEvent := makeEvent("similar", "similar message", makeObjectReference("Pod", "my-pod", "my-ns"))
similarEvent.InvolvedObject.FieldPath = "spec.containers{container1}"
aggregateEvent := makeEvent(similarEvent.Reason, EventAggregatorByReasonMessageFunc(&similarEvent), similarEvent.InvolvedObject) aggregateEvent := makeEvent(similarEvent.Reason, EventAggregatorByReasonMessageFunc(&similarEvent), similarEvent.InvolvedObject)
similarButDifferentContainerEvent := similarEvent
similarButDifferentContainerEvent.InvolvedObject.FieldPath = "spec.containers{container2}"
scenario := map[string]struct { scenario := map[string]struct {
previousEvents []v1.Event previousEvents []v1.Event
newEvent v1.Event newEvent v1.Event
...@@ -214,6 +218,12 @@ func TestEventCorrelator(t *testing.T) { ...@@ -214,6 +218,12 @@ func TestEventCorrelator(t *testing.T) {
expectedEvent: setCount(aggregateEvent, 2), expectedEvent: setCount(aggregateEvent, 2),
intervalSeconds: 5, intervalSeconds: 5,
}, },
"events-from-different-containers-do-not-aggregate": {
previousEvents: makeEvents(1, similarButDifferentContainerEvent),
newEvent: similarEvent,
expectedEvent: setCount(similarEvent, 1),
intervalSeconds: 5,
},
"similar-events-whose-interval-is-greater-than-aggregate-interval-do-not-aggregate": { "similar-events-whose-interval-is-greater-than-aggregate-interval-do-not-aggregate": {
previousEvents: makeSimilarEvents(defaultAggregateMaxEvents-1, similarEvent, similarEvent.Message), previousEvents: makeSimilarEvents(defaultAggregateMaxEvents-1, similarEvent, similarEvent.Message),
newEvent: similarEvent, newEvent: similarEvent,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment