From a4445e943bc5b6487056408c270d72f42daebac0 Mon Sep 17 00:00:00 2001 From: ilewis Date: Fri, 10 Nov 2023 09:54:19 +0000 Subject: [PATCH 1/2] Use reader client to get operator config map The operator config map is not always in the same namespace that is being watched, and the client provided by the manager will only read resources in the watched namespace. 'Get' on the configmap will fail in this situation Use the reader client instead, as this will read resources from any namespace --- utils/reconciler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/reconciler.go b/utils/reconciler.go index 8fef3114..9565db01 100644 --- a/utils/reconciler.go +++ b/utils/reconciler.go @@ -168,7 +168,7 @@ func (r *ReconcilerBase) DeleteResources(resources []client.Object) error { // GetOpConfigMap ... func (r *ReconcilerBase) GetOpConfigMap(name string, ns string) (*corev1.ConfigMap, error) { configMap := &corev1.ConfigMap{} - err := r.GetClient().Get(context.TODO(), types.NamespacedName{Name: name, Namespace: ns}, configMap) + err := r.GetAPIReader().Get(context.TODO(), types.NamespacedName{Name: name, Namespace: ns}, configMap) if err != nil { return nil, err } From 56ab9798e5cef66909c71df156df0c0ec5abdb6f Mon Sep 17 00:00:00 2001 From: ilewis Date: Fri, 10 Nov 2023 13:39:06 +0000 Subject: [PATCH 2/2] Fix up tests. Need to use the same fake client to create and fetch the configmap otherwise, the configmap can't be retrieved --- utils/reconciler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/reconciler_test.go b/utils/reconciler_test.go index 5237ac22..5a69ab62 100644 --- a/utils/reconciler_test.go +++ b/utils/reconciler_test.go @@ -264,7 +264,7 @@ func TestGetOpConfigMap(t *testing.T) { objs, s := []runtime.Object{runtimecomponent}, scheme.Scheme s.AddKnownTypes(appstacksv1.GroupVersion, runtimecomponent) cl := fakeclient.NewFakeClient(objs...) - rcl := fakeclient.NewFakeClient(objs...) + rcl := cl r := NewReconcilerBase(rcl, cl, s, &rest.Config{}, record.NewFakeRecorder(10))