Skip to content

Commit

Permalink
Merge pull request gardener#285 from gardener/more-cname-targets
Browse files Browse the repository at this point in the history
Allow more CNAME targets
  • Loading branch information
MartinWeindel authored Nov 7, 2022
2 parents c026eab + bb89c99 commit 273eb8d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
1 change: 0 additions & 1 deletion pkg/dns/dnsset.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func (dnssets DNSSets) GetOwners() utils.StringSet {
const (
ATTR_OWNER = "owner"
ATTR_PREFIX = "prefix"
ATTR_CNAMES = "cnames"
ATTR_KIND = "kind"

ATTR_TIMESTAMP = "ts"
Expand Down
28 changes: 2 additions & 26 deletions pkg/dns/provider/changemodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package provider
import (
"fmt"
"reflect"
"sort"
"strings"
"time"

api "github.com/gardener/external-dns-management/pkg/apis/dns/v1alpha1"
Expand Down Expand Up @@ -522,35 +520,13 @@ func (this *ChangeModel) ApplySpec(set *dns.DNSSet, base *dns.DNSSet, provider D
}

targetsets := set.Sets
cnames := []string{}
for _, t := range spec.Targets() {
// use status calculated in entry
ttl := t.GetTTL()
if t.GetRecordType() == dns.RS_CNAME && len(spec.Targets()) > 1 {
cnames = append(cnames, t.GetHostName())
ipv4addrs, ipv6addrs, err := lookupHosts(t.GetHostName())
if err == nil {
for _, addr := range ipv4addrs {
AddRecord(targetsets, dns.RS_A, addr, ttl)
}
for _, addr := range ipv6addrs {
AddRecord(targetsets, dns.RS_AAAA, addr, ttl)
}
} else {
this.Errorf("cannot lookup '%s': %s", t.GetHostName(), err)
}
this.Debugf("mapping target '%s' to A records: %s or AAAA records: %s",
t.GetHostName(), strings.Join(ipv4addrs, ","), strings.Join(ipv6addrs, ","))
} else {
t = provider.MapTarget(t)
AddRecord(targetsets, t.GetRecordType(), t.GetHostName(), ttl)
}
t = provider.MapTarget(t)
AddRecord(targetsets, t.GetRecordType(), t.GetHostName(), ttl)
}
set.Sets = targetsets
if len(cnames) > 0 && this.Owns(set) {
sort.Strings(cnames)
set.SetMetaAttr(dns.ATTR_CNAMES, strings.Join(cnames, ","))
}
return set
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/dns/provider/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import (

const MSG_PRESERVED = "errorneous entry preserved in provider"

// maxCNAMETargets is the maximum number of CNAME targets. It is restricted, as it needs regular DNS lookups.
const maxCNAMETargets = 25

type EntryPremise struct {
ptypes utils.StringSet
ptype string
Expand Down Expand Up @@ -774,8 +777,8 @@ func normalizeTargets(logger logger.LogContext, object dnsutils.DNSSpecification
}

result := make(Targets, 0, len(targets))
if len(targets) > 11 {
w := fmt.Sprintf("too many CNAME targets: %d", len(targets))
if len(targets) > maxCNAMETargets {
w := fmt.Sprintf("too many CNAME targets: %d (maximum allowed: %d)", len(targets), maxCNAMETargets)
logger.Warn(w)
object.Event(corev1.EventTypeWarning, "dnslookup restriction", w)
return result, true, false
Expand Down

0 comments on commit 273eb8d

Please sign in to comment.