Skip to content

Commit

Permalink
Remove reconcile annotation on reconciliation (#406)
Browse files Browse the repository at this point in the history
* remove reconcile annotation on reconciliation

* test: Add integration test for reconcile annotation

* test: Add missing assertion

---------

Co-authored-by: Marc Vornetran <[email protected]>
  • Loading branch information
MartinWeindel and marc1404 authored Dec 13, 2024
1 parent 1ec2aaa commit 02c1a28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/dns/provider/state_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/gardener/external-dns-management/pkg/dns"
perrs "github.com/gardener/external-dns-management/pkg/dns/provider/errors"
dnsutils "github.com/gardener/external-dns-management/pkg/dns/utils"
"github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
"k8s.io/utils/ptr"
)

Expand Down Expand Up @@ -250,6 +251,17 @@ func (this *state) HandleUpdateEntry(logger logger.LogContext, op string, object
defer old.lock.Unlock()
}

if object.GetAnnotations()[constants.GardenerOperation] == constants.GardenerOperationReconcile {
_, err := object.Modify(func(data resources.ObjectData) (bool, error) {
annotations := data.GetAnnotations()
delete(annotations, constants.GardenerOperation)
return true, nil
})
if err != nil {
return reconcile.Delay(logger, err)
}
}

if ignored, annotation := ignoredByAnnotation(object); ignored {
var err error
if !object.IsDeleting() {
Expand Down
22 changes: 22 additions & 0 deletions test/integration/compound/compound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gardener/controller-manager-library/pkg/controllermanager"
"github.com/gardener/external-dns-management/pkg/dns"
"github.com/gardener/external-dns-management/pkg/dns/provider"
"github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
. "github.com/gardener/gardener/pkg/utils/test/matchers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -410,6 +411,27 @@ var _ = Describe("Compound controller tests", func() {
By("check mock database")
checkSingleEntryInMockDatabase(nil)
})

It("should remove the Gardener reconcile operation annotation after reconciliation", func() {
By("Create new DNS entry")
Expect(testClient.Create(ctx, e1)).To(Succeed())
DeferCleanup(func() {
Expect(testClient.Delete(ctx, e1)).To(Succeed())
})
checkEntry(e1)

By("Set reconcile annotation on DNS entry")
e1.Annotations = map[string]string{
constants.GardenerOperation: constants.GardenerOperationReconcile,
}
Expect(testClient.Update(ctx, e1)).To(Succeed())

By("Wait for the reconcile annotation to be removed from the DNS entry")
Eventually(func(g Gomega) {
g.Expect(testClient.Get(ctx, client.ObjectKeyFromObject(e1), e1)).To(Succeed())
g.Expect(e1.Annotations).NotTo(HaveKey(constants.GardenerOperation))
}).Should(Succeed())
})
})

func quoted(txt []string) []string {
Expand Down

0 comments on commit 02c1a28

Please sign in to comment.