Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnssources: ignore empty targets for slave entries on update #357

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/dns/source/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,13 @@ func (this *sourceReconciler) updateEntryFor(logger logger.LogContext, obj resou
mod.Modify(true)
}
}
mod.AssureStringSet(&spec.Targets, targets)
mod.AssureStringSet(&spec.Text, text)
if len(targets) > 0 || len(text) > 0 || !ignoreEmptyTargets(obj) {
mod.AssureStringSet(&spec.Targets, targets)
mod.AssureStringSet(&spec.Text, text)
} else if len(spec.Targets) > 0 && ignoreEmptyTargets(obj) {
// keep old targets if load balancer disappears temporarily
logger.Infof("ignoring empty targets for entry %s", slave.ObjectName())
}
if info.IPStack != "" {
annots := o.GetAnnotations()
if annots == nil {
Expand Down Expand Up @@ -602,3 +607,8 @@ func (this *sourceReconciler) deleteEntry(logger logger.LogContext, e resources.
}
return err
}

func ignoreEmptyTargets(obj resources.Object) bool {
_, ok := obj.Data().(*api.DNSEntry)
return !ok
}
25 changes: 19 additions & 6 deletions test/integration/ingressAnnotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ var _ = Describe("IngressAnnotation", func() {
Ω(entry.Spec.OwnerId).Should(BeNil())
Ω(entry.Annotations["dns.gardener.cloud/ip-stack"]).Should(Equal("dual-stack"))

// keep old targets if ingress lost its load balancers
err = testEnv.PatchIngressLoadBalancer(ingress, "")
Ω(err).ShouldNot(HaveOccurred())

entryObj2, err := testEnv.AwaitObjectByOwner("Ingress", ingress2.GetName())
entry2 := UnwrapEntry(entryObj2)
Ω(err).ShouldNot(HaveOccurred())
Expand All @@ -61,25 +65,34 @@ var _ = Describe("IngressAnnotation", func() {
Ω(entry3.Spec.OwnerId).ShouldNot(BeNil())
Ω(*entry3.Spec.OwnerId).Should(Equal("second"))

err = ingress.Delete()
Ω(err).ShouldNot(HaveOccurred())
err = ingress2.Delete()
Ω(err).ShouldNot(HaveOccurred())
err = ingress3.Delete()
Ω(err).ShouldNot(HaveOccurred())

err = testEnv.AwaitIngressDeletion(ingress.GetName())
Ω(err).ShouldNot(HaveOccurred())
err = testEnv.AwaitIngressDeletion(ingress2.GetName())
Ω(err).ShouldNot(HaveOccurred())
err = testEnv.AwaitIngressDeletion(ingress3.GetName())
Ω(err).ShouldNot(HaveOccurred())

err = testEnv.AwaitEntryDeletion(entryObj.GetName())
Ω(err).ShouldNot(HaveOccurred())
err = testEnv.AwaitEntryDeletion(entryObj2.GetName())
Ω(err).ShouldNot(HaveOccurred())
err = testEnv.AwaitEntryDeletion(entryObj3.GetName())
Ω(err).ShouldNot(HaveOccurred())

// check unchanged target
entryObj, err = testEnv.AwaitObjectByOwner("Ingress", ingress.GetName())
entry = UnwrapEntry(entryObj)
Ω(err).ShouldNot(HaveOccurred())
Ω(entry.Spec.Targets).Should(ConsistOf(fakeExternalIP))

err = ingress.Delete()
Ω(err).ShouldNot(HaveOccurred())

err = testEnv.AwaitIngressDeletion(ingress.GetName())
Ω(err).ShouldNot(HaveOccurred())

err = testEnv.AwaitEntryDeletion(entryObj.GetName())
Ω(err).ShouldNot(HaveOccurred())
})
})
33 changes: 23 additions & 10 deletions test/integration/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,23 +619,36 @@ func (te *TestEnv) CreateIngressWithAnnotation(name, domainName, fakeExternalIP
}

if fakeExternalIP != "" {
res, err := te.resources.Get(ingress)
err := te.PatchIngressLoadBalancer(obj, fakeExternalIP)
if err != nil {
return obj, err
}
_, _, err = res.ModifyStatus(ingress, func(data resources.ObjectData) (bool, error) {
o := data.(*networkingv1.Ingress)
}

return obj, err
}

func (te *TestEnv) PatchIngressLoadBalancer(ingressObj resources.Object, fakeExternalIP string) error {
ingress, ok := ingressObj.Data().(*networkingv1.Ingress)
if !ok {
return fmt.Errorf("not an ingress object")
}
res, err := te.resources.Get(ingress)
if err != nil {
return err
}
_, _, err = res.ModifyStatus(ingress, func(data resources.ObjectData) (bool, error) {
o := data.(*networkingv1.Ingress)
if fakeExternalIP != "" {
o.Status.LoadBalancer.Ingress = []networkingv1.IngressLoadBalancerIngress{
{IP: fakeExternalIP},
}
return true, nil
})
if err != nil {
return obj, err
} else {
o.Status.LoadBalancer.Ingress = []networkingv1.IngressLoadBalancerIngress{}
}
}

return obj, err
return true, nil
})
return err
}

func (te *TestEnv) GetIngress(name string) (resources.Object, *networkingv1.Ingress, error) {
Expand Down