diff --git a/pkg/ansible/controller/controller.go b/pkg/ansible/controller/controller.go index 9c542779e83..0a4c0b0b2a9 100644 --- a/pkg/ansible/controller/controller.go +++ b/pkg/ansible/controller/controller.go @@ -27,6 +27,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" crthandler "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/manager" @@ -56,7 +57,13 @@ func Add(mgr manager.Manager, options Options) *controller.Controller { eventHandlers := append(options.EventHandlers, events.NewLoggingEventHandler(options.LoggingLevel)) aor := &AnsibleOperatorReconciler{ - Client: mgr.GetClient(), + // The default client will use the DelegatingReader for reads + // this forces it to use the cache for unstructured types. + Client: client.DelegatingClient{ + Reader: mgr.GetCache(), + Writer: mgr.GetClient(), + StatusClient: mgr.GetClient(), + }, GVK: options.GVK, Runner: options.Runner, EventHandlers: eventHandlers, diff --git a/pkg/helm/controller/controller.go b/pkg/helm/controller/controller.go index 3d57b76cad9..093904a02d1 100644 --- a/pkg/helm/controller/controller.go +++ b/pkg/helm/controller/controller.go @@ -29,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" rpb "k8s.io/helm/pkg/proto/hapi/release" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/event" crthandler "sigs.k8s.io/controller-runtime/pkg/handler" @@ -56,7 +57,13 @@ type WatchOptions struct { // Add creates a new helm operator controller and adds it to the manager func Add(mgr manager.Manager, options WatchOptions) error { r := &HelmOperatorReconciler{ - Client: mgr.GetClient(), + // The default client will use the DelegatingReader for reads + // this forces it to use the cache for unstructured types. + Client: client.DelegatingClient{ + Reader: mgr.GetCache(), + Writer: mgr.GetClient(), + StatusClient: mgr.GetClient(), + }, GVK: options.GVK, ManagerFactory: options.ManagerFactory, ReconcilePeriod: options.ReconcilePeriod,