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

remove provider store and don't initialize each DNS provider #96

Merged
merged 4 commits into from
Mar 16, 2017
Merged

remove provider store and don't initialize each DNS provider #96

merged 4 commits into from
Mar 16, 2017

Conversation

linki
Copy link
Member

@linki linki commented Mar 16, 2017

This just moves the initialization of the DNS provider API client to the Initialize method of the respective provider. This way we can register providers and then look them up via flags. We could also seamlessly support multiple providers eventually.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 16, 2017
@linki
Copy link
Member Author

linki commented Mar 16, 2017

/cc @ideahitme @mikkeloscar

main.go Outdated
log.Fatal(err)
}
dnsprovider.Register("google", dnsprovider.NewGoogleProvider(cfg.GoogleProject, cfg.DryRun))
dnsprovider.Register("aws", dnsprovider.NewAWSProvider(cfg.DryRun))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it not make more sense to only register/initialize the providers which are required?

E.g. the interface would be more like this:

provider, err := dnsprovider.Initialize(cfg.DNSProvider)

Disregard if I'm missing some context.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, sounds right. However, you would just move the following lines into a method in the dnsprovider package (I wouldn't consider this a change).

The registration part here is more annoying. It needs provider specific configuration passed in, e.g. the google project. So we still need it this way I believe. We could pass arbitrary config to your proposed Initialize method and then just forward to the picked provider, but I'm not sure if that would be any better.

Choose a reason for hiding this comment

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

yes passing "arbitrary config" to Initialize method is not best approach IMO. Another way, might be to allow store return DNS provider with/without client. But registration should occur via passing raw object. E.g:

dnsprovider.Register("aws", &dnsprovider.AWSProvider{DryRun:DryRun})
...

then store

dnsprovider.LookUpWithClient(cfg.Dnsprovider) //creates client internally based on dns provider

not sure if this is any better

Choose a reason for hiding this comment

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

and dnsprovider.NewAWSProvider() still initializes the client internally

@ideahitme
Copy link

@linki maybe not totally related to the PR, but from this it seems to be that the dnsprovider/store introduces unnecessary complexity. Why not just go with simple switch statement in main() and choose dnsprovider based on provided --dnsprovider value ?

Though I might be missing the point of store

@linki
Copy link
Member Author

linki commented Mar 16, 2017

Yeah, I see your point. I though it would become easier with this. However, the switch approach works fine until you exceed 3~4 options I guess. Then magically the other approach becomes more pleasing, I wonder why not for 2 already ^^

One thing that this approach supports and the other doesn't is the ability to have a MultiDNSProvider provider at some point, which could add DNS records at multiple places.

@linki
Copy link
Member Author

linki commented Mar 16, 2017

I would also like to see the providers registering themselve, then this would just become @mikkeloscar's proposed "activation" of the correct one.

@ideahitme
Copy link

@linki by complexity I meant the need to move out the client initialisation phase to a separate method, which does not seem intuitive to me. Ideally, I would want to get a dnsprovider instance and roll with it, because IMO initialisation phase is presumed and invisible to the user

@linki
Copy link
Member Author

linki commented Mar 16, 2017

@ideahitme @mikkeloscar I dropped the complicated store stuff.

@ideahitme
Copy link

maybe u can fix the PR title, because now it is about removing dnsprovider store :)

@linki linki changed the title do not always initialize each DNS provider remove provider store and don't initialize each DNS provider Mar 16, 2017
@ideahitme
Copy link

👍

@linki linki merged commit 8170947 into kubernetes-sigs:master Mar 16, 2017
@linki linki deleted the feat/initialize branch March 16, 2017 16:10
@mikkeloscar
Copy link
Contributor

👍

ffledgling pushed a commit to ffledgling/external-dns that referenced this pull request Jan 18, 2018
…tes-sigs#96)

* fix(dnsprovider): do not always initialize each DNS provider

* fix(dnsprovider): fix unnecessary error return value

* ref(dnsprovider): drop the store and use a simple switch for lookup
lou-lan pushed a commit to lou-lan/external-dns that referenced this pull request May 11, 2022
Fixes kubernetes-sigs#81. There's a bunch of odd rules in the parsing of stdin vs args vs
--manifest. We might need to simplify it and be more strict.

Signed-off-by: Ahmet Alp Balkan <[email protected]>
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants