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

introduce dns.gardener.cloud/target-hard-ignore annotation #404

Merged
merged 2 commits into from
Dec 13, 2024
Merged
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
4 changes: 4 additions & 0 deletions pkg/dns/const.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
}
@@ -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, ""
}
Loading