Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ZoneIDFilter for Cloudflare #1494

Merged
merged 1 commit into from
May 22, 2020

Conversation

james-callahan
Copy link
Contributor

This PR is a rebased and cleaned up #1307

This commit should help #1127. While users in the past were able to
define ZoneIDFilter for this provider, it did not actually do anything
under the hood.

In this case, we're changing Zones() to iterate over the provided
zoneIDs and return only those zones.

I would have also done this for domainFilter, but unfortunately the
CloudFlare API requires that in order to list zones (and find them by
name) that you have "all" permissions, which seems silly. After talking
to their support, this is probably the best way to do this.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 8, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @james-callahan!

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 the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 8, 2020
@k8s-ci-robot k8s-ci-robot requested review from linki and Raffo April 8, 2020 04:47
@james-callahan
Copy link
Contributor Author

/assign @hjacobs

@drGrove
Copy link
Contributor

drGrove commented Apr 8, 2020

Here's an image with the changes. i built it as I needed it for a project and it works as intended: https://hub.docker.com/layers/drgrove/external-dns/0.7.1_dev1/images/sha256-27b1618cb574ec6a3a79cec4ba4e909c2b1d0c75f399851f1092bdaa54abc334?context=repo

@james-callahan
Copy link
Contributor Author

CI failure seems unrelated:

$ make lint
golangci-lint run --timeout=5m ./...
provider/coredns.go:33: File is not `goimports`-ed (goimports)
	etcdcv3 "go.etcd.io/etcd/clientv3"
Makefile:34: recipe for target 'lint' failed
make: *** [lint] Error 1
The command "make lint" exited with 2.

@njuettner
Copy link
Member

Thanks, can you please rebase from master again, should be fixed now 👍.

Copy link
Member

@njuettner njuettner left a comment

Choose a reason for hiding this comment

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

Added some comments, PTAL.

@@ -150,6 +155,26 @@ func (p *CloudFlareProvider) Zones(ctx context.Context) ([]cloudflare.Zone, erro
result := []cloudflare.Zone{}
p.PaginationOptions.Page = 1

// if there is a zoneIDfilter configured
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is needed, the code already explains it so I would drop the comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(note: I didn't write this: the author of #1307 did):

The following line that notes that empty strings are used by tests is informative.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see my bad, I would still like to drop those lines. Maybe only keep the second ... blank string for unit tests ...

@@ -150,6 +155,26 @@ func (p *CloudFlareProvider) Zones(ctx context.Context) ([]cloudflare.Zone, erro
result := []cloudflare.Zone{}
p.PaginationOptions.Page = 1

// if there is a zoneIDfilter configured
// && if the filter isnt just a blank string (used in tests)
if len(p.zoneIDFilter.zoneIDs) > 0 && p.zoneIDFilter.zoneIDs[0] != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you could add a new method ZoneDetailsByDomainFilter which includes your code.

Copy link
Member

Choose a reason for hiding this comment

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

or ListZonesByIDFilter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to split this off (and create functions that each returned iterators) but my minimal knowledge of Go wasn't enough to get things working.

Splitting off just the contents of this branch didn't seem to improve readability.

continue
}

if !p.zoneIDFilter.Match(zone.ID) {
Copy link
Member

Choose a reason for hiding this comment

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

Just to understand it a bit better, this is dropped because it's not working?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropped because if there was any zoneIDFilter then the above branch would be taken and this code is unreachable.

@sheerun
Copy link
Contributor

sheerun commented Apr 16, 2020

Cheering for this to be merged. Right now I need to issue access token that has access to read all zones

sheerun added a commit to sheerun/external-dns that referenced this pull request Apr 16, 2020
sheerun added a commit to sheerun/external-dns that referenced this pull request Apr 16, 2020
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 5, 2020
@k8s-ci-robot k8s-ci-robot removed the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 21, 2020
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 21, 2020
@k8s-ci-robot k8s-ci-robot added 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 May 21, 2020
@james-callahan
Copy link
Contributor Author

/assign @sheerun

@sheerun
Copy link
Contributor

sheerun commented May 21, 2020

@james-callahan Please sign CLA

@sheerun
Copy link
Contributor

sheerun commented May 21, 2020

Or is it @dmizelle that haven't signed?

@james-callahan
Copy link
Contributor Author

cla check passed: it is dmizelle's code.

@sheerun
Copy link
Contributor

sheerun commented May 21, 2020

I need to consult kubernetes team what to do in cases like this...

@sheerun
Copy link
Contributor

sheerun commented May 21, 2020

Two things smell bad here:

  • There's no need to define ZoneDetails on interface
  • If some zoneId doesn't exist, none are processed, instead it should be skipped with error message

This commit _should_ help kubernetes-sigs#1127. While users in the past were able to
define ZoneIDFilter for this provider, it did not actually do anything
under the hood.

In this case, we're changing Zones() to iterate over the provided
zoneIDs and return only those zones.

I would have also done this for domainFilter, but unfortunately the
CloudFlare API requires that in order to list zones (and find them by
name) that you have "all" permissions, which seems silly. After talking
to their support, this is probably the best way to do this.

Signed-off-by: James Callahan <jamescallahan@bitgo.com>
@james-callahan
Copy link
Contributor Author

james-callahan commented May 21, 2020

  • There's no need to define ZoneDetails on interface

Why not?

  • If some zoneId doesn't exist, none are processed, instead it should be skipped with error message

Fixed.

@sheerun
Copy link
Contributor

sheerun commented May 22, 2020

I thought that ZoneList supports multiple domains, but it's probably not the case: https://community.cloudflare.com/t/bug-zone-detail-by-name-requires-zone-list-permission/128042/15

@sheerun
Copy link
Contributor

sheerun commented May 22, 2020

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: james-callahan, sheerun

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 22, 2020
@sheerun
Copy link
Contributor

sheerun commented May 22, 2020

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 22, 2020
@k8s-ci-robot k8s-ci-robot merged commit 4f6ba41 into kubernetes-sigs:master May 22, 2020
@james-callahan james-callahan deleted the zoneid-filter branch May 25, 2020 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants