Skip to content

Commit 7ef94d6

Browse files
author
Shawn Hurley
authored
ansible/controller,helm/controller: reconcile controller to use cache (#1022)
<!-- Before making a PR, please read our contributing guidelines https://github.com/operator-framework/operator-sdk/blob/master/CONTRIBUTING.MD Note: Make sure your branch is rebased to the latest upstream master. --> **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
1 parent e282bb1 commit 7ef94d6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pkg/ansible/controller/controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2929
"k8s.io/apimachinery/pkg/runtime"
3030
"k8s.io/apimachinery/pkg/runtime/schema"
31+
"sigs.k8s.io/controller-runtime/pkg/client"
3132
"sigs.k8s.io/controller-runtime/pkg/controller"
3233
crthandler "sigs.k8s.io/controller-runtime/pkg/handler"
3334
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -57,7 +58,13 @@ func Add(mgr manager.Manager, options Options) *controller.Controller {
5758
eventHandlers := append(options.EventHandlers, events.NewLoggingEventHandler(options.LoggingLevel))
5859

5960
aor := &AnsibleOperatorReconciler{
60-
Client: mgr.GetClient(),
61+
// The default client will use the DelegatingReader for reads
62+
// this forces it to use the cache for unstructured types.
63+
Client: client.DelegatingClient{
64+
Reader: mgr.GetCache(),
65+
Writer: mgr.GetClient(),
66+
StatusClient: mgr.GetClient(),
67+
},
6168
GVK: options.GVK,
6269
Runner: options.Runner,
6370
EventHandlers: eventHandlers,

pkg/helm/controller/controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3030
"k8s.io/apimachinery/pkg/runtime/schema"
3131
rpb "k8s.io/helm/pkg/proto/hapi/release"
32+
"sigs.k8s.io/controller-runtime/pkg/client"
3233
"sigs.k8s.io/controller-runtime/pkg/controller"
3334
"sigs.k8s.io/controller-runtime/pkg/event"
3435
crthandler "sigs.k8s.io/controller-runtime/pkg/handler"
@@ -56,7 +57,13 @@ type WatchOptions struct {
5657
// Add creates a new helm operator controller and adds it to the manager
5758
func Add(mgr manager.Manager, options WatchOptions) error {
5859
r := &HelmOperatorReconciler{
59-
Client: mgr.GetClient(),
60+
// The default client will use the DelegatingReader for reads
61+
// this forces it to use the cache for unstructured types.
62+
Client: client.DelegatingClient{
63+
Reader: mgr.GetCache(),
64+
Writer: mgr.GetClient(),
65+
StatusClient: mgr.GetClient(),
66+
},
6067
GVK: options.GVK,
6168
ManagerFactory: options.ManagerFactory,
6269
ReconcilePeriod: options.ReconcilePeriod,

0 commit comments

Comments
 (0)