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

Refactor using single SharedInformer #244

Merged

Conversation

davidvonthenen
Copy link
Contributor

What this PR does / why we need it:
This was some fallout from creating listers for multiple secrets for VC creds. This refactors NewInformer so that only a single SharedInformer is created. In English, we only have a single watcher for all secrets.

Which issue this PR fixes : fixes #243

Special notes for your reviewer:
Tested on k8s 1.14.1 on vsphere 6.7u2 using multiple secrets.

Release note:
NA

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 4, 2019
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 4, 2019
@davidvonthenen
Copy link
Contributor Author

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 4, 2019
@davidvonthenen
Copy link
Contributor Author

/hold cancel

This is ready for review...

CC: @andrewsykim @frapposelli

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 4, 2019
var signalHandler <-chan struct{}
var (
signalHandler <-chan struct{}
informerFactory informers.SharedInformerFactory
Copy link
Member

Choose a reason for hiding this comment

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

Not a fan of global var for the informer factory, is there a way to build the informer factory in Initialize() and just pass down only the needed informers down to connection manager (i.e. informerFactory.Core().Secrets())?

Copy link
Member

@andrewsykim andrewsykim Sep 4, 2019

Choose a reason for hiding this comment

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

hmmm okay, I see now that would require a larger refactor on the InformerManager

Copy link
Contributor Author

@davidvonthenen davidvonthenen Sep 4, 2019

Choose a reason for hiding this comment

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

I think it's ok as a global. The global informerFactory isn't exported out of the package/process so it can't be re-used by other processes. Since this global is confined to this package, you are getting exactly what you want... a single informer factory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you really do want to pass in the variable, it would require a second function for NewInformer(WithProvidedFactory) and also a second function to InitializeSecretLister(WithProvidedFactory), but it would still accomplish effectively the same thing with a private global.

Copy link
Member

Choose a reason for hiding this comment

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

So I think my biggest concern with this is that you would call informerFactory.Start() multiple times for multiple InformerManagers using the same shared informer factory. Ideally you construct the informer factory in one place and pass that into various types that need resource-specific informers and you would call informerFactory.Start() once, ideally in the same place you constructed it. With that said, I think the real problem isn't the global var but the InformerManager type which makes it hard to easily pass down the informer factory but probably don't want to address that in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I looked at the code behind Start() and also tested to make sure the behavior is correct. That's why I made the update to the function comment. You can call Start() multiple times as you add in new Listers and it only inits the new ones.

The downside of getting all of the Listers upfront, is it complicates the CPI init logic a lot.


// NewInformer creates a newk8s client based on a service account
func NewInformer(client clientset.Interface) *InformerManager {
func NewInformer(client clientset.Interface, singleWatcher bool) *InformerManager {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the singleWatcher toggle? In what scenario would we not want a single informer for all lister/watchers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, we don't have a need for it currently. Was just trying to preserve the option. Only reason for it would be having multiple client connections based on individual service accounts.

If you want to remove it and tackle it when we get there, that cool. Just let me know.

var signalHandler <-chan struct{}
var (
signalHandler <-chan struct{}
informerFactory informers.SharedInformerFactory
Copy link
Member

Choose a reason for hiding this comment

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

So I think my biggest concern with this is that you would call informerFactory.Start() multiple times for multiple InformerManagers using the same shared informer factory. Ideally you construct the informer factory in one place and pass that into various types that need resource-specific informers and you would call informerFactory.Start() once, ideally in the same place you constructed it. With that said, I think the real problem isn't the global var but the InformerManager type which makes it hard to easily pass down the informer factory but probably don't want to address that in this PR.

@andrewsykim
Copy link
Member

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 4, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewsykim

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 Sep 4, 2019
@k8s-ci-robot k8s-ci-robot merged commit b67f516 into kubernetes:master Sep 4, 2019
@davidvonthenen davidvonthenen deleted the feature/sharedinformer branch September 4, 2019 19:58
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/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update NewInformer to reuse SharedInformerFactory but create NewLister
3 participants