From 92940fa80d67593c7a2333267da4424c8b45ac88 Mon Sep 17 00:00:00 2001 From: mattjmcnaughton Date: Mon, 30 Dec 2019 11:55:47 -0500 Subject: [PATCH] Remove `recorder.PastEventf` method The `recorder.PastEventf` method wasn't actually working as advertised. It was supposed to accept a timestamp, which would be used when generating the event. However, as the [source code](https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/tools/record/event.go#L316) shows, this `timestamp` was never actually used. In other words, `PastEventf` is identical to `Eventf`. We have two options: one would be to fix `PastEventf` so that it works as advertised. The other would be to delete `PastEventf` and only support `Eventf`. Ultimately, I could only find one use of `PastEventf` in the code base, so I propose we just delete `PastEventf` and convert all uses to `Eventf`. --- pkg/controller/testutil/test_utils.go | 4 ---- pkg/kubelet/container/BUILD | 1 - pkg/kubelet/container/helpers.go | 7 ------- pkg/kubelet/oom/BUILD | 2 -- pkg/kubelet/oom/oom_watcher_linux.go | 3 +-- staging/src/k8s.io/client-go/tools/record/event.go | 7 ------- staging/src/k8s.io/client-go/tools/record/fake.go | 4 ---- 7 files changed, 1 insertion(+), 27 deletions(-) diff --git a/pkg/controller/testutil/test_utils.go b/pkg/controller/testutil/test_utils.go index d94576ed495..807139524ff 100644 --- a/pkg/controller/testutil/test_utils.go +++ b/pkg/controller/testutil/test_utils.go @@ -368,10 +368,6 @@ func (f *FakeRecorder) Eventf(obj runtime.Object, eventtype, reason, messageFmt f.Event(obj, eventtype, reason, fmt.Sprintf(messageFmt, args...)) } -// PastEventf is a no-op -func (f *FakeRecorder) PastEventf(obj runtime.Object, timestamp metav1.Time, eventtype, reason, messageFmt string, args ...interface{}) { -} - // AnnotatedEventf emits a fake formatted event to the fake recorder func (f *FakeRecorder) AnnotatedEventf(obj runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) { f.Eventf(obj, eventtype, reason, messageFmt, args...) diff --git a/pkg/kubelet/container/BUILD b/pkg/kubelet/container/BUILD index 4ca7352fb16..6d99107060c 100644 --- a/pkg/kubelet/container/BUILD +++ b/pkg/kubelet/container/BUILD @@ -25,7 +25,6 @@ go_library( "//pkg/util/hash:go_default_library", "//pkg/volume:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library", diff --git a/pkg/kubelet/container/helpers.go b/pkg/kubelet/container/helpers.go index 71475aa9d56..ae74305f093 100644 --- a/pkg/kubelet/container/helpers.go +++ b/pkg/kubelet/container/helpers.go @@ -25,7 +25,6 @@ import ( "k8s.io/klog" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" @@ -210,12 +209,6 @@ func (irecorder *innerEventRecorder) Eventf(object runtime.Object, eventtype, re } -func (irecorder *innerEventRecorder) PastEventf(object runtime.Object, timestamp metav1.Time, eventtype, reason, messageFmt string, args ...interface{}) { - if ref, ok := irecorder.shouldRecordEvent(object); ok { - irecorder.recorder.PastEventf(ref, timestamp, eventtype, reason, messageFmt, args...) - } -} - func (irecorder *innerEventRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) { if ref, ok := irecorder.shouldRecordEvent(object); ok { irecorder.recorder.AnnotatedEventf(ref, annotations, eventtype, reason, messageFmt, args...) diff --git a/pkg/kubelet/oom/BUILD b/pkg/kubelet/oom/BUILD index f1ca684af36..0a550c46458 100644 --- a/pkg/kubelet/oom/BUILD +++ b/pkg/kubelet/oom/BUILD @@ -13,7 +13,6 @@ go_library( "//staging/src/k8s.io/api/core/v1:go_default_library", ] + select({ "@io_bazel_rules_go//go/platform:android": [ - "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library", "//staging/src/k8s.io/client-go/tools/record:go_default_library", "//vendor/github.com/google/cadvisor/utils/oomparser:go_default_library", @@ -32,7 +31,6 @@ go_library( "//staging/src/k8s.io/client-go/tools/record:go_default_library", ], "@io_bazel_rules_go//go/platform:linux": [ - "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library", "//staging/src/k8s.io/client-go/tools/record:go_default_library", "//vendor/github.com/google/cadvisor/utils/oomparser:go_default_library", diff --git a/pkg/kubelet/oom/oom_watcher_linux.go b/pkg/kubelet/oom/oom_watcher_linux.go index dd8fcc39ee0..cf015f841ff 100644 --- a/pkg/kubelet/oom/oom_watcher_linux.go +++ b/pkg/kubelet/oom/oom_watcher_linux.go @@ -22,7 +22,6 @@ import ( "fmt" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/tools/record" "k8s.io/klog" @@ -64,7 +63,7 @@ func (ow *realWatcher) Start(ref *v1.ObjectReference) error { if event.ProcessName != "" && event.Pid != 0 { eventMsg = fmt.Sprintf("%s, victim process: %s, pid: %d", eventMsg, event.ProcessName, event.Pid) } - ow.recorder.PastEventf(ref, metav1.Time{Time: event.TimeOfDeath}, v1.EventTypeWarning, systemOOMEvent, eventMsg) + ow.recorder.Eventf(ref, v1.EventTypeWarning, systemOOMEvent, eventMsg) } } klog.Errorf("Unexpectedly stopped receiving OOM notifications") diff --git a/staging/src/k8s.io/client-go/tools/record/event.go b/staging/src/k8s.io/client-go/tools/record/event.go index 66f8bd634e8..64d1fd2d789 100644 --- a/staging/src/k8s.io/client-go/tools/record/event.go +++ b/staging/src/k8s.io/client-go/tools/record/event.go @@ -102,9 +102,6 @@ type EventRecorder interface { // Eventf is just like Event, but with Sprintf for the message field. Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{}) - // PastEventf is just like Eventf, but with an option to specify the event's 'timestamp' field. - PastEventf(object runtime.Object, timestamp metav1.Time, eventtype, reason, messageFmt string, args ...interface{}) - // AnnotatedEventf is just like eventf, but with annotations attached AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) } @@ -343,10 +340,6 @@ func (recorder *recorderImpl) Eventf(object runtime.Object, eventtype, reason, m recorder.Event(object, eventtype, reason, fmt.Sprintf(messageFmt, args...)) } -func (recorder *recorderImpl) PastEventf(object runtime.Object, timestamp metav1.Time, eventtype, reason, messageFmt string, args ...interface{}) { - recorder.generateEvent(object, nil, timestamp, eventtype, reason, fmt.Sprintf(messageFmt, args...)) -} - func (recorder *recorderImpl) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) { recorder.generateEvent(object, annotations, metav1.Now(), eventtype, reason, fmt.Sprintf(messageFmt, args...)) } diff --git a/staging/src/k8s.io/client-go/tools/record/fake.go b/staging/src/k8s.io/client-go/tools/record/fake.go index 6e031daaff8..8546c1dd1c7 100644 --- a/staging/src/k8s.io/client-go/tools/record/fake.go +++ b/staging/src/k8s.io/client-go/tools/record/fake.go @@ -19,7 +19,6 @@ package record import ( "fmt" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -42,9 +41,6 @@ func (f *FakeRecorder) Eventf(object runtime.Object, eventtype, reason, messageF } } -func (f *FakeRecorder) PastEventf(object runtime.Object, timestamp metav1.Time, eventtype, reason, messageFmt string, args ...interface{}) { -} - func (f *FakeRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) { f.Eventf(object, eventtype, reason, messageFmt, args) }