From ef580809d5972d5514b1d7c2ee2f946bb445b526 Mon Sep 17 00:00:00 2001 From: Paul Abel <128620221+pdabelf5@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:13:22 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Revert=20"ExternalDNS=20controller=20should?= =?UTF-8?q?=20handle=20errors=20registering=20the=20EventHand=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 455bcdfe3179c256fe96e9b7c5b0ed2d8c416d73. --- internal/externaldns/controller.go | 42 ++++++++++-------------------- internal/k8s/controller.go | 9 ++----- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/internal/externaldns/controller.go b/internal/externaldns/controller.go index 84b9b01af4..ad289b3541 100644 --- a/internal/externaldns/controller.go +++ b/internal/externaldns/controller.go @@ -2,7 +2,6 @@ package externaldns import ( "context" - "errors" "fmt" "sync" "time" @@ -59,7 +58,7 @@ type ExtDNSOpts struct { } // NewController takes external dns config and return a new External DNS Controller. -func NewController(opts *ExtDNSOpts) (*ExtDNSController, error) { +func NewController(opts *ExtDNSOpts) *ExtDNSController { ig := make(map[string]*namespacedInformer) c := &ExtDNSController{ ctx: opts.context, @@ -75,44 +74,35 @@ func NewController(opts *ExtDNSOpts) (*ExtDNSController, error) { // no initial namespaces with watched label - skip creating informers for now break } - _, err := c.newNamespacedInformer(ns) - if err != nil { - return nil, err - } + c.newNamespacedInformer(ns) } c.sync = SyncFnFor(c.recorder, c.client, c.informerGroup) - return c, nil + return c } -func (c *ExtDNSController) newNamespacedInformer(ns string) (*namespacedInformer, error) { +func (c *ExtDNSController) newNamespacedInformer(ns string) *namespacedInformer { nsi := &namespacedInformer{sharedInformerFactory: k8s_nginx_informers.NewSharedInformerFactoryWithOptions(c.client, c.resync, k8s_nginx_informers.WithNamespace(ns))} nsi.stopCh = make(chan struct{}) nsi.vsLister = nsi.sharedInformerFactory.K8s().V1().VirtualServers().Lister() nsi.extdnslister = nsi.sharedInformerFactory.Externaldns().V1().DNSEndpoints().Lister() - vsInformer := nsi.sharedInformerFactory.K8s().V1().VirtualServers().Informer() - vsHandlerReg, err := vsInformer.AddEventHandler( + nsi.sharedInformerFactory.K8s().V1().VirtualServers().Informer().AddEventHandler( &QueuingEventHandler{ Queue: c.queue, }, ) - if err != nil { - return nil, err - } - dnsInformer := nsi.sharedInformerFactory.Externaldns().V1().DNSEndpoints().Informer() - dnsHandlerReg, err := dnsInformer.AddEventHandler(&BlockingEventHandler{ + + nsi.sharedInformerFactory.Externaldns().V1().DNSEndpoints().Informer().AddEventHandler(&BlockingEventHandler{ WorkFunc: externalDNSHandler(c.queue), }) - if err != nil { - return nil, err - } + nsi.mustSync = append(nsi.mustSync, - vsHandlerReg.HasSynced, - dnsHandlerReg.HasSynced, + nsi.sharedInformerFactory.K8s().V1().VirtualServers().Informer().HasSynced, + nsi.sharedInformerFactory.Externaldns().V1().DNSEndpoints().Informer().HasSynced, ) c.informerGroup[ns] = nsi - return nsi, nil + return nsi } // Run sets up the event handlers for types we are interested in, as well @@ -264,20 +254,16 @@ func getNamespacedInformer(ns string, ig map[string]*namespacedInformer) *namesp } // AddNewNamespacedInformer adds watchers for a new namespace -func (c *ExtDNSController) AddNewNamespacedInformer(ns string) error { +func (c *ExtDNSController) AddNewNamespacedInformer(ns string) { glog.V(3).Infof("Adding or Updating cert-manager Watchers for Namespace: %v", ns) nsi := getNamespacedInformer(ns, c.informerGroup) if nsi == nil { - nsi, err := c.newNamespacedInformer(ns) - if err != nil { - return err - } + nsi = c.newNamespacedInformer(ns) nsi.start() } if !cache.WaitForCacheSync(nsi.stopCh, nsi.mustSync...) { - return errors.New("failed to sync the cache") + return } - return nil } // RemoveNamespacedInformer removes watchers for a namespace we are no longer watching diff --git a/internal/k8s/controller.go b/internal/k8s/controller.go index 124d3079af..b54cc855c5 100644 --- a/internal/k8s/controller.go +++ b/internal/k8s/controller.go @@ -274,9 +274,7 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc } if input.ExternalDNSEnabled { - if lbc.externalDNSController, err = ed_controller.NewController(ed_controller.BuildOpts(context.TODO(), lbc.namespaceList, lbc.recorder, lbc.confClient, input.ResyncPeriod, isDynamicNs)); err != nil { - glog.Fatalf("failed to initialize ExternalDNS: %v", err) - } + lbc.externalDNSController = ed_controller.NewController(ed_controller.BuildOpts(context.TODO(), lbc.namespaceList, lbc.recorder, lbc.confClient, input.ResyncPeriod, isDynamicNs)) } glog.V(3).Infof("Nginx Ingress Controller has class: %v", input.IngressClass) @@ -1144,10 +1142,7 @@ func (lbc *LoadBalancerController) syncNamespace(task task) { lbc.certManagerController.AddNewNamespacedInformer(key) } if lbc.externalDNSController != nil { - if err := lbc.externalDNSController.AddNewNamespacedInformer(key); err != nil { - lbc.syncQueue.Requeue(task, err) - return - } + lbc.externalDNSController.AddNewNamespacedInformer(key) } if !cache.WaitForCacheSync(nsi.stopCh, nsi.cacheSyncs...) { return From 923f40a3420a7751bd31fc9de239ff7a545d69b5 Mon Sep 17 00:00:00 2001 From: Paul Abel Date: Tue, 12 Mar 2024 09:45:13 +0000 Subject: [PATCH 2/2] ignore externaldns lint errors until refactor --- internal/externaldns/controller.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/externaldns/controller.go b/internal/externaldns/controller.go index ad289b3541..3ccbe8dc07 100644 --- a/internal/externaldns/controller.go +++ b/internal/externaldns/controller.go @@ -87,13 +87,13 @@ func (c *ExtDNSController) newNamespacedInformer(ns string) *namespacedInformer nsi.vsLister = nsi.sharedInformerFactory.K8s().V1().VirtualServers().Lister() nsi.extdnslister = nsi.sharedInformerFactory.Externaldns().V1().DNSEndpoints().Lister() - nsi.sharedInformerFactory.K8s().V1().VirtualServers().Informer().AddEventHandler( + nsi.sharedInformerFactory.K8s().V1().VirtualServers().Informer().AddEventHandler( //nolint:errcheck,gosec &QueuingEventHandler{ Queue: c.queue, }, ) - nsi.sharedInformerFactory.Externaldns().V1().DNSEndpoints().Informer().AddEventHandler(&BlockingEventHandler{ + nsi.sharedInformerFactory.Externaldns().V1().DNSEndpoints().Informer().AddEventHandler(&BlockingEventHandler{ //nolint:errcheck,gosec WorkFunc: externalDNSHandler(c.queue), })