Skip to content

Commit

Permalink
fix deletion of entries after controller restart
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWeindel committed Jan 17, 2025
1 parent 0cf9d3d commit b0aeb6f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
41 changes: 24 additions & 17 deletions pkg/dns/provider/changemodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,16 @@ type TargetSpec = dnsutils.TargetSpec

type ChangeModel struct {
logger.LogContext
config Config
ownership dns.Ownership
context *zoneReconciliation
applied map[dns.DNSSetName]*dns.DNSSet
dangling *ChangeGroup
providergroups map[string]*ChangeGroup
zonestate DNSZoneState
failedDNSNames dns.DNSNameSet
oldDNSSets dns.DNSSets
config Config
ownership dns.Ownership
context *zoneReconciliation
applied map[dns.DNSSetName]*dns.DNSSet
dangling *ChangeGroup
providergroups map[string]*ChangeGroup
zonestate DNSZoneState
succeededDNSNames dns.DNSNameSet
failedDNSNames dns.DNSNameSet
oldDNSSets dns.DNSSets
}

type ChangeResult struct {
Expand All @@ -247,14 +248,15 @@ type ChangeResult struct {

func NewChangeModel(logger logger.LogContext, ownership dns.Ownership, req *zoneReconciliation, config Config, oldDNSSets dns.DNSSets) *ChangeModel {
return &ChangeModel{
LogContext: logger,
config: config,
ownership: ownership,
context: req,
applied: map[dns.DNSSetName]*dns.DNSSet{},
providergroups: map[string]*ChangeGroup{},
failedDNSNames: dns.DNSNameSet{},
oldDNSSets: oldDNSSets,
LogContext: logger,
config: config,
ownership: ownership,
context: req,
applied: map[dns.DNSSetName]*dns.DNSSet{},
providergroups: map[string]*ChangeGroup{},
succeededDNSNames: dns.DNSNameSet{},
failedDNSNames: dns.DNSNameSet{},
oldDNSSets: oldDNSSets,
}
}

Expand Down Expand Up @@ -469,6 +471,10 @@ func (this *ChangeModel) IsFailed(name dns.DNSSetName) bool {
return this.failedDNSNames.Contains(name)
}

func (this *ChangeModel) IsSucceeded(name dns.DNSSetName) bool {
return this.succeededDNSNames.Contains(name)
}

func (this *ChangeModel) wrappedDoneHandler(name dns.DNSSetName, done DoneHandler) DoneHandler {
return &changeModelDoneHandler{
changeModel: this,
Expand Down Expand Up @@ -500,6 +506,7 @@ func (this *changeModelDoneHandler) Failed(err error) {
}

func (this *changeModelDoneHandler) Succeeded() {
this.changeModel.succeededDNSNames.Add(this.dnsSetName)
if this.inner != nil {
this.inner.Succeeded()
}
Expand Down
24 changes: 19 additions & 5 deletions pkg/dns/provider/state_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,19 @@ func (this *state) reconcileZone(logger logger.LogContext, req *zoneReconciliati
for _, e := range outdatedEntries {
if changes.IsFailed(e.DNSSetName()) {
if oldSet, ok := oldDNSSets[e.DNSSetName()]; ok {
if txn := this.getActiveZoneTransaction(zoneid); txn != nil {
txn.AddEntryChange(e.ObjectKey(), e.Object().GetGeneration(), oldSet, nil)
} else {
logger.Warnf("cleanup postpone failure: missing zone for %s", e.ObjectName())
}
this.addDeleteToNextTransaction(logger, req, zoneid, e, oldSet)
} else {
logger.Warnf("cleanup postpone failure: old set not found for %s", e.ObjectName())
}
continue
}
if !changes.IsSucceeded(e.DNSSetName()) {
// DNSEntry in deleting state, but not completely handled (e.g. after restart before zone reconciliation was running)
if oldSet, ok := changes.zonestate.GetDNSSets()[e.DNSSetName()]; ok {
this.addDeleteToNextTransaction(logger, req, zoneid, e, oldSet)
continue
}
}
logger.Infof("cleanup outdated entry %q", e.ObjectName())
err := e.RemoveFinalizer()
if err == nil || errors.IsNotFound(err) {
Expand All @@ -233,6 +236,17 @@ func (this *state) reconcileZone(logger logger.LogContext, req *zoneReconciliati
return err
}

func (this *state) addDeleteToNextTransaction(logger logger.LogContext, req *zoneReconciliation, zoneid dns.ZoneID, e *Entry, oldSet *dns.DNSSet) {
if txn := this.getActiveZoneTransaction(zoneid); txn != nil {
txn.AddEntryChange(e.ObjectKey(), e.Object().GetGeneration(), oldSet, nil)
if req.zone.nextTrigger == 0 {
req.zone.nextTrigger = this.config.Delay
}
} else {
logger.Warnf("cleanup postpone failure: missing zone for %s", e.ObjectName())
}
}

func (this *state) deleteZone(zoneid dns.ZoneID) {
metrics.DeleteZone(zoneid)
delete(this.zones, zoneid)
Expand Down

0 comments on commit b0aeb6f

Please sign in to comment.