From 25eee8e06756f411e9eb94c000942751abe920ce Mon Sep 17 00:00:00 2001 From: Miciah Masters Date: Wed, 23 Nov 2022 09:13:37 -0600 Subject: [PATCH] configurable-route: Don't use NewKindWithCache Replace source.NewKindWithCache(&foo{}, mgr.GetCache()) with &source.Kind{Type: &foo{}} in the configurable-route controller. Using source.NewKindWithCache() is needlessly complicated since this controller uses the default cache anyway. Moreover, using source.NewKindWithCache() causes controller-runtime's logging to be more noisy. Before this commit, the operator emitted log messages like the following on startup: 2022-11-23T08:47:35.646-0600 INFO operator.init controller/controller.go:241 Starting EventSource {"controller": "configurable_route_controller", "source": "&{{%!s(*v1.Role=&{{ } { 0 {{0 0 }} map[] map[] [] [] []} []}) %!s(*cache.multiNamespaceCache=&{map[openshift-config:0xc000712110 openshift-config-managed:0xc000712108 openshift-ingress:0xc0007120f8 openshift-ingress-canary:0xc000712100 openshift-ingress-operator:0xc0007120e8] 0xc000261ea0 0xc00010e190 0xc0007120e0}) %!s(chan error=) %!s(func()=)}}"} 2022-11-23T08:47:35.646-0600 INFO operator.init controller/controller.go:241 Starting EventSource {"controller": "configurable_route_controller", "source": "&{{%!s(*v1.RoleBinding=&{{ } { 0 {{0 0 }} map[] map[] [] [] []} [] { }}) %!s(*cache.multiNamespaceCache=&{map[openshift-config:0xc000712110 openshift-config-managed:0xc000712108 openshift-ingress:0xc0007120f8 openshift-ingress-canary:0xc000712100 openshift-ingress-operator:0xc0007120e8] 0xc000261ea0 0xc00010e190 0xc0007120e0}) %!s(chan error=) %!s(func()=)}}"} 2022-11-23T08:47:35.646-0600 INFO operator.init controller/controller.go:241 Starting Controller {"controller": "configurable_route_controller"} After this commit, the operator instead emits log messages like the following: 2022-11-23T08:48:43.076-0600 INFO operator.init controller/controller.go:241 Starting EventSource {"controller": "configurable_route_controller", "source": "kind source: *v1.Role"} 2022-11-23T08:48:43.078-0600 INFO operator.init controller/controller.go:241 Starting EventSource {"controller": "configurable_route_controller", "source": "kind source: *v1.RoleBinding"} 2022-11-23T08:48:43.078-0600 INFO operator.init controller/controller.go:241 Starting Controller {"controller": "configurable_route_controller"} Follow-up to commit baf2d3e1c1fea1a3c9f40dcc44c5d7418b347f75. This commit fixes OCPBUGS-4054. https://issues.redhat.com/browse/OCPBUGS-4054 * pkg/operator/controller/configurable-route/controller.go (New): Replace source.NewKindWithCache() with source.Kind{}. --- pkg/operator/controller/configurable-route/controller.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/operator/controller/configurable-route/controller.go b/pkg/operator/controller/configurable-route/controller.go index 5673e06df..5b57dcad8 100644 --- a/pkg/operator/controller/configurable-route/controller.go +++ b/pkg/operator/controller/configurable-route/controller.go @@ -86,11 +86,11 @@ func New(mgr manager.Manager, config Config, eventRecorder events.Recorder) (con return ok }) - if err := c.Watch(source.NewKindWithCache(&rbacv1.Role{}, mgr.GetCache()), handler.EnqueueRequestsFromMapFunc(reconciler.resourceToClusterIngressConfig), defaultPredicate); err != nil { + if err := c.Watch(&source.Kind{Type: &rbacv1.Role{}}, handler.EnqueueRequestsFromMapFunc(reconciler.resourceToClusterIngressConfig), defaultPredicate); err != nil { return nil, err } - if err := c.Watch(source.NewKindWithCache(&rbacv1.RoleBinding{}, mgr.GetCache()), handler.EnqueueRequestsFromMapFunc(reconciler.resourceToClusterIngressConfig), defaultPredicate); err != nil { + if err := c.Watch(&source.Kind{Type: &rbacv1.RoleBinding{}}, handler.EnqueueRequestsFromMapFunc(reconciler.resourceToClusterIngressConfig), defaultPredicate); err != nil { return nil, err }