From 79b4d4150180456767b676a75939d124d3783386 Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Wed, 29 Nov 2023 09:27:24 -0700 Subject: [PATCH] registry/controller: use a live client for configmaps ConfigMaps provided for the internal source type are user-created and won't have our labels, so we need to use a live client to fetch them. Signed-off-by: Steve Kuznetsov --- pkg/controller/registry/reconciler/configmap.go | 6 ++++-- pkg/controller/registry/reconciler/configmap_test.go | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/controller/registry/reconciler/configmap.go b/pkg/controller/registry/reconciler/configmap.go index 2fdb4775b6..8ab69d3abb 100644 --- a/pkg/controller/registry/reconciler/configmap.go +++ b/pkg/controller/registry/reconciler/configmap.go @@ -290,9 +290,11 @@ func (c *ConfigMapRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry, if source.Spec.SourceType == v1alpha1.SourceTypeConfigmap || source.Spec.SourceType == v1alpha1.SourceTypeInternal { // fetch configmap first, exit early if we can't find it - configMap, err := c.Lister.CoreV1().ConfigMapLister().ConfigMaps(source.GetNamespace()).Get(source.Spec.ConfigMap) + // we use the live client here instead of a lister since our listers are scoped to objects with the olm.managed label, + // and this configmap is a user-provided input to the catalog source and will not have that label + configMap, err := c.OpClient.KubernetesInterface().CoreV1().ConfigMaps(source.GetNamespace()).Get(context.TODO(), source.Spec.ConfigMap, metav1.GetOptions{}) if err != nil { - return fmt.Errorf("unable to get configmap %s/%s from cache", source.GetNamespace(), source.Spec.ConfigMap) + return fmt.Errorf("unable to find configmap %s/%s: %w", source.GetNamespace(), source.Spec.ConfigMap, err) } if source.ConfigMapChanges(configMap) { diff --git a/pkg/controller/registry/reconciler/configmap_test.go b/pkg/controller/registry/reconciler/configmap_test.go index 04f7644594..7e6b1dcd76 100644 --- a/pkg/controller/registry/reconciler/configmap_test.go +++ b/pkg/controller/registry/reconciler/configmap_test.go @@ -299,13 +299,17 @@ func TestConfigMapRegistryReconciler(t *testing.T) { in: in{ cluster: cluster{}, catsrc: &v1alpha1.CatalogSource{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "test-ns", + }, Spec: v1alpha1.CatalogSourceSpec{ SourceType: v1alpha1.SourceTypeConfigmap, + ConfigMap: "test-cm", }, }, }, out: out{ - err: fmt.Errorf("unable to get configmap / from cache"), + err: fmt.Errorf(`unable to find configmap test-ns/test-cm: configmaps "test-cm" not found`), }, }, { @@ -463,7 +467,11 @@ func TestConfigMapRegistryReconciler(t *testing.T) { err := rec.EnsureRegistryServer(logrus.NewEntry(logrus.New()), tt.in.catsrc) - require.Equal(t, tt.out.err, err) + if tt.out.err != nil { + require.EqualError(t, err, tt.out.err.Error()) + } else { + require.NoError(t, err) + } require.Equal(t, tt.out.status, tt.in.catsrc.Status.RegistryServiceStatus) if tt.out.err != nil {