mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #123937 from p0lyn0mial/upstream-use-initial-events-annotation-key-const
use metav1.InitialEventsAnnotationKey const
This commit is contained in:
commit
c016b0b9a8
@ -579,7 +579,7 @@ func TestCacheWatcherDrainingNoBookmarkAfterResourceVersionSent(t *testing.T) {
|
|||||||
{Type: watch.Bookmark, Object: &v1.Pod{
|
{Type: watch.Bookmark, Object: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "10",
|
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)},
|
{Type: watch.Added, Object: makePod(15)},
|
||||||
|
@ -1952,7 +1952,7 @@ func TestDoNotPopExpiredWatchersWhenNoEventsSeen(t *testing.T) {
|
|||||||
{Type: watch.Bookmark, Object: &example.Pod{
|
{Type: watch.Bookmark, Object: &example.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "102",
|
ResourceVersion: "102",
|
||||||
Annotations: map[string]string{"k8s.io/initial-events-end": "true"},
|
Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
}, true)
|
}, true)
|
||||||
|
@ -1250,7 +1250,7 @@ func RunWatchSemantics(ctx context.Context, t *testing.T, store storage.Interfac
|
|||||||
Object: &example.Pod{
|
Object: &example.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: createdInitialPods[len(createdInitialPods)-1].ResourceVersion,
|
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{
|
watchEvents = append(watchEvents, watch.Event{Type: watch.Bookmark, Object: &example.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: globalResourceVersion,
|
ResourceVersion: globalResourceVersion,
|
||||||
Annotations: map[string]string{"k8s.io/initial-events-end": "true"},
|
Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "true"},
|
||||||
},
|
},
|
||||||
}})
|
}})
|
||||||
return watchEvents
|
return watchEvents
|
||||||
|
@ -24,18 +24,12 @@ import (
|
|||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/api/validation/path"
|
"k8s.io/apimachinery/pkg/api/validation/path"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"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)
|
type SimpleUpdateFunc func(runtime.Object) (runtime.Object, error)
|
||||||
|
|
||||||
// SimpleUpdateFunc converts SimpleUpdateFunc into UpdateFunc
|
// SimpleUpdateFunc converts SimpleUpdateFunc into UpdateFunc
|
||||||
@ -140,7 +134,7 @@ func AnnotateInitialEventsEndBookmark(obj runtime.Object) error {
|
|||||||
if objAnnotations == nil {
|
if objAnnotations == nil {
|
||||||
objAnnotations = map[string]string{}
|
objAnnotations = map[string]string{}
|
||||||
}
|
}
|
||||||
objAnnotations[initialEventsAnnotationKey] = "true"
|
objAnnotations[metav1.InitialEventsAnnotationKey] = "true"
|
||||||
objMeta.SetAnnotations(objAnnotations)
|
objMeta.SetAnnotations(objAnnotations)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -153,5 +147,5 @@ func HasInitialEventsEndBookmarkAnnotation(obj runtime.Object) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
objAnnotations := objMeta.GetAnnotations()
|
objAnnotations := objMeta.GetAnnotations()
|
||||||
return objAnnotations[initialEventsAnnotationKey] == "true", nil
|
return objAnnotations[metav1.InitialEventsAnnotationKey] == "true", nil
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ func TestHasInitialEventsEndBookmarkAnnotation(t *testing.T) {
|
|||||||
createAnnotatedPod := func(name, value string) *example.Pod {
|
createAnnotatedPod := func(name, value string) *example.Pod {
|
||||||
p := createPod(name)
|
p := createPod(name)
|
||||||
p.Annotations = map[string]string{}
|
p.Annotations = map[string]string{}
|
||||||
p.Annotations["k8s.io/initial-events-end"] = value
|
p.Annotations[metav1.InitialEventsAnnotationKey] = value
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
scenarios := []struct {
|
scenarios := []struct {
|
||||||
|
@ -780,7 +780,7 @@ loop:
|
|||||||
}
|
}
|
||||||
case watch.Bookmark:
|
case watch.Bookmark:
|
||||||
// A `Bookmark` means watch has synced here, just update the resourceVersion
|
// 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 {
|
if exitOnInitialEventsEndBookmark != nil {
|
||||||
*exitOnInitialEventsEndBookmark = true
|
*exitOnInitialEventsEndBookmark = true
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ func TestWatchList(t *testing.T) {
|
|||||||
{Type: watch.Bookmark, Object: &v1.Pod{
|
{Type: watch.Bookmark, Object: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "2",
|
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{
|
{Type: watch.Bookmark, Object: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "5",
|
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{
|
{Type: watch.Bookmark, Object: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "2",
|
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{
|
{Type: watch.Bookmark, Object: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "1",
|
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{
|
{Type: watch.Bookmark, Object: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "2",
|
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")},
|
{Type: watch.Added, Object: makePod("p3", "3")},
|
||||||
@ -351,7 +351,7 @@ func TestWatchList(t *testing.T) {
|
|||||||
{Type: watch.Bookmark, Object: &v1.Pod{
|
{Type: watch.Bookmark, Object: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "2",
|
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")},
|
{Type: watch.Added, Object: makePod("p3", "3")},
|
||||||
@ -382,7 +382,7 @@ func TestWatchList(t *testing.T) {
|
|||||||
{Type: watch.Bookmark, Object: &v1.Pod{
|
{Type: watch.Bookmark, Object: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "2",
|
ResourceVersion: "2",
|
||||||
Annotations: map[string]string{"k8s.io/initial-events-end": "false"},
|
Annotations: map[string]string{metav1.InitialEventsAnnotationKey: "false"},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user