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

Support for multiple domains within --domain-filter #252

Merged
merged 11 commits into from
Jun 29, 2017
Merged

Support for multiple domains within --domain-filter #252

merged 11 commits into from
Jun 29, 2017

Conversation

totallyunknown
Copy link
Contributor

@totallyunknown totallyunknown commented Jun 27, 2017

The parameter accepts a comma separated list of domains with or without trailing dot. Example: --domain-filter="example.org, company.test.,staging.com". Closes #247 and #229

The parameter accepts a comma separated list of domains with or without trailing dot. Example: --domain-filter="example.org, company.test.,staging.com". Closes #247 and #229
@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jun 27, 2017
@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 Jun 27, 2017
@hjacobs
Copy link
Contributor

hjacobs commented Jun 27, 2017

Thanks for the PR!

main.go Outdated
@@ -108,20 +109,22 @@ func main() {

endpointsSource := source.NewDedupSource(source.NewMultiSource(sources))

domainFilter := domains.NewDomainFilter(cfg.DomainFilter)
Copy link
Member

Choose a reason for hiding this comment

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

👍 very nice!

@@ -99,7 +99,7 @@ func (cfg *Config) ParseFlags(args []string) error {
// Flags related to providers
app.Flag("provider", "The DNS provider where the DNS records will be created (required, options: aws, google, azure, cloudflare, digitalocean, inmemory)").Required().PlaceHolder("provider").EnumVar(&cfg.Provider, "aws", "google", "azure", "cloudflare", "digitalocean", "inmemory")
app.Flag("google-project", "When using the Google provider, specify the Google project (required when --provider=google)").Default(defaultConfig.GoogleProject).StringVar(&cfg.GoogleProject)
app.Flag("domain-filter", "Limit possible target zones by a domain suffix (optional)").Default(defaultConfig.DomainFilter).StringVar(&cfg.DomainFilter)
app.Flag("domain-filter", "Limit possible target zones by a comma separeted list of domain suffixes (optional)").Default(defaultConfig.DomainFilter).StringVar(&cfg.DomainFilter)
Copy link
Member

Choose a reason for hiding this comment

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

I would like to change this to use StringVars, note the traling s. This already supports processing multiple strings into a single string slice. This avoids strings.Split(",") in your code.

Furthermore, it changes the usage to provide the flag --domain-filter multiple times. Your example would become:

external-dns \
  --domain-filter=example.com \
  --domain-filter=company.org \
  --domain-filter=staging-company.org

This approach is also used by helm and kubernetes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason doing this way is, it's much easier to inject multiple domains as a single environmental variable into the pod. But might we work with a variable like this DOMAINS="--domain-filter foobar.org --domain-filter bla.org"..

Copy link
Member

Choose a reason for hiding this comment

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

True, but I would like to push this problem to kingpin. Ideally kingpin would allow to support both modes when using StringVars. FWIW kingpin's env var for this flag is DOMAIN_FILTER and you can specify multiple values by separating them with a line break.

Copy link
Member

Choose a reason for hiding this comment

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

lol, you already know that 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but it's ugly.

for i, tt := range domainFilterTests {
domainFilter := NewDomainFilter(tt.domainFilter)
for _, domain := range tt.domains {
require.Equal(t, tt.expected, domainFilter.Match(domain), "should not fail: %v in test-case #%v", domain, i)
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer assert.Equal here.

for _, tt := range domainFilterTests {
domainFilter := DomainFilter{}
for i, domain := range tt.domains {
require.True(t, domainFilter.Match(domain), "should not fail: %v in test-case #%v", domain, i)
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer assert.True here.

filters = append(filters[:i], filters[i+1:]...)
i--
}
}
Copy link
Member

Choose a reason for hiding this comment

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

That looks quite complicated. Maybe we can add some comments on what it's doing.


for _, filter := range df.filters {

// user can define domains either with trailing dot or without.
Copy link
Member

@linki linki Jun 28, 2017

Choose a reason for hiding this comment

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

I think it's better to sanitize both domains and then have only one suffix check. E.g. you could append or strip it from the provided filters before storing them. And then do the same with domain here before going through the filters.

We settled with stripping it from the domain in several parts of the code. But yeah, it's a little annoying.

@totallyunknown
Copy link
Contributor Author

Please take a look. Changed the implementation to StringsVar() and change the code regarding your comments.

main.go Outdated
@@ -35,6 +35,7 @@ import (
"github.com/kubernetes-incubator/external-dns/controller"
"github.com/kubernetes-incubator/external-dns/pkg/apis/externaldns"
"github.com/kubernetes-incubator/external-dns/pkg/apis/externaldns/validation"
"github.com/kubernetes-incubator/external-dns/pkg/util/domains"

Choose a reason for hiding this comment

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

why is this in the util ? it is generally not a good practice to put things into util, if it is part of the provider, it should be in the provider package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I put it directly into provider package?

Choose a reason for hiding this comment

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

If the domain filter only to be used by providers then yes, it should be either in provider package directory, or it's child subdirectory.
If we find that provider exposes too many types/functions we can think of refactoring it later on

}
}

func TestDomainFilter_Match_default_Filter_always_matches(t *testing.T) {

Choose a reason for hiding this comment

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

please remove underscores and use camelcase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree

@@ -84,7 +84,7 @@ spec:
args:
- --source=service
- --source=ingress
- --domain-filter=external-dns-test.my-org.com. # will make ExternalDNS see only the hosted zones matching provided domain, omit to process all available hosted zones
- --domain-filter=external-dns-test.my-org.com # will make ExternalDNS see only the hosted zones matching provided domain, omit to process all available hosted zones
Copy link

@ideahitme ideahitme Jun 29, 2017

Choose a reason for hiding this comment

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

I would not change tutorials before the new release, the tutorial is anyway tied to the previous release

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, is there a branch that is setup for those types of changes that PRs could be created against to allow PR authors the ability to update the docs with a stable 'release' process and limit your need to update them?

Choose a reason for hiding this comment

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

@jrnt30 no, but would be interesting to hear if you don't mind explaining the process in the docs (maybe create a PR with modified contribution guidelines) ?


// NewDomainFilter returns a new DomainFilter given a comma separated list of domains
func NewDomainFilter(filters []string) DomainFilter {

Copy link

@ideahitme ideahitme Jun 29, 2017

Choose a reason for hiding this comment

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

nitpick: it is better to make a new slice and copy the strings into it without retaining pointer from SliceHeader

@ideahitme
Copy link

please update the changelog, and it is good to be merged

@ideahitme ideahitme added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 29, 2017
@totallyunknown
Copy link
Contributor Author

Updated the changelog.

Copy link

@ideahitme ideahitme left a comment

Choose a reason for hiding this comment

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

thanks

@kubernetes-sigs kubernetes-sigs deleted a comment from k8s-ci-robot Jun 29, 2017
@linki
Copy link
Member

linki commented Jun 29, 2017

@totallyunknown This is also a fix for #229 right?

Copy link
Member

@linki linki left a comment

Choose a reason for hiding this comment

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

great!

@ideahitme ideahitme merged commit 73d3979 into kubernetes-sigs:master Jun 29, 2017
@totallyunknown
Copy link
Contributor Author

Thanks for merging!

@linki
Copy link
Member

linki commented Jun 30, 2017

@totallyunknown Thanks!

ffledgling pushed a commit to ffledgling/external-dns that referenced this pull request Jan 18, 2018
)

* Support for multiple domains within --domain-filter

The parameter accepts a comma separated list of domains with or without trailing dot. Example: --domain-filter="example.org, company.test.,staging.com". Closes kubernetes-sigs#247 and kubernetes-sigs#229

* Add boilerplate header

* Add documentation for methods and structs

* use StringsVar for the domain-filter flag

* go fmt

* Remove camel case from tests

* Revert changes in README.md

* Move DomainFilter to provider package

* Make a new slice and copy elements to it

* Update CHANGELOG.md

* docs: change minor spelling mistake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants