Skip to content

Commit

Permalink
introduce dns.gardener.cloud/target-hard-ignore annotation (#404)
Browse files Browse the repository at this point in the history
* introduce `dns.gardener.cloud/target-hard-ignore` annotation

* remove finalizer on deletion for hard ignored entry
  • Loading branch information
MartinWeindel authored Dec 13, 2024
1 parent 95657c2 commit b5f1fd4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkg/dns/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ const (

// AnnotationIgnore is an optional annotation for DNSEntries and source resources to ignore them on reconciliation.
AnnotationIgnore = ANNOTATION_GROUP + "/ignore"
// AnnotationHardIgnore is an optional annotation for a generated target DNSEntry to ignore it on reconciliation.
// This annotation is not propagated from source objects to the target DNSEntry.
// IMPORTANT NOTE: The entry is even ignored on deletion, so use with caution to avoid orphaned entries.
AnnotationHardIgnore = ANNOTATION_GROUP + "/target-hard-ignore"
)
31 changes: 23 additions & 8 deletions pkg/dns/provider/state_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,19 @@ func (this *state) HandleUpdateEntry(logger logger.LogContext, op string, object
defer old.lock.Unlock()
}

if !object.IsDeleting() && object.GetAnnotations()[dns.AnnotationIgnore] == "true" {
_, err := object.ModifyStatus(func(data resources.ObjectData) (bool, error) {
status := &data.(*api.DNSEntry).Status
mod := utils.ModificationState{}
mod.AssureStringValue(&status.State, api.STATE_IGNORED)
mod.AssureStringPtrPtr(&status.Message, ptr.To("entry is ignored as annotated with "+dns.AnnotationIgnore))
return mod.IsModified(), nil
})
if ignored, annotation := ignoredByAnnotation(object); ignored {
var err error
if !object.IsDeleting() {
_, err = object.ModifyStatus(func(data resources.ObjectData) (bool, error) {
status := &data.(*api.DNSEntry).Status
mod := utils.ModificationState{}
mod.AssureStringValue(&status.State, api.STATE_IGNORED)
mod.AssureStringPtrPtr(&status.Message, ptr.To(fmt.Sprintf("entry is ignored as annotated with %s", annotation)))
return mod.IsModified(), nil
})
} else {
err = this.RemoveFinalizer(object)
}
if err != nil {
return reconcile.Delay(logger, err)
}
Expand Down Expand Up @@ -370,3 +375,13 @@ func (this *state) DeleteLookupJob(entryName resources.ObjectName) {
func (this *state) UpsertLookupJob(entryName resources.ObjectName, results lookupAllResults, interval time.Duration) {
this.lookupProcessor.Upsert(entryName, results, interval)
}

func ignoredByAnnotation(object *dnsutils.DNSEntryObject) (bool, string) {
if !object.IsDeleting() && object.GetAnnotations()[dns.AnnotationIgnore] == "true" {
return true, dns.AnnotationIgnore
}
if object.GetAnnotations()[dns.AnnotationHardIgnore] == "true" {
return true, dns.AnnotationHardIgnore
}
return false, ""
}

0 comments on commit b5f1fd4

Please sign in to comment.