Skip to content

Commit

Permalink
Merge pull request #123937 from p0lyn0mial/upstream-use-initial-event…
Browse files Browse the repository at this point in the history
…s-annotation-key-const

use metav1.InitialEventsAnnotationKey const
  • Loading branch information
k8s-ci-robot committed Apr 18, 2024
2 parents f401f30 + a953539 commit c016b0b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
}}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions staging/src/k8s.io/apiserver/pkg/storage/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion staging/src/k8s.io/apiserver/pkg/storage/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion staging/src/k8s.io/client-go/tools/cache/reflector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
}},
},
Expand Down Expand Up @@ -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"},
},
}},
},
Expand Down Expand Up @@ -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"},
},
}},
},
Expand Down Expand Up @@ -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"},
},
}},
},
Expand Down Expand Up @@ -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")},
Expand Down Expand Up @@ -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")},
Expand Down Expand Up @@ -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"},
},
}},
},
Expand Down

0 comments on commit c016b0b

Please sign in to comment.