Skip to content

Commit

Permalink
ansible/controller,helm/controller: reconcile controller to use cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Hurley committed Jan 31, 2019
1 parent 0777311 commit b64ce51
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/ansible/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion pkg/helm/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b64ce51

Please sign in to comment.