From a43f324cb9860b5c55b532fbe988f5e26740b509 Mon Sep 17 00:00:00 2001 From: Lucy Sweet Date: Fri, 17 Feb 2023 16:38:10 +0100 Subject: [PATCH 1/3] Allow inclusion of annotations in channel events when using FakeRecorder Kubernetes-commit: 9839ce96f557413f522230fa3e374e26356ae3d9 --- tools/record/fake.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/record/fake.go b/tools/record/fake.go index 0b3f344a..d18ddc82 100644 --- a/tools/record/fake.go +++ b/tools/record/fake.go @@ -28,7 +28,8 @@ import ( type FakeRecorder struct { Events chan string - IncludeObject bool + IncludeObject bool + IncludeAnnotations bool } func objectString(object runtime.Object, includeObject bool) string { @@ -54,7 +55,12 @@ func (f *FakeRecorder) Eventf(object runtime.Object, eventtype, reason, messageF } func (f *FakeRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) { - f.Eventf(object, eventtype, reason, messageFmt, args...) + if f.IncludeAnnotations { + args = append(args, fmt.Sprint(annotations)) + f.Eventf(object, eventtype, reason, messageFmt+" %s", args...) + } else { + f.Eventf(object, eventtype, reason, messageFmt, args...) + } } // NewFakeRecorder creates new fake event recorder with event channel with From f7f367ebae20f16607369d930e50827f5022924f Mon Sep 17 00:00:00 2001 From: Lucy Sweet Date: Tue, 21 Feb 2023 16:29:38 +0100 Subject: [PATCH 2/3] Respond to review Kubernetes-commit: 7a48c6e2171d23fea76b7a15ab4971989f125b96 --- tools/record/fake.go | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/record/fake.go b/tools/record/fake.go index d18ddc82..09cf3aef 100644 --- a/tools/record/fake.go +++ b/tools/record/fake.go @@ -42,25 +42,37 @@ func objectString(object runtime.Object, includeObject bool) string { ) } -func (f *FakeRecorder) Event(object runtime.Object, eventtype, reason, message string) { - if f.Events != nil { - f.Events <- fmt.Sprintf("%s %s %s%s", eventtype, reason, message, objectString(object, f.IncludeObject)) +func annotationString(annotations map[string]string, includeAnnotations bool) string { + if !includeAnnotations { + return "" } + return " " + fmt.Sprint(annotations) +} + +func (f *FakeRecorder) writeEvent(event string) { + if f.Events != nil { + f.Events <- event + } +} + +func (f *FakeRecorder) Event(object runtime.Object, eventtype, reason, message string) { + f.writeEvent(fmt.Sprintf("%s %s %s%s", eventtype, reason, message, objectString(object, f.IncludeObject))) + } func (f *FakeRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{}) { - if f.Events != nil { - f.Events <- fmt.Sprintf(eventtype+" "+reason+" "+messageFmt, args...) + objectString(object, f.IncludeObject) - } + f.writeEvent( + fmt.Sprintf(eventtype+" "+reason+" "+messageFmt, args...) + + objectString(object, f.IncludeObject), + ) } func (f *FakeRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) { - if f.IncludeAnnotations { - args = append(args, fmt.Sprint(annotations)) - f.Eventf(object, eventtype, reason, messageFmt+" %s", args...) - } else { - f.Eventf(object, eventtype, reason, messageFmt, args...) - } + f.writeEvent( + fmt.Sprintf(eventtype+" "+reason+" "+messageFmt, args...) + + objectString(object, f.IncludeObject) + + annotationString(annotations, f.IncludeAnnotations), + ) } // NewFakeRecorder creates new fake event recorder with event channel with From c633a8222b61c106ea81d08a04273b90b05e0e18 Mon Sep 17 00:00:00 2001 From: Lucy Sweet Date: Tue, 21 Feb 2023 16:42:37 +0100 Subject: [PATCH 3/3] Include annotations all the time Kubernetes-commit: 8373afef0e0886fcd05a4cbf8b0bedeaa82a4d05 --- tools/record/fake.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tools/record/fake.go b/tools/record/fake.go index 09cf3aef..a5b523fb 100644 --- a/tools/record/fake.go +++ b/tools/record/fake.go @@ -28,8 +28,7 @@ import ( type FakeRecorder struct { Events chan string - IncludeObject bool - IncludeAnnotations bool + IncludeObject bool } func objectString(object runtime.Object, includeObject bool) string { @@ -42,13 +41,6 @@ func objectString(object runtime.Object, includeObject bool) string { ) } -func annotationString(annotations map[string]string, includeAnnotations bool) string { - if !includeAnnotations { - return "" - } - return " " + fmt.Sprint(annotations) -} - func (f *FakeRecorder) writeEvent(event string) { if f.Events != nil { f.Events <- event @@ -57,7 +49,6 @@ func (f *FakeRecorder) writeEvent(event string) { func (f *FakeRecorder) Event(object runtime.Object, eventtype, reason, message string) { f.writeEvent(fmt.Sprintf("%s %s %s%s", eventtype, reason, message, objectString(object, f.IncludeObject))) - } func (f *FakeRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{}) { @@ -71,7 +62,7 @@ func (f *FakeRecorder) AnnotatedEventf(object runtime.Object, annotations map[st f.writeEvent( fmt.Sprintf(eventtype+" "+reason+" "+messageFmt, args...) + objectString(object, f.IncludeObject) + - annotationString(annotations, f.IncludeAnnotations), + " " + fmt.Sprint(annotations), ) }