Skip to content

Commit 7736d29

Browse files
committed
Address feedback
1 parent f3d3ad1 commit 7736d29

File tree

3 files changed

+46
-49
lines changed

3 files changed

+46
-49
lines changed

pkg/apis/externaldns/types.go

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -190,36 +190,34 @@ type Config struct {
190190
NS1Endpoint string
191191
NS1IgnoreSSL bool
192192
NS1MinTTLSeconds int
193-
// Accepts repeatable --ns1-zone-handle-map flags or a comma-separated
194-
// EXTERNAL_DNS_NS1_ZONE_HANDLE_MAP env var like: "example.com=corp,dev.example.com=dev"
195-
NS1ZoneHandleMap map[string]string
196-
TransIPAccountName string
197-
TransIPPrivateKeyFile string
198-
DigitalOceanAPIPageSize int
199-
ManagedDNSRecordTypes []string
200-
ExcludeDNSRecordTypes []string
201-
GoDaddyAPIKey string `secure:"yes"`
202-
GoDaddySecretKey string `secure:"yes"`
203-
GoDaddyTTL int64
204-
GoDaddyOTE bool
205-
OCPRouterName string
206-
PiholeServer string
207-
PiholePassword string `secure:"yes"`
208-
PiholeTLSInsecureSkipVerify bool
209-
PiholeApiVersion string
210-
PluralCluster string
211-
PluralProvider string
212-
WebhookProviderURL string
213-
WebhookProviderReadTimeout time.Duration
214-
WebhookProviderWriteTimeout time.Duration
215-
WebhookServer bool
216-
TraefikEnableLegacy bool
217-
TraefikDisableNew bool
218-
NAT64Networks []string
219-
ExcludeUnschedulable bool
220-
EmitEvents []string
221-
ForceDefaultTargets bool
222-
sourceWrappers map[string]bool // map of source wrappers, e.g. "targetfilter", "nat64"
193+
NS1ZoneHandleMap map[string]string
194+
TransIPAccountName string
195+
TransIPPrivateKeyFile string
196+
DigitalOceanAPIPageSize int
197+
ManagedDNSRecordTypes []string
198+
ExcludeDNSRecordTypes []string
199+
GoDaddyAPIKey string `secure:"yes"`
200+
GoDaddySecretKey string `secure:"yes"`
201+
GoDaddyTTL int64
202+
GoDaddyOTE bool
203+
OCPRouterName string
204+
PiholeServer string
205+
PiholePassword string `secure:"yes"`
206+
PiholeTLSInsecureSkipVerify bool
207+
PiholeApiVersion string
208+
PluralCluster string
209+
PluralProvider string
210+
WebhookProviderURL string
211+
WebhookProviderReadTimeout time.Duration
212+
WebhookProviderWriteTimeout time.Duration
213+
WebhookServer bool
214+
TraefikEnableLegacy bool
215+
TraefikDisableNew bool
216+
NAT64Networks []string
217+
ExcludeUnschedulable bool
218+
EmitEvents []string
219+
ForceDefaultTargets bool
220+
sourceWrappers map[string]bool // map of source wrappers, e.g. "targetfilter", "nat64"
223221
}
224222

225223
var defaultConfig = &Config{

provider/ns1/ns1.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,12 @@ func (n NS1DomainService) ListZones() ([]*dns.Zone, *http.Response, error) {
8585

8686
// NS1Config passes cli args to the NS1Provider
8787
type NS1Config struct {
88-
DomainFilter *endpoint.DomainFilter
89-
ZoneIDFilter provider.ZoneIDFilter
90-
NS1Endpoint string
91-
NS1IgnoreSSL bool
92-
DryRun bool
93-
MinTTLSeconds int
94-
// Optional: map a zone FQDN (or suffix) to the NS1 zone handle/ID to use
95-
// when looking up that zone. Keys/values are case-insensitive;
96-
// trailing dots on keys are ignored.
97-
// e.g. map[string]string{"example.com":"corp-prod-zone","dev.example.com":"dev-view-handle"}
88+
DomainFilter *endpoint.DomainFilter
89+
ZoneIDFilter provider.ZoneIDFilter
90+
NS1Endpoint string
91+
NS1IgnoreSSL bool
92+
DryRun bool
93+
MinTTLSeconds int
9894
ZoneHandleOverrides map[string]string
9995
}
10096

@@ -164,7 +160,7 @@ func (p *NS1Provider) Records(ctx context.Context) ([]*endpoint.Endpoint, error)
164160
for _, zone := range zones {
165161
// TODO handle Header Codes
166162
// Prefer lookup via handle/ID if an override exists; fall back to FQDN.
167-
lookup := p.zoneLookupKeyFor(zone.Zone)
163+
lookup := p.longestMatch(zone.Zone)
168164
zoneData, _, err := p.client.GetZone(lookup)
169165
if err != nil {
170166
if lookup != strings.TrimSuffix(zone.Zone, ".") {
@@ -325,13 +321,17 @@ func normalizeOverrides(m map[string]string) map[string]string {
325321
if len(m) == 0 {
326322
return map[string]string{}
327323
}
328-
out := make(map[string]string, len(m))
324+
out := make(map[string]string)
329325
for k, v := range m {
330326
kk := strings.TrimSuffix(strings.ToLower(strings.TrimSpace(k)), ".")
331327
vv := strings.ToLower(strings.TrimSpace(v))
332-
if kk != "" && vv != "" {
333-
out[kk] = vv
328+
329+
if kk == "" || vv == "" {
330+
log.Debugf("Encounted empty string for zone handle override: key=%s, value=%s", kk, vv)
331+
continue
334332
}
333+
334+
out[kk] = vv
335335
}
336336
return out
337337
}
@@ -359,7 +359,7 @@ func (p *NS1Provider) ns1ChangesByZone(zones []*dns.Zone, changeSets []*ns1Chang
359359

360360
// replace zone FQDN with zone handle if FQDN is overridden
361361
for k, v := range changes {
362-
writeKey := p.zoneLookupKeyFor(k)
362+
writeKey := p.longestMatch(k)
363363

364364
if writeKey != k {
365365
changes[writeKey] = v
@@ -370,16 +370,16 @@ func (p *NS1Provider) ns1ChangesByZone(zones []*dns.Zone, changeSets []*ns1Chang
370370
return changes
371371
}
372372

373-
// zoneLookupKeyFor returns the preferred key to pass to GetZone:
373+
// longestMatch returns the preferred key to pass to GetZone:
374374
// if an override exists for fqdn (or a more specific suffix), return its mapped handle/ID;
375375
// otherwise return the normalized FQDN.
376-
func (p *NS1Provider) zoneLookupKeyFor(fqdn string) string {
376+
func (p *NS1Provider) longestMatch(fqdn string) string {
377377
name := strings.TrimSuffix(strings.ToLower(strings.TrimSpace(fqdn)), ".")
378378
bestKey := ""
379379
for k := range p.zoneHandleOverrides {
380380
if name == k || strings.HasSuffix(name, "."+k) {
381381
if len(k) > len(bestKey) {
382-
bestKey = k // longest (most specific) match wins
382+
bestKey = k
383383
}
384384
}
385385
}

provider/ns1/ns1_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ func TestNewNS1ChangesByZone(t *testing.T) {
319319
assert.Len(t, changes["foo.com"], 3)
320320
}
321321

322-
// helper: build a change
323322
func change(action, name, rtype string) *ns1Change {
324323
return &ns1Change{
325324
Action: action,

0 commit comments

Comments
 (0)