Skip to content

Conversation

cbertinato
Copy link

What does it do ?

This PR introduces the ability to explicitly override a zone FQDN with a "zone handle" for the NS1 provider, which is an organization-unique identifier for a zone in NS1.

Motivation

When a zone is created in NS1 and a zone handle is not specified, then the zone handle is the same as the zone FQDN. However, if a zone has been created with a zone handle that is different from its FQDN, then external-dns will fail to find that zone in NS1.

The functionality allows one to explicitly map an FQDN to a zone handle via flags:

--ns1-zone-handle-map=dev.example.com=dev-view

and by environment variable:

EXTERNAL_DNS_NS1_ZONE_HANDLE_MAP="example.com=corp-prod\ndev.example.com=dev-view"

If a zone handle override is not found for a given FQDN, then external-dns will default to using the FQDN to identify the zone.

More

  • Yes, this PR title follows Conventional Commits
  • Yes, I added unit tests
  • Yes, I updated end user documentation accordingly

Copy link

linux-foundation-easycla bot commented Aug 18, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @cbertinato!

It looks like this is your first PR to kubernetes-sigs/external-dns 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/external-dns has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 18, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @cbertinato. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added apis Issues or PRs related to API change controller Issues or PRs related to the controller docs size/L Denotes a PR that changes 100-499 lines, ignoring generated files. provider Issues or PRs related to a provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 18, 2025
Copy link
Collaborator

@mloiseleur mloiseleur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbertinato Thanks for this PR.

Would you please update the ns1 tutorial accordingly ?

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 20, 2025
@cbertinato cbertinato force-pushed the map-ns1-zone-handle branch from 949f0e7 to 3625a8e Compare August 20, 2025 21:16
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 20, 2025
@cbertinato
Copy link
Author

@mloiseleur you got it!

Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com>
@mloiseleur
Copy link
Collaborator

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 22, 2025
@ivankatliarchuk
Copy link
Contributor

Could you share evidences that NS1 provider still works with and without this new flag?

Copy link
Contributor

@szuecs szuecs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, mostly cosmetic stuff but the error handling is a blocker for me.

EmitEvents []string
ForceDefaultTargets bool
sourceWrappers map[string]bool // map of source wrappers, e.g. "targetfilter", "nat64"
// Accepts repeatable --ns1-zone-handle-map flags or a comma-separated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either godoc style or none as the others.

@@ -91,6 +91,11 @@ type NS1Config struct {
NS1IgnoreSSL bool
DryRun bool
MinTTLSeconds int
// Optional: map a zone FQDN (or suffix) to the NS1 zone handle/ID to use
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please godoc style or no comment

if err != nil {
return nil, err
if lookup != strings.TrimSuffix(zone.Zone, ".") {
// fallback to FQDN lookup if override missed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should better fail by an error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean return an error instead of falling back?

if err != nil {
return nil, err
if lookup != strings.TrimSuffix(zone.Zone, ".") {
// fallback to FQDN lookup if override missed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should better fail by an error.

if len(m) == 0 {
return map[string]string{}
}
out := make(map[string]string, len(m))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can drop the len hint for maps. You won't have any advantage in doing this and it is uncommon for maps to have it.

for k, v := range m {
kk := strings.TrimSuffix(strings.ToLower(strings.TrimSpace(k)), ".")
vv := strings.ToLower(strings.TrimSpace(v))
if kk != "" && vv != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want to log anything because it looks like an error if you end up ignoring empty string.

// otherwise return the normalized FQDN.
func (p *NS1Provider) zoneLookupKeyFor(fqdn string) string {
name := strings.TrimSuffix(strings.ToLower(strings.TrimSpace(fqdn)), ".")
bestKey := ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change the name to longestMatch and you can delete the comment below.

for k := range p.zoneHandleOverrides {
if name == k || strings.HasSuffix(name, "."+k) {
if len(k) > len(bestKey) {
bestKey = k // longest (most specific) match wins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment

assert.Len(t, changes["bar.com"], 1)
assert.Len(t, changes["foo.com"], 3)
}

// helper: build a change
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the comment because it ha no value

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 24, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from mloiseleur. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cbertinato
Copy link
Author

@ivankatliarchuk yes, I will do. Also, I will address all feedback @szuecs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apis Issues or PRs related to API change cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. controller Issues or PRs related to the controller docs ok-to-test Indicates a non-member PR verified by an org member that is safe to test. provider Issues or PRs related to a provider size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants