From 56f1ea9a684cf9d76288f0efc26bda9837b131c2 Mon Sep 17 00:00:00 2001 From: craig Date: Tue, 12 Mar 2024 11:50:54 +0000 Subject: [PATCH] updates after review --- api/v1alpha1/dnsrecord_types.go | 13 ++----------- internal/controller/dnsrecord_controller.go | 7 +++++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/api/v1alpha1/dnsrecord_types.go b/api/v1alpha1/dnsrecord_types.go index 62f1cec4..76b2d142 100644 --- a/api/v1alpha1/dnsrecord_types.go +++ b/api/v1alpha1/dnsrecord_types.go @@ -106,14 +106,7 @@ const ( DefaultGeo string = "default" ) -const wildcardPrefix = "*." - -func (s *DNSRecord) isWildCardRoot() bool { - if s.Spec.RootHost != nil { - return strings.HasPrefix(*s.Spec.RootHost, wildcardPrefix) - } - return false -} +const WildcardPrefix = "*." func (s *DNSRecord) Validate() error { if s.Spec.RootHost != nil { @@ -125,9 +118,7 @@ func (s *DNSRecord) Validate() error { return fmt.Errorf("no endpoints defined for DNSRecord. Nothing to do.") } - if s.isWildCardRoot() { - root = strings.Replace(root, wildcardPrefix, "", 1) - } + root, _ = strings.CutPrefix(root, WildcardPrefix) rootEndpointFound := false for _, ep := range s.Spec.Endpoints { diff --git a/internal/controller/dnsrecord_controller.go b/internal/controller/dnsrecord_controller.go index 41842d1b..eed2b076 100644 --- a/internal/controller/dnsrecord_controller.go +++ b/internal/controller/dnsrecord_controller.go @@ -228,8 +228,11 @@ func setDNSRecordCondition(dnsRecord *v1alpha1.DNSRecord, conditionType string, func (r *DNSRecordReconciler) applyChanges(ctx context.Context, dnsRecord *v1alpha1.DNSRecord, managedZone *v1alpha1.ManagedZone, isDelete bool) error { logger := log.FromContext(ctx) - - rootDomainFilter := externaldnsendpoint.NewDomainFilter([]string{managedZone.Spec.DomainName}) + filterDomain, _ := strings.CutPrefix(*dnsRecord.Spec.RootHost, v1alpha1.WildcardPrefix) + if dnsRecord.Spec.RootHost != nil { + filterDomain = *dnsRecord.Spec.RootHost + } + rootDomainFilter := externaldnsendpoint.NewDomainFilter([]string{filterDomain}) providerConfig := provider.Config{ DomainFilter: externaldnsendpoint.NewDomainFilter([]string{managedZone.Spec.DomainName}),