mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
Merge pull request #116506 from HirazawaUi/fix-events-field
generate ReportingInstance and ReportingController in Event
This commit is contained in:
commit
b277afdf46
@ -357,6 +357,9 @@ func (recorder *recorderImpl) generateEvent(object runtime.Object, annotations m
|
|||||||
event := recorder.makeEvent(ref, annotations, eventtype, reason, message)
|
event := recorder.makeEvent(ref, annotations, eventtype, reason, message)
|
||||||
event.Source = recorder.source
|
event.Source = recorder.source
|
||||||
|
|
||||||
|
event.ReportingInstance = recorder.source.Host
|
||||||
|
event.ReportingController = recorder.source.Component
|
||||||
|
|
||||||
// NOTE: events should be a non-blocking operation, but we also need to not
|
// NOTE: events should be a non-blocking operation, but we also need to not
|
||||||
// put this in a goroutine, otherwise we'll race to write to a closed channel
|
// put this in a goroutine, otherwise we'll race to write to a closed channel
|
||||||
// when we go to shut down this broadcaster. Just drop events if we get overloaded,
|
// when we go to shut down this broadcaster. Just drop events if we get overloaded,
|
||||||
|
@ -179,11 +179,12 @@ func TestEventf(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[2]",
|
FieldPath: "spec.containers[2]",
|
||||||
},
|
},
|
||||||
Reason: "Started",
|
Reason: "Started",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 1,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 1,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
||||||
expectUpdate: false,
|
expectUpdate: false,
|
||||||
@ -206,11 +207,12 @@ func TestEventf(t *testing.T) {
|
|||||||
UID: "bar",
|
UID: "bar",
|
||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
},
|
},
|
||||||
Reason: "Killed",
|
Reason: "Killed",
|
||||||
Message: "some other verbose message: 1",
|
Message: "some other verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 1,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 1,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:""}): type: 'Normal' reason: 'Killed' some other verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:""}): type: 'Normal' reason: 'Killed' some other verbose message: 1`,
|
||||||
expectUpdate: false,
|
expectUpdate: false,
|
||||||
@ -234,11 +236,12 @@ func TestEventf(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[2]",
|
FieldPath: "spec.containers[2]",
|
||||||
},
|
},
|
||||||
Reason: "Started",
|
Reason: "Started",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 2,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 2,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
||||||
expectUpdate: true,
|
expectUpdate: true,
|
||||||
@ -262,11 +265,12 @@ func TestEventf(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[3]",
|
FieldPath: "spec.containers[3]",
|
||||||
},
|
},
|
||||||
Reason: "Started",
|
Reason: "Started",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 1,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 1,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
||||||
expectUpdate: false,
|
expectUpdate: false,
|
||||||
@ -290,11 +294,12 @@ func TestEventf(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[2]",
|
FieldPath: "spec.containers[2]",
|
||||||
},
|
},
|
||||||
Reason: "Started",
|
Reason: "Started",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 3,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 3,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
||||||
expectUpdate: true,
|
expectUpdate: true,
|
||||||
@ -318,11 +323,12 @@ func TestEventf(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[3]",
|
FieldPath: "spec.containers[3]",
|
||||||
},
|
},
|
||||||
Reason: "Stopped",
|
Reason: "Stopped",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 1,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 1,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`,
|
||||||
expectUpdate: false,
|
expectUpdate: false,
|
||||||
@ -346,11 +352,12 @@ func TestEventf(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[3]",
|
FieldPath: "spec.containers[3]",
|
||||||
},
|
},
|
||||||
Reason: "Stopped",
|
Reason: "Stopped",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 2,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 2,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`,
|
||||||
expectUpdate: true,
|
expectUpdate: true,
|
||||||
@ -735,11 +742,12 @@ func TestMultiSinkCache(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[2]",
|
FieldPath: "spec.containers[2]",
|
||||||
},
|
},
|
||||||
Reason: "Started",
|
Reason: "Started",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 1,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 1,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
||||||
expectUpdate: false,
|
expectUpdate: false,
|
||||||
@ -762,11 +770,12 @@ func TestMultiSinkCache(t *testing.T) {
|
|||||||
UID: "bar",
|
UID: "bar",
|
||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
},
|
},
|
||||||
Reason: "Killed",
|
Reason: "Killed",
|
||||||
Message: "some other verbose message: 1",
|
Message: "some other verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 1,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 1,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:""}): type: 'Normal' reason: 'Killed' some other verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:""}): type: 'Normal' reason: 'Killed' some other verbose message: 1`,
|
||||||
expectUpdate: false,
|
expectUpdate: false,
|
||||||
@ -790,11 +799,12 @@ func TestMultiSinkCache(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[2]",
|
FieldPath: "spec.containers[2]",
|
||||||
},
|
},
|
||||||
Reason: "Started",
|
Reason: "Started",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 2,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 2,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
||||||
expectUpdate: true,
|
expectUpdate: true,
|
||||||
@ -818,11 +828,12 @@ func TestMultiSinkCache(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[3]",
|
FieldPath: "spec.containers[3]",
|
||||||
},
|
},
|
||||||
Reason: "Started",
|
Reason: "Started",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 1,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 1,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
||||||
expectUpdate: false,
|
expectUpdate: false,
|
||||||
@ -846,11 +857,12 @@ func TestMultiSinkCache(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[2]",
|
FieldPath: "spec.containers[2]",
|
||||||
},
|
},
|
||||||
Reason: "Started",
|
Reason: "Started",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 3,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 3,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[2]"}): type: 'Normal' reason: 'Started' some verbose message: 1`,
|
||||||
expectUpdate: true,
|
expectUpdate: true,
|
||||||
@ -874,11 +886,12 @@ func TestMultiSinkCache(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[3]",
|
FieldPath: "spec.containers[3]",
|
||||||
},
|
},
|
||||||
Reason: "Stopped",
|
Reason: "Stopped",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 1,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 1,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`,
|
||||||
expectUpdate: false,
|
expectUpdate: false,
|
||||||
@ -902,11 +915,12 @@ func TestMultiSinkCache(t *testing.T) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
FieldPath: "spec.containers[3]",
|
FieldPath: "spec.containers[3]",
|
||||||
},
|
},
|
||||||
Reason: "Stopped",
|
Reason: "Stopped",
|
||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: v1.EventSource{Component: "eventTest"},
|
Source: v1.EventSource{Component: "eventTest"},
|
||||||
Count: 2,
|
ReportingController: "eventTest",
|
||||||
Type: v1.EventTypeNormal,
|
Count: 2,
|
||||||
|
Type: v1.EventTypeNormal,
|
||||||
},
|
},
|
||||||
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`,
|
expectLog: `Event(v1.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"differentUid", APIVersion:"v1", ResourceVersion:"", FieldPath:"spec.containers[3]"}): type: 'Normal' reason: 'Stopped' some verbose message: 1`,
|
||||||
expectUpdate: true,
|
expectUpdate: true,
|
||||||
|
@ -115,6 +115,9 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
|
|||||||
// Temp clear time stamps for comparison because actual values don't matter for comparison
|
// Temp clear time stamps for comparison because actual values don't matter for comparison
|
||||||
recvEvent.FirstTimestamp = expectedEvent.FirstTimestamp
|
recvEvent.FirstTimestamp = expectedEvent.FirstTimestamp
|
||||||
recvEvent.LastTimestamp = expectedEvent.LastTimestamp
|
recvEvent.LastTimestamp = expectedEvent.LastTimestamp
|
||||||
|
|
||||||
|
recvEvent.ReportingController = expectedEvent.ReportingController
|
||||||
|
|
||||||
// Check that name has the right prefix.
|
// Check that name has the right prefix.
|
||||||
if n, en := recvEvent.Name, expectedEvent.Name; !strings.HasPrefix(n, en) {
|
if n, en := recvEvent.Name, expectedEvent.Name; !strings.HasPrefix(n, en) {
|
||||||
t.Errorf("%v - Name '%v' does not contain prefix '%v'", messagePrefix, n, en)
|
t.Errorf("%v - Name '%v' does not contain prefix '%v'", messagePrefix, n, en)
|
||||||
|
Loading…
Reference in New Issue
Block a user