mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-17 15:13:08 +00:00
Add EventSource to api to have both Component and Host information.
This commit is contained in:
@@ -41,13 +41,13 @@ type EventRecorder interface {
|
||||
// StartRecording starts sending events to recorder. Call once while initializing
|
||||
// your binary. Subsequent calls will be ignored. The return value can be ignored
|
||||
// or used to stop recording, if desired.
|
||||
func StartRecording(recorder EventRecorder, sourceName string) watch.Interface {
|
||||
func StartRecording(recorder EventRecorder, source api.EventSource) watch.Interface {
|
||||
return GetEvents(func(event *api.Event) {
|
||||
// Make a copy before modification, because there could be multiple listeners.
|
||||
// Events are safe to copy like this.
|
||||
eventCopy := *event
|
||||
event = &eventCopy
|
||||
event.Source = sourceName
|
||||
event.Source = source
|
||||
try := 0
|
||||
for {
|
||||
try++
|
||||
|
@@ -89,7 +89,7 @@ func TestEventf(t *testing.T) {
|
||||
Condition: "Running",
|
||||
Reason: "Started",
|
||||
Message: "some verbose message: 1",
|
||||
Source: "eventTest",
|
||||
Source: api.EventSource{Component: "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`,
|
||||
},
|
||||
@@ -114,7 +114,7 @@ func TestEventf(t *testing.T) {
|
||||
Condition: "Running",
|
||||
Reason: "Started",
|
||||
Message: "some verbose message: 1",
|
||||
Source: "eventTest",
|
||||
Source: api.EventSource{Component: "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`,
|
||||
},
|
||||
@@ -142,7 +142,7 @@ func TestEventf(t *testing.T) {
|
||||
return event, nil
|
||||
},
|
||||
}
|
||||
recorder := record.StartRecording(&testEvents, "eventTest")
|
||||
recorder := record.StartRecording(&testEvents, api.EventSource{Component: "eventTest"})
|
||||
logger := record.StartLogging(t.Logf) // Prove that it is useful
|
||||
logger2 := record.StartLogging(func(formatter string, args ...interface{}) {
|
||||
if e, a := item.expectLog, fmt.Sprintf(formatter, args...); e != a {
|
||||
@@ -223,7 +223,7 @@ func TestWriteEventError(t *testing.T) {
|
||||
return event, nil
|
||||
},
|
||||
},
|
||||
"eventTest",
|
||||
api.EventSource{Component: "eventTest"},
|
||||
).Stop()
|
||||
|
||||
for caseName := range table {
|
||||
|
Reference in New Issue
Block a user