Skip to content

Commit b5d45ab

Browse files
authored
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
1 parent ff19816 commit b5d45ab

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

utils/reconciler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (r *ReconcilerBase) DeleteResources(resources []client.Object) error {
168168
// GetOpConfigMap ...
169169
func (r *ReconcilerBase) GetOpConfigMap(name string, ns string) (*corev1.ConfigMap, error) {
170170
configMap := &corev1.ConfigMap{}
171-
err := r.GetClient().Get(context.TODO(), types.NamespacedName{Name: name, Namespace: ns}, configMap)
171+
err := r.GetAPIReader().Get(context.TODO(), types.NamespacedName{Name: name, Namespace: ns}, configMap)
172172
if err != nil {
173173
return nil, err
174174
}

utils/reconciler_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func TestGetOpConfigMap(t *testing.T) {
264264
objs, s := []runtime.Object{runtimecomponent}, scheme.Scheme
265265
s.AddKnownTypes(appstacksv1.GroupVersion, runtimecomponent)
266266
cl := fakeclient.NewFakeClient(objs...)
267-
rcl := fakeclient.NewFakeClient(objs...)
267+
rcl := cl
268268

269269
r := NewReconcilerBase(rcl, cl, s, &rest.Config{}, record.NewFakeRecorder(10))
270270

0 commit comments

Comments
 (0)