diff --git a/vendor/github.com/openshift/library-go/pkg/operator/staticpod/controllers.go b/vendor/github.com/openshift/library-go/pkg/operator/staticpod/controllers.go index e6f0c6091e..ff8ca7f74f 100644 --- a/vendor/github.com/openshift/library-go/pkg/operator/staticpod/controllers.go +++ b/vendor/github.com/openshift/library-go/pkg/operator/staticpod/controllers.go @@ -237,12 +237,12 @@ func (b *staticPodOperatorControllerBuilder) ToControllers() (manager.Controller // ensure that all controllers that need the secret/configmap informer-based clients // need to wait for their synchronization before starting using WithInformer - configMapClient := v1helpers.CachedConfigMapGetter(b.kubeClient.CoreV1(), b.kubeNamespaceInformers) - secretClient := v1helpers.CachedSecretGetter(b.kubeClient.CoreV1(), b.kubeNamespaceInformers) + operandInformers := b.kubeNamespaceInformers.InformersFor(b.operandNamespace) + configMapClient := v1helpers.NewNamespacedCachedConfigMapGetter(b.kubeClient.CoreV1(), operandInformers, b.operandNamespace) + secretClient := v1helpers.NewNamespacedCachedSecretGetter(b.kubeClient.CoreV1(), operandInformers, b.operandNamespace) podClient := b.kubeClient.CoreV1() eventsClient := b.kubeClient.CoreV1() pdbClient := b.kubeClient.PolicyV1() - operandInformers := b.kubeNamespaceInformers.InformersFor(b.operandNamespace) clusterInformers := b.kubeClusterInformers infraInformers := b.configInformers.Config().V1().Infrastructures() diff --git a/vendor/github.com/openshift/library-go/pkg/operator/v1helpers/core_getters.go b/vendor/github.com/openshift/library-go/pkg/operator/v1helpers/core_getters.go index bdfe17d92a..b5672ca2c1 100644 --- a/vendor/github.com/openshift/library-go/pkg/operator/v1helpers/core_getters.go +++ b/vendor/github.com/openshift/library-go/pkg/operator/v1helpers/core_getters.go @@ -8,6 +8,7 @@ import ( "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/informers" corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1listers "k8s.io/client-go/listers/core/v1" ) @@ -17,11 +18,14 @@ var ( emptyListOptions = metav1.ListOptions{} ) +// combinedConfigMapGetter implements corev1client.ConfigMapsGetter using a client and a KubeInformersForNamespaces. type combinedConfigMapGetter struct { client corev1client.ConfigMapsGetter listers KubeInformersForNamespaces } +// CachedConfigMapGetter returns a corev1client.ConfigMapsGetter that uses cached informers +// from KubeInformersForNamespaces for read operations. Write operations are delegated to the provided client. func CachedConfigMapGetter(client corev1client.ConfigMapsGetter, listers KubeInformersForNamespaces) corev1client.ConfigMapsGetter { return &combinedConfigMapGetter{ client: client, @@ -29,12 +33,14 @@ func CachedConfigMapGetter(client corev1client.ConfigMapsGetter, listers KubeInf } } +// combinedConfigMapInterface implements corev1client.ConfigMapInterface using a client and a namespaced lister. type combinedConfigMapInterface struct { corev1client.ConfigMapInterface lister corev1listers.ConfigMapNamespaceLister namespace string } +// ConfigMaps returns a combinedConfigMapInterface for the given namespace. func (g combinedConfigMapGetter) ConfigMaps(namespace string) corev1client.ConfigMapInterface { return combinedConfigMapInterface{ ConfigMapInterface: g.client.ConfigMaps(namespace), @@ -43,6 +49,7 @@ func (g combinedConfigMapGetter) ConfigMaps(namespace string) corev1client.Confi } } +// Get retrieves a ConfigMap from the cache. GetOptions are not honored. func (g combinedConfigMapInterface) Get(_ context.Context, name string, options metav1.GetOptions) (*corev1.ConfigMap, error) { if !equality.Semantic.DeepEqual(options, emptyGetOptions) { return nil, fmt.Errorf("GetOptions are not honored by cached client: %#v", options) @@ -54,6 +61,8 @@ func (g combinedConfigMapInterface) Get(_ context.Context, name string, options } return ret.DeepCopy(), nil } + +// List retrieves a list of ConfigMaps from the cache. ListOptions are not honored. func (g combinedConfigMapInterface) List(_ context.Context, options metav1.ListOptions) (*corev1.ConfigMapList, error) { if !equality.Semantic.DeepEqual(options, emptyListOptions) { return nil, fmt.Errorf("ListOptions are not honored by cached client: %#v", options) @@ -71,11 +80,14 @@ func (g combinedConfigMapInterface) List(_ context.Context, options metav1.ListO return ret, nil } +// combinedSecretGetter implements corev1client.SecretsGetter using a client and a KubeInformersForNamespaces. type combinedSecretGetter struct { client corev1client.SecretsGetter listers KubeInformersForNamespaces } +// CachedSecretGetter returns a corev1client.SecretsGetter that uses cached informers +// from KubeInformersForNamespaces for read operations. Write operations are delegated to the provided client. func CachedSecretGetter(client corev1client.SecretsGetter, listers KubeInformersForNamespaces) corev1client.SecretsGetter { return &combinedSecretGetter{ client: client, @@ -83,12 +95,14 @@ func CachedSecretGetter(client corev1client.SecretsGetter, listers KubeInformers } } +// combinedSecretInterface implements corev1client.SecretInterface using a client and a namespaced lister. type combinedSecretInterface struct { corev1client.SecretInterface lister corev1listers.SecretNamespaceLister namespace string } +// Secrets returns a combinedSecretInterface for the given namespace. func (g combinedSecretGetter) Secrets(namespace string) corev1client.SecretInterface { return combinedSecretInterface{ SecretInterface: g.client.Secrets(namespace), @@ -97,6 +111,7 @@ func (g combinedSecretGetter) Secrets(namespace string) corev1client.SecretInter } } +// Get retrieves a Secret from the cache. GetOptions are not honored. func (g combinedSecretInterface) Get(_ context.Context, name string, options metav1.GetOptions) (*corev1.Secret, error) { if !equality.Semantic.DeepEqual(options, emptyGetOptions) { return nil, fmt.Errorf("GetOptions are not honored by cached client: %#v", options) @@ -109,6 +124,7 @@ func (g combinedSecretInterface) Get(_ context.Context, name string, options met return ret.DeepCopy(), nil } +// List retrieves a list of Secrets from the cache. ListOptions are not honored. func (g combinedSecretInterface) List(_ context.Context, options metav1.ListOptions) (*corev1.SecretList, error) { if !equality.Semantic.DeepEqual(options, emptyListOptions) { return nil, fmt.Errorf("ListOptions are not honored by cached client: %#v", options) @@ -125,3 +141,71 @@ func (g combinedSecretInterface) List(_ context.Context, options metav1.ListOpti } return ret, nil } + +// namespacedConfigMapGetter implements corev1client.ConfigMapsGetter +// for a single, predefined namespace, using a shared informer for cached reads. +type namespacedConfigMapGetter struct { + client corev1client.ConfigMapsGetter + informerFactory informers.SharedInformerFactory + namespace string // The specific namespace this getter is for +} + +// NewNamespacedCachedConfigMapGetter returns a corev1client.ConfigMapsGetter that is scoped to a specific namespace. +// Read operations for the specified namespace will use the shared informer cache. +// Read operations for other namespaces (if any) and all write operations will be delegated to the provided client. +func NewNamespacedCachedConfigMapGetter(client corev1client.ConfigMapsGetter, informerFactory informers.SharedInformerFactory, namespace string) corev1client.ConfigMapsGetter { + return &namespacedConfigMapGetter{ + client: client, + informerFactory: informerFactory, + namespace: namespace, + } +} + +// ConfigMaps returns a ConfigMapInterface. If the requested namespace matches the predefined namespace, +// it returns a cached interface. Otherwise, it returns the client's direct interface. +func (g *namespacedConfigMapGetter) ConfigMaps(namespace string) corev1client.ConfigMapInterface { + // If the requested namespace matches the getter's predefined namespace, use the cached interface. + if namespace == g.namespace { + return combinedConfigMapInterface{ + ConfigMapInterface: g.client.ConfigMaps(namespace), // Delegate write operations + lister: g.informerFactory.Core().V1().ConfigMaps().Lister().ConfigMaps(namespace), + namespace: namespace, + } + } + // For any other namespace, or if it's not the designated namespace, delegate to the uncached client. + return g.client.ConfigMaps(namespace) +} + +// namespacedSecretGetter implements corev1client.SecretsGetter +// for a single, predefined namespace, using a shared informer for cached reads. +type namespacedSecretGetter struct { + client corev1client.SecretsGetter + informerFactory informers.SharedInformerFactory + namespace string // The specific namespace this getter is for +} + +// NewNamespacedCachedSecretGetter returns a corev1client.SecretsGetter that is scoped to a specific namespace. +// Read operations for the specified namespace will use the shared informer cache. +// Read operations for other namespaces (if any) and all write operations will be delegated to the provided client. +func NewNamespacedCachedSecretGetter(client corev1client.SecretsGetter, informerFactory informers.SharedInformerFactory, namespace string) corev1client.SecretsGetter { + return &namespacedSecretGetter{ + client: client, + informerFactory: informerFactory, + namespace: namespace, + } +} + +// Secrets returns a SecretInterface. If the requested namespace matches the predefined namespace, +// it returns a cached interface. Otherwise, it returns the client's direct interface. +func (g *namespacedSecretGetter) Secrets(namespace string) corev1client.SecretInterface { + // If the requested namespace matches the getter's predefined namespace, use the cached interface. + if namespace == g.namespace { + return combinedSecretInterface{ + SecretInterface: g.client.Secrets(namespace), // Delegate write operations + lister: g.informerFactory.Core().V1().Secrets().Lister().Secrets(namespace), + namespace: namespace, + } + } + // For any other namespace, or if it's not the designated namespace, delegate to the uncached client. + return g.client.Secrets(namespace) +}