Skip to content

Commit

Permalink
Delete the DNSEndpoint resource when VS is deleted & Ratelimit requeu…
Browse files Browse the repository at this point in the history
…es on errors. (#4504)
  • Loading branch information
ciarams87 authored Nov 17, 2023
1 parent c7680a4 commit 6d85f27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions internal/certmanager/cm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 8 additions & 1 deletion internal/externaldns/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}()
}
}
Expand All @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion internal/externaldns/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 6d85f27

Please sign in to comment.