From 7ee36ee7140dbdadf4d081a8e61ce2c9b6079c9e 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 1f70a72f..fd4a4f41 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-20221007113855-42ea70af8076 + require ( github.com/ghodss/yaml v1.0.0 github.com/gogo/protobuf v1.3.1 diff --git a/go.sum b/go.sum index 32975a1c..0df9266e 100644 --- a/go.sum +++ b/go.sum @@ -316,6 +316,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/luksa/xns-informer v0.0.0-20221007113855-42ea70af8076 h1:prVeSFqnQj56i9MQJGUW0SNycFgE71yZ05o9nLZTyug= +github.com/luksa/xns-informer v0.0.0-20221007113855-42ea70af8076/go.mod h1:Bwe3VRiuXlSXu8MktDkmbrFcmSDysxuoOra542o0Ljk= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -324,8 +326,6 @@ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN 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/maistra/xns-informer v0.0.0-20220920133259-f0b868f688e0 h1:RncQuyq1CZPFwnf8O/kAuQJFj1A4M1jwptfr0WHmuCw= -github.com/maistra/xns-informer v0.0.0-20220920133259-f0b868f688e0/go.mod h1:Bwe3VRiuXlSXu8MktDkmbrFcmSDysxuoOra542o0Ljk= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 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 d813b99d..1dd891f2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -45,7 +45,7 @@ github.com/imdario/mergo github.com/inconshreveable/mousetrap # github.com/json-iterator/go v1.1.10 github.com/json-iterator/go -# github.com/maistra/xns-informer v0.0.0-20220920133259-f0b868f688e0 +# github.com/maistra/xns-informer v0.0.0-20220920133259-f0b868f688e0 => github.com/luksa/xns-informer v0.0.0-20221007113855-42ea70af8076 ## explicit github.com/maistra/xns-informer/cmd/xns-informer-gen github.com/maistra/xns-informer/cmd/xns-informer-gen/args @@ -548,4 +548,5 @@ sigs.k8s.io/structured-merge-diff/v4/value # sigs.k8s.io/yaml v1.2.0 ## explicit sigs.k8s.io/yaml +# github.com/maistra/xns-informer => github.com/luksa/xns-informer v0.0.0-20221007113855-42ea70af8076 # github.com/go-logr/zapr => github.com/go-logr/zapr v0.2.0