diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cache_watcher_test.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cache_watcher_test.go index 1a59615ce39..e5f8181b7cf 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cache_watcher_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cache_watcher_test.go @@ -579,7 +579,7 @@ func TestCacheWatcherDrainingNoBookmarkAfterResourceVersionSent(t *testing.T) { {Type: watch.Bookmark, Object: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "10", - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }}, {Type: watch.Added, Object: makePod(15)}, diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go index 8caa3551a77..7854cc0b887 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go @@ -1952,7 +1952,7 @@ func TestDoNotPopExpiredWatchersWhenNoEventsSeen(t *testing.T) { {Type: watch.Bookmark, Object: &example.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "102", - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }}, }, true) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/testing/watcher_tests.go b/staging/src/k8s.io/apiserver/pkg/storage/testing/watcher_tests.go index 79564da9848..6b17f85d78f 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/testing/watcher_tests.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/testing/watcher_tests.go @@ -1250,7 +1250,7 @@ func RunWatchSemantics(ctx context.Context, t *testing.T, store storage.Interfac Object: &example.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: createdInitialPods[len(createdInitialPods)-1].ResourceVersion, - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }, }} @@ -1512,7 +1512,7 @@ func RunWatchSemanticInitialEventsExtended(ctx context.Context, t *testing.T, st watchEvents = append(watchEvents, watch.Event{Type: watch.Bookmark, Object: &example.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: globalResourceVersion, - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }}) return watchEvents diff --git a/staging/src/k8s.io/apiserver/pkg/storage/util.go b/staging/src/k8s.io/apiserver/pkg/storage/util.go index a98a7aa8a1f..1aca351d99f 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/util.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/util.go @@ -24,18 +24,12 @@ import ( "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/validation/path" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" ) -const ( - // initialEventsAnnotationKey the name of the key - // under which an annotation marking the end of list stream - // is kept. - initialEventsAnnotationKey = "k8s.io/initial-events-end" -) - type SimpleUpdateFunc func(runtime.Object) (runtime.Object, error) // SimpleUpdateFunc converts SimpleUpdateFunc into UpdateFunc @@ -140,7 +134,7 @@ func AnnotateInitialEventsEndBookmark(obj runtime.Object) error { if objAnnotations == nil { objAnnotations = map[string]string{} } - objAnnotations[initialEventsAnnotationKey] = "true" + objAnnotations[metav1.InitialEventsAnnotationKey] = "true" objMeta.SetAnnotations(objAnnotations) return nil } @@ -153,5 +147,5 @@ func HasInitialEventsEndBookmarkAnnotation(obj runtime.Object) (bool, error) { return false, err } objAnnotations := objMeta.GetAnnotations() - return objAnnotations[initialEventsAnnotationKey] == "true", nil + return objAnnotations[metav1.InitialEventsAnnotationKey] == "true", nil } diff --git a/staging/src/k8s.io/apiserver/pkg/storage/util_test.go b/staging/src/k8s.io/apiserver/pkg/storage/util_test.go index 8f44d44411a..ed9f43ef6a6 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/util_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/util_test.go @@ -154,7 +154,7 @@ func TestHasInitialEventsEndBookmarkAnnotation(t *testing.T) { createAnnotatedPod := func(name, value string) *example.Pod { p := createPod(name) p.Annotations = map[string]string{} - p.Annotations["k8s.io/initial-events-end"] = value + p.Annotations[metav1.InitialEventsAnnotationKey] = value return p } scenarios := []struct { diff --git a/staging/src/k8s.io/client-go/tools/cache/reflector.go b/staging/src/k8s.io/client-go/tools/cache/reflector.go index f733e244ccc..14221cd2400 100644 --- a/staging/src/k8s.io/client-go/tools/cache/reflector.go +++ b/staging/src/k8s.io/client-go/tools/cache/reflector.go @@ -780,7 +780,7 @@ loop: } case watch.Bookmark: // A `Bookmark` means watch has synced here, just update the resourceVersion - if meta.GetAnnotations()["k8s.io/initial-events-end"] == "true" { + if meta.GetAnnotations()[metav1.InitialEventsAnnotationKey] == "true" { if exitOnInitialEventsEndBookmark != nil { *exitOnInitialEventsEndBookmark = true } diff --git a/staging/src/k8s.io/client-go/tools/cache/reflector_watchlist_test.go b/staging/src/k8s.io/client-go/tools/cache/reflector_watchlist_test.go index 76eacb5a515..a2eec9193f4 100644 --- a/staging/src/k8s.io/client-go/tools/cache/reflector_watchlist_test.go +++ b/staging/src/k8s.io/client-go/tools/cache/reflector_watchlist_test.go @@ -174,7 +174,7 @@ func TestWatchList(t *testing.T) { {Type: watch.Bookmark, Object: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "2", - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }}, }, @@ -203,7 +203,7 @@ func TestWatchList(t *testing.T) { {Type: watch.Bookmark, Object: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "5", - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }}, }, @@ -241,7 +241,7 @@ func TestWatchList(t *testing.T) { {Type: watch.Bookmark, Object: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "2", - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }}, }, @@ -279,7 +279,7 @@ func TestWatchList(t *testing.T) { {Type: watch.Bookmark, Object: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "1", - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }}, }, @@ -310,7 +310,7 @@ func TestWatchList(t *testing.T) { {Type: watch.Bookmark, Object: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "2", - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }}, {Type: watch.Added, Object: makePod("p3", "3")}, @@ -351,7 +351,7 @@ func TestWatchList(t *testing.T) { {Type: watch.Bookmark, Object: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "2", - Annotations: map[string]string{"k8s.io/initial-events-end": "true"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"}, }, }}, {Type: watch.Added, Object: makePod("p3", "3")}, @@ -382,7 +382,7 @@ func TestWatchList(t *testing.T) { {Type: watch.Bookmark, Object: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "2", - Annotations: map[string]string{"k8s.io/initial-events-end": "false"}, + Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "false"}, }, }}, },