Enable propagration of HasSynced

* Add tracker types and tests
* Modify ResourceEventHandler interface's OnAdd member
* Add additional ResourceEventHandlerDetailedFuncs struct
* Fix SharedInformer to let users track HasSynced for their handlers
* Fix in-tree controllers which weren't computing HasSynced correctly
* Deprecate the cache.Pop function

Kubernetes-commit: 8100efc7b3122ad119ee8fa4bbbedef3b90f2e0d
This commit is contained in:
Daniel Smith
2022-11-18 00:12:50 +00:00
committed by Kubernetes Publisher
parent e7e7d01afd
commit 5d70a118df
11 changed files with 524 additions and 52 deletions

View File

@@ -62,7 +62,7 @@ func Example() {
// Let's implement a simple controller that just deletes
// everything that comes in.
Process: func(obj interface{}) error {
Process: func(obj interface{}, isInInitialList bool) error {
// Obj is from the Pop method of the Queue we make above.
newest := obj.(Deltas).Newest()
@@ -137,8 +137,8 @@ func ExampleNewInformer() {
source,
&v1.Pod{},
time.Millisecond*100,
ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
ResourceEventHandlerDetailedFuncs{
AddFunc: func(obj interface{}, isInInitialList bool) {
source.Delete(obj.(runtime.Object))
},
DeleteFunc: func(obj interface{}) {
@@ -213,8 +213,8 @@ func TestHammerController(t *testing.T) {
source,
&v1.Pod{},
time.Millisecond*100,
ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { recordFunc("add", obj) },
ResourceEventHandlerDetailedFuncs{
AddFunc: func(obj interface{}, isInInitialList bool) { recordFunc("add", obj) },
UpdateFunc: func(oldObj, newObj interface{}) { recordFunc("update", newObj) },
DeleteFunc: func(obj interface{}) { recordFunc("delete", obj) },
},
@@ -416,8 +416,8 @@ func TestPanicPropagated(t *testing.T) {
source,
&v1.Pod{},
time.Millisecond*100,
ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
ResourceEventHandlerDetailedFuncs{
AddFunc: func(obj interface{}, isInInitialList bool) {
// Create a panic.
panic("Just panic.")
},
@@ -526,8 +526,8 @@ func TestTransformingInformer(t *testing.T) {
source,
&v1.Pod{},
0,
ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { recordEvent(watch.Added, nil, obj) },
ResourceEventHandlerDetailedFuncs{
AddFunc: func(obj interface{}, isInInitialList bool) { recordEvent(watch.Added, nil, obj) },
UpdateFunc: func(oldObj, newObj interface{}) { recordEvent(watch.Modified, oldObj, newObj) },
DeleteFunc: func(obj interface{}) { recordEvent(watch.Deleted, obj, nil) },
},