apiserver/storage: use metav1.InitialEventsAnnotationKey const

This commit is contained in:
Lukasz Szaszkiewicz 2024-03-11 11:40:21 +01:00
parent b3926d137c
commit ed2b92c3df
5 changed files with 8 additions and 14 deletions

View File

@ -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)},

View File

@ -1926,7 +1926,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)

View File

@ -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"},
},
},
}}
@ -1513,7 +1513,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

View File

@ -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
@ -144,7 +138,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
}
@ -157,5 +151,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
}

View File

@ -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 {