From 7132d61594d474484fe8890d0de2cd9a3bfee68a Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Fri, 6 Mar 2020 11:30:38 -0800 Subject: [PATCH] :running: Pass a stripped down object to controller.Watch Signed-off-by: Vince Prignano --- controllers/external/tracker.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/controllers/external/tracker.go b/controllers/external/tracker.go index a2eac38430f1..bbc097c60af1 100644 --- a/controllers/external/tracker.go +++ b/controllers/external/tracker.go @@ -21,6 +21,7 @@ import ( "github.com/go-logr/logr" "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/handler" @@ -41,20 +42,23 @@ func (o *ObjectTracker) Watch(log logr.Logger, obj runtime.Object, handler handl return nil } - gk := obj.GetObjectKind().GroupVersionKind().GroupKind() - _, loaded := o.m.LoadOrStore(gk.String(), struct{}{}) + gvk := obj.GetObjectKind().GroupVersionKind() + _, loaded := o.m.LoadOrStore(gvk.GroupKind().String(), struct{}{}) if loaded { return nil } - log.Info("Adding watcher on external object", "GroupKind", gk.String()) + u := &unstructured.Unstructured{} + u.SetGroupVersionKind(gvk) + + log.Info("Adding watcher on external object", "GroupVersionKind", gvk.String()) err := o.Controller.Watch( - &source.Kind{Type: obj}, + &source.Kind{Type: u}, handler, ) if err != nil { o.m.Delete(obj) - return errors.Wrapf(err, "failed to add watcher on external object %q", gk.String()) + return errors.Wrapf(err, "failed to add watcher on external object %q", gvk.String()) } return nil }