From 6d85f273fcbbcce3694b9e5fd5028a65b5a21afd Mon Sep 17 00:00:00 2001 From: Ciara Stacke <18287516+ciarams87@users.noreply.github.com> Date: Fri, 17 Nov 2023 12:49:53 +0000 Subject: [PATCH] Delete the DNSEndpoint resource when VS is deleted & Ratelimit requeues on errors. (#4504) --- internal/certmanager/cm_controller.go | 6 ++++++ internal/externaldns/controller.go | 9 ++++++++- internal/externaldns/sync.go | 5 ++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/certmanager/cm_controller.go b/internal/certmanager/cm_controller.go index 59a75ef904..4cbbe59146 100644 --- a/internal/certmanager/cm_controller.go +++ b/internal/certmanager/cm_controller.go @@ -40,6 +40,7 @@ import ( k8s_nginx "github.com/nginxinc/kubernetes-ingress/pkg/client/clientset/versioned" vsinformers "github.com/nginxinc/kubernetes-ingress/pkg/client/informers/externalversions" listers_v1 "github.com/nginxinc/kubernetes-ingress/pkg/client/listers/configuration/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" ) const ( @@ -146,6 +147,11 @@ func (c *CmController) processItem(ctx context.Context, key string) error { var vs *conf_v1.VirtualServer vs, err = nsi.vsLister.VirtualServers(namespace).Get(name) + // VS has been deleted + if apierrors.IsNotFound(err) { + return nil + } + if err != nil { return err } diff --git a/internal/externaldns/controller.go b/internal/externaldns/controller.go index 57d258bf96..02c38ce16f 100644 --- a/internal/externaldns/controller.go +++ b/internal/externaldns/controller.go @@ -13,6 +13,7 @@ import ( listersV1 "github.com/nginxinc/kubernetes-ingress/pkg/client/listers/configuration/v1" extdnslisters "github.com/nginxinc/kubernetes-ingress/pkg/client/listers/externaldns/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/tools/cache" @@ -165,10 +166,11 @@ func (c *ExtDNSController) runWorker(ctx context.Context) { if err := c.processItem(ctx, key); err != nil { glog.V(3).Infof("Re-queuing item due to error processing: %v", err) - c.queue.Add(obj) + c.queue.AddRateLimited(obj) return } glog.V(3).Infof("finished processing work item") + c.queue.Forget(obj) }() } } @@ -183,6 +185,11 @@ func (c *ExtDNSController) processItem(ctx context.Context, key string) error { nsi := getNamespacedInformer(namespace, c.informerGroup) vs, err = nsi.vsLister.VirtualServers(namespace).Get(name) + // VS has been deleted + if apierrors.IsNotFound(err) { + return nil + } + if err != nil { return err } diff --git a/internal/externaldns/sync.go b/internal/externaldns/sync.go index 96d2273c24..2aaa4694a5 100644 --- a/internal/externaldns/sync.go +++ b/internal/externaldns/sync.go @@ -155,13 +155,16 @@ func buildDNSEndpoint(extdnsLister extdnslisters.DNSEndpointLister, vs *vsapi.Vi return nil, nil, err } var controllerGVK schema.GroupVersionKind = vsGVK + ownerRef := *metav1.NewControllerRef(vs, controllerGVK) + blockOwnerDeletion := false + ownerRef.BlockOwnerDeletion = &blockOwnerDeletion dnsEndpoint := &extdnsapi.DNSEndpoint{ ObjectMeta: metav1.ObjectMeta{ Name: vs.ObjectMeta.Name, Namespace: vs.Namespace, Labels: vs.Labels, - OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(vs, controllerGVK)}, + OwnerReferences: []metav1.OwnerReference{ownerRef}, }, Spec: extdnsapi.DNSEndpointSpec{ Endpoints: []*extdnsapi.Endpoint{