From b5d45ab23956a5f2d2ee2551f8748eeba9df7e9d Mon Sep 17 00:00:00 2001 From: Ian Lewis Date: Fri, 10 Nov 2023 15:15:27 +0000 Subject: [PATCH] Use reader client to get operator config map (#591) 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 Also 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.go | 2 +- utils/reconciler_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 } 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))