From bb89c9922046e1f63301076971c7ad715ade6534 Mon Sep 17 00:00:00 2001 From: Martin Weindel Date: Mon, 31 Oct 2022 13:17:28 +0100 Subject: [PATCH] allow more cname targets (25 instead of 11); remove obsolete code from changemodel --- pkg/dns/dnsset.go | 1 - pkg/dns/provider/changemodel.go | 28 ++-------------------------- pkg/dns/provider/entry.go | 7 +++++-- 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/pkg/dns/dnsset.go b/pkg/dns/dnsset.go index d07a81091..e4a732207 100644 --- a/pkg/dns/dnsset.go +++ b/pkg/dns/dnsset.go @@ -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" diff --git a/pkg/dns/provider/changemodel.go b/pkg/dns/provider/changemodel.go index cee2adcdc..ead786b9f 100644 --- a/pkg/dns/provider/changemodel.go +++ b/pkg/dns/provider/changemodel.go @@ -19,8 +19,6 @@ package provider import ( "fmt" "reflect" - "sort" - "strings" "time" api "github.com/gardener/external-dns-management/pkg/apis/dns/v1alpha1" @@ -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 } diff --git a/pkg/dns/provider/entry.go b/pkg/dns/provider/entry.go index 99296a403..0710e45bb 100644 --- a/pkg/dns/provider/entry.go +++ b/pkg/dns/provider/entry.go @@ -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 @@ -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