From 0a4f4cea28bb9d78d996014e36d7e83438d8660f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Luk=C5=A1a?= Date: Thu, 22 Sep 2022 18:11:40 +0200 Subject: [PATCH] OSSM-2006 Alternative fix for informer.HasSynced() --- client/xnsinformer/factory.go | 8 ++-- go.mod | 2 + go.sum | 4 +- .../xns-informer-gen/generators/factory.go | 10 ++--- .../xns-informer/pkg/informers/dynamic.go | 8 ++-- .../xns-informer/pkg/informers/metadata.go | 8 ++-- .../pkg/informers/namespace_set.go | 37 ++++++++++++------- vendor/modules.txt | 3 +- 8 files changed, 46 insertions(+), 34 deletions(-) diff --git a/client/xnsinformer/factory.go b/client/xnsinformer/factory.go index 59b08c73..9c399843 100644 --- a/client/xnsinformer/factory.go +++ b/client/xnsinformer/factory.go @@ -70,7 +70,7 @@ func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFu // WithNamespaces limits the SharedInformerFactory to the specified namespaces. func WithNamespaces(namespaces ...string) SharedInformerOption { return func(factory *sharedInformerFactory) *sharedInformerFactory { - factory.SetNamespaces(namespaces...) + factory.SetNamespaces(namespaces) return factory } } @@ -100,11 +100,11 @@ func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResy } // SetNamespaces updates the set of namespaces for all current and future informers. -func (f *sharedInformerFactory) SetNamespaces(namespaces ...string) { +func (f *sharedInformerFactory) SetNamespaces(namespaces []string) { f.lock.Lock() defer f.lock.Unlock() - f.namespaces.SetNamespaces(namespaces...) + f.namespaces.SetNamespaces(namespaces) } // Start initializes all requested informers. @@ -169,7 +169,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal // API group versions. type SharedInformerFactory interface { internalinterfaces.SharedInformerFactory - SetNamespaces(namespaces ...string) + SetNamespaces(namespaces []string) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool diff --git a/go.mod b/go.mod index c9a0cf85..207bbd1e 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module maistra.io/api go 1.15 +replace github.com/maistra/xns-informer => github.com/luksa/xns-informer v0.0.0-20221007103507-5488f0815e0f + require ( github.com/ghodss/yaml v1.0.0 github.com/gogo/protobuf v1.3.2 diff --git a/go.sum b/go.sum index aff18800..74087eea 100644 --- a/go.sum +++ b/go.sum @@ -331,14 +331,14 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc= +github.com/luksa/xns-informer v0.0.0-20221007103507-5488f0815e0f h1:GB/Jedxbj3kBWN+V4FxkQvMZd2ghwkMlfzG4LPRqQUw= +github.com/luksa/xns-informer v0.0.0-20221007103507-5488f0815e0f/go.mod h1:0ZUF4kjow/MlN7Gp6OY7w2qBsWSG4MDBNxUp1VSSs/A= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/maistra/xns-informer v0.0.0-20220920101259-8467c347491a h1:0eb/ZjoJgg7QjUMKy9nPbjztSiiYgH68ZblO2zqimw0= -github.com/maistra/xns-informer v0.0.0-20220920101259-8467c347491a/go.mod h1:0ZUF4kjow/MlN7Gp6OY7w2qBsWSG4MDBNxUp1VSSs/A= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= diff --git a/vendor/github.com/maistra/xns-informer/cmd/xns-informer-gen/generators/factory.go b/vendor/github.com/maistra/xns-informer/cmd/xns-informer-gen/generators/factory.go index 6d28a3a3..02db8b33 100644 --- a/vendor/github.com/maistra/xns-informer/cmd/xns-informer-gen/generators/factory.go +++ b/vendor/github.com/maistra/xns-informer/cmd/xns-informer-gen/generators/factory.go @@ -140,7 +140,7 @@ func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFu // WithNamespaces limits the SharedInformerFactory to the specified namespaces. func WithNamespaces(namespaces ...string) SharedInformerOption { return func(factory *sharedInformerFactory) *sharedInformerFactory { - factory.SetNamespaces(namespaces...) + factory.SetNamespaces(namespaces) return factory } } @@ -154,7 +154,7 @@ func NewSharedInformerFactory(client {{.clientSetInterface|raw}}, defaultResync func NewSharedInformerFactoryWithOptions(client {{.clientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}, options ...SharedInformerOption) SharedInformerFactory { factory := &sharedInformerFactory{ client: client, - namespaces: {{.xnsNewNamespaceSet|raw}}(), + namespaces: {{.xnsNewNamespaceSet|raw}}(v1.NamespaceAll), defaultResync: defaultResync, informers: make(map[{{.reflectType|raw}}]{{.cacheSharedIndexInformer|raw}}), startedInformers: make(map[{{.reflectType|raw}}]bool), @@ -170,11 +170,11 @@ func NewSharedInformerFactoryWithOptions(client {{.clientSetInterface|raw}}, def } // SetNamespaces updates the set of namespaces for all current and future informers. -func (f *sharedInformerFactory) SetNamespaces(namespaces ...string) { +func (f *sharedInformerFactory) SetNamespaces(namespaces []string) { f.lock.Lock() defer f.lock.Unlock() - f.namespaces.SetNamespaces(namespaces...) + f.namespaces.SetNamespaces(namespaces) } // Start initializes all requested informers. @@ -242,7 +242,7 @@ var sharedInformerFactoryInterface = ` // API group versions. type SharedInformerFactory interface { {{.informerFactoryInterface|raw}} - SetNamespaces(namespaces ...string) + SetNamespaces(namespaces []string) ForResource(resource {{.schemaGroupVersionResource|raw}}) (GenericInformer, error) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool diff --git a/vendor/github.com/maistra/xns-informer/pkg/informers/dynamic.go b/vendor/github.com/maistra/xns-informer/pkg/informers/dynamic.go index 008ffe6e..90a434e3 100644 --- a/vendor/github.com/maistra/xns-informer/pkg/informers/dynamic.go +++ b/vendor/github.com/maistra/xns-informer/pkg/informers/dynamic.go @@ -22,14 +22,14 @@ import ( // namespaces, it will not work for cluster-scoped resources. type DynamicSharedInformerFactory interface { Start(stopCh <-chan struct{}) - SetNamespaces(namespaces ...string) + SetNamespaces(namespaces []string) ForResource(gvr schema.GroupVersionResource) informers.GenericInformer WaitForCacheSync(stopCh <-chan struct{}) map[schema.GroupVersionResource]bool } // NewDynamicSharedInformerFactory constructs a new instance of dynamicSharedInformerFactory for all namespaces. func NewDynamicSharedInformerFactory(client dynamic.Interface, defaultResync time.Duration) DynamicSharedInformerFactory { - namespaces := NewNamespaceSet() + namespaces := NewNamespaceSet(metav1.NamespaceAll) return NewFilteredDynamicSharedInformerFactory(client, defaultResync, namespaces, nil) } @@ -86,11 +86,11 @@ func (f *dynamicSharedInformerFactory) ForResource(gvr schema.GroupVersionResour } // SetNamespaces updates the set of namespaces for all current and future informers. -func (f *dynamicSharedInformerFactory) SetNamespaces(namespaces ...string) { +func (f *dynamicSharedInformerFactory) SetNamespaces(namespaces []string) { f.lock.Lock() defer f.lock.Unlock() - f.namespaces.SetNamespaces(namespaces...) + f.namespaces.SetNamespaces(namespaces) } // Start initializes all requested informers. diff --git a/vendor/github.com/maistra/xns-informer/pkg/informers/metadata.go b/vendor/github.com/maistra/xns-informer/pkg/informers/metadata.go index c87f5d61..8925f5dc 100644 --- a/vendor/github.com/maistra/xns-informer/pkg/informers/metadata.go +++ b/vendor/github.com/maistra/xns-informer/pkg/informers/metadata.go @@ -18,14 +18,14 @@ import ( // MetadataSharedInformerFactory provides access to shared informers and listers for metadata client. type MetadataSharedInformerFactory interface { Start(stopCh <-chan struct{}) - SetNamespaces(namespaces ...string) + SetNamespaces(namespaces []string) ForResource(gvr schema.GroupVersionResource) informers.GenericInformer WaitForCacheSync(stopCh <-chan struct{}) map[schema.GroupVersionResource]bool } // NewMetadataSharedInformerFactory constructs a new instance of metadataSharedInformerFactory for all namespaces. func NewMetadataSharedInformerFactory(client metadata.Interface, defaultResync time.Duration) MetadataSharedInformerFactory { - namespaces := NewNamespaceSet() + namespaces := NewNamespaceSet(metav1.NamespaceAll) return NewFilteredMetadataSharedInformerFactory(client, defaultResync, namespaces, nil) } @@ -74,11 +74,11 @@ func (f *metadataSharedInformerFactory) ForResource(gvr schema.GroupVersionResou } // SetNamespaces updates the set of namespaces for all current and future informers. -func (f *metadataSharedInformerFactory) SetNamespaces(namespaces ...string) { +func (f *metadataSharedInformerFactory) SetNamespaces(namespaces []string) { f.lock.Lock() defer f.lock.Unlock() - f.namespaces.SetNamespaces(namespaces...) + f.namespaces.SetNamespaces(namespaces) } // Start initializes all requested informers. diff --git a/vendor/github.com/maistra/xns-informer/pkg/informers/namespace_set.go b/vendor/github.com/maistra/xns-informer/pkg/informers/namespace_set.go index 01002afa..8174aea6 100644 --- a/vendor/github.com/maistra/xns-informer/pkg/informers/namespace_set.go +++ b/vendor/github.com/maistra/xns-informer/pkg/informers/namespace_set.go @@ -42,22 +42,30 @@ func (h NamespaceSetHandlerFuncs) OnRemove(namespace string) { type NamespaceSet interface { // Initialized returns true if SetNamespaces() has been called at least once Initialized() bool - SetNamespaces(namespaces ...string) + SetNamespaces(namespaces []string) AddHandler(handler NamespaceSetHandler) Contains(namespace string) bool List() []string } type namespaceSet struct { - initialized bool - lock sync.Mutex - namespaces sets.Set - handlers []NamespaceSetHandler + lock sync.Mutex + namespaces sets.Set + handlers []NamespaceSetHandler } -// NewNamespaceSet returns a new NamespaceSet. -func NewNamespaceSet() NamespaceSet { - return &namespaceSet{} +// NewNamespaceSet returns a new NamespaceSet tracking the given namespaces. +func NewNamespaceSet(namespaces ...string) NamespaceSet { + n := &namespaceSet{} + n.SetNamespaces(namespaces) + + return n +} + +// NewUninitializedNamespaceSet returns a new uninitialized NamespaceSet +func NewUninitializedNamespaceSet() NamespaceSet { + n := &namespaceSet{} + return n } // Contains indicates whether the given namespace is in the set. @@ -83,20 +91,21 @@ func (n *namespaceSet) Initialized() bool { n.lock.Lock() defer n.lock.Unlock() - return n.initialized + return n.namespaces != nil } // SetNamespaces replaces the set of namespaces. -func (n *namespaceSet) SetNamespaces(namespaces ...string) { +func (n *namespaceSet) SetNamespaces(namespaces []string) { n.lock.Lock() defer n.lock.Unlock() - if !n.initialized { - n.initialized = true + var newNamespaceSet sets.Set + if namespaces == nil { + newNamespaceSet = nil + } else { + newNamespaceSet = sets.NewSet(namespaces...) } - newNamespaceSet := sets.NewSet(namespaces...) - // If the set of namespaces, includes metav1.NamespaceAll, then it // only makes sense to track that. if newNamespaceSet.Contains(metav1.NamespaceAll) { diff --git a/vendor/modules.txt b/vendor/modules.txt index 62eda0a2..f531d7fd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -41,7 +41,7 @@ github.com/imdario/mergo github.com/inconshreveable/mousetrap # github.com/json-iterator/go v1.1.11 github.com/json-iterator/go -# github.com/maistra/xns-informer v0.0.0-20220920101259-8467c347491a +# github.com/maistra/xns-informer v0.0.0-20220920101259-8467c347491a => github.com/luksa/xns-informer v0.0.0-20221007103507-5488f0815e0f ## explicit github.com/maistra/xns-informer/cmd/xns-informer-gen github.com/maistra/xns-informer/cmd/xns-informer-gen/args @@ -588,4 +588,5 @@ sigs.k8s.io/structured-merge-diff/v4/value # sigs.k8s.io/yaml v1.3.0 ## explicit sigs.k8s.io/yaml +# github.com/maistra/xns-informer => github.com/luksa/xns-informer v0.0.0-20221007103507-5488f0815e0f # github.com/go-logr/zapr => github.com/go-logr/zapr v0.2.0