From c43f614d40f9fc24c29a365e808627d36cf87624 Mon Sep 17 00:00:00 2001 From: Shawn Hurley Date: Fri, 1 Feb 2019 11:12:09 -0500 Subject: [PATCH] ansible/controller,helm/controller: reconcile controller to use cache (#1022) **Description of the change:** Set the reconciler to use the cache for a Reader. **Motivation for the change:** The delegating reader will proxy unstructured calls to the API and not use the cache. This is specifically for 0.4.0, there is a better mechanism when using controller-runtime v0.1.10 --- pkg/ansible/controller/controller.go | 9 ++++++++- pkg/helm/controller/controller.go | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/ansible/controller/controller.go b/pkg/ansible/controller/controller.go index 0364fb39e4..ddca5d62b3 100644 --- a/pkg/ansible/controller/controller.go +++ b/pkg/ansible/controller/controller.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "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" @@ -57,7 +58,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 3d57b76cad..093904a02d 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,