Skip to content

Commit

Permalink
Use reader client to get operator config map (#591)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
idlewis authored Nov 10, 2023
1 parent ff19816 commit b5d45ab
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion utils/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion utils/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit b5d45ab

Please sign in to comment.