Skip to content

Commit 79b4d41

Browse files
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 <[email protected]>
1 parent 7a056b2 commit 79b4d41

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

pkg/controller/registry/reconciler/configmap.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,11 @@ func (c *ConfigMapRegistryReconciler) EnsureRegistryServer(logger *logrus.Entry,
290290

291291
if source.Spec.SourceType == v1alpha1.SourceTypeConfigmap || source.Spec.SourceType == v1alpha1.SourceTypeInternal {
292292
// fetch configmap first, exit early if we can't find it
293-
configMap, err := c.Lister.CoreV1().ConfigMapLister().ConfigMaps(source.GetNamespace()).Get(source.Spec.ConfigMap)
293+
// we use the live client here instead of a lister since our listers are scoped to objects with the olm.managed label,
294+
// and this configmap is a user-provided input to the catalog source and will not have that label
295+
configMap, err := c.OpClient.KubernetesInterface().CoreV1().ConfigMaps(source.GetNamespace()).Get(context.TODO(), source.Spec.ConfigMap, metav1.GetOptions{})
294296
if err != nil {
295-
return fmt.Errorf("unable to get configmap %s/%s from cache", source.GetNamespace(), source.Spec.ConfigMap)
297+
return fmt.Errorf("unable to find configmap %s/%s: %w", source.GetNamespace(), source.Spec.ConfigMap, err)
296298
}
297299

298300
if source.ConfigMapChanges(configMap) {

pkg/controller/registry/reconciler/configmap_test.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,17 @@ func TestConfigMapRegistryReconciler(t *testing.T) {
299299
in: in{
300300
cluster: cluster{},
301301
catsrc: &v1alpha1.CatalogSource{
302+
ObjectMeta: metav1.ObjectMeta{
303+
Namespace: "test-ns",
304+
},
302305
Spec: v1alpha1.CatalogSourceSpec{
303306
SourceType: v1alpha1.SourceTypeConfigmap,
307+
ConfigMap: "test-cm",
304308
},
305309
},
306310
},
307311
out: out{
308-
err: fmt.Errorf("unable to get configmap / from cache"),
312+
err: fmt.Errorf(`unable to find configmap test-ns/test-cm: configmaps "test-cm" not found`),
309313
},
310314
},
311315
{
@@ -463,7 +467,11 @@ func TestConfigMapRegistryReconciler(t *testing.T) {
463467

464468
err := rec.EnsureRegistryServer(logrus.NewEntry(logrus.New()), tt.in.catsrc)
465469

466-
require.Equal(t, tt.out.err, err)
470+
if tt.out.err != nil {
471+
require.EqualError(t, err, tt.out.err.Error())
472+
} else {
473+
require.NoError(t, err)
474+
}
467475
require.Equal(t, tt.out.status, tt.in.catsrc.Status.RegistryServiceStatus)
468476

469477
if tt.out.err != nil {

0 commit comments

Comments
 (0)