Skip to content

Commit

Permalink
registry/controller: use a live client for configmaps
Browse files Browse the repository at this point in the history
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 <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Nov 30, 2023
1 parent 7a056b2 commit 79b4d41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/controller/registry/reconciler/configmap.go
Expand Up @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions pkg/controller/registry/reconciler/configmap_test.go
Expand Up @@ -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`),
},
},
{
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 79b4d41

Please sign in to comment.