Skip to content

Commit

Permalink
fix empty targets (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: Uwe Krueger <uwe.krueger@sap.com>

Co-authored-by: Uwe Krueger <uwe.krueger@sap.com>
  • Loading branch information
MartinWeindel and mandelsoft authored Jan 14, 2020
1 parent aaff72c commit 990b21b
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions pkg/dns/provider/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,15 @@ func validate(state *state, entry *EntryVersion) (targets Targets, warnings []st
return
}
if spec.TTL != nil && (*spec.TTL == 0 || *spec.TTL < 0) {
err = fmt.Errorf("TTL must be greater than zero: %s", err)
err = fmt.Errorf("TTL must be greater than zero: %s", err)
return
}

for _, t := range spec.Targets {
for i, t := range spec.Targets {
if strings.TrimSpace(t) == "" {
err = fmt.Errorf("target %d must not be empty", i+1)
return
}
var new Target
new, err = NewTargetFromEntryVersion(t, entry)
if err != nil {
Expand All @@ -222,13 +226,21 @@ func validate(state *state, entry *EntryVersion) (targets Targets, warnings []st
}
}
for _, t := range spec.Text {
if t == "" {
warnings = append(warnings, fmt.Sprintf("dns entry %q has empty text", entry.ObjectName()))
continue
}
new := NewText(t, entry)
if targets.Has(new) {
warnings = append(warnings, fmt.Sprintf("dns entry %q has duplicate text %q", entry.ObjectName(), new))
} else {
targets = append(targets, new)
}
}
if len(spec.Targets) == 0 {
err = fmt.Errorf("dns entry has only empty text")
return
}

if utils.StringValue(spec.OwnerId) != "" {
if !state.ownerCache.IsResponsibleFor(*spec.OwnerId) {
Expand Down Expand Up @@ -343,10 +355,21 @@ func (this *EntryVersion) Setup(logger logger.LogContext, state *state, p *Entry
this.warnings = warnings
targets, multiCName := normalizeTargets(logger, this.object, targets...)
if multiCName {
this.interval = int64(600)
if spec.CNameLookupInterval != nil && *spec.CNameLookupInterval > 0 {
this.interval = *spec.CNameLookupInterval
} else {
this.interval = 600
}
if len(targets) == 0 {
msg := "targets cannot be resolved to any valid IPv4 address"
verr := fmt.Errorf(msg)
hello.Infof(logger, msg)

state := api.STATE_INVALID
if this.status.State == api.STATE_READY {
state = api.STATE_STALE
}
this.UpdateStatus(logger, state, verr.Error())
return reconcile.Recheck(logger, verr, time.Duration(this.interval)*time.Second)
}
} else {
this.interval = 0
Expand Down

0 comments on commit 990b21b

Please sign in to comment.