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

dynamic informer factory #69308

Merged
merged 1 commit into from
Oct 11, 2018
Merged

Conversation

p0lyn0mial
Copy link
Contributor

@p0lyn0mial p0lyn0mial commented Oct 1, 2018

What this PR does / why we need it: adds dynamic informer factory

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged): #64319

Special notes for your reviewer:

Release note:

adds dynamic shared informers to write generic, non-generated controllers

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 1, 2018
@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 1, 2018
@p0lyn0mial
Copy link
Contributor Author

/assign @deads2k

}

// Start initializes all requested informers.
// TODO: accept context ?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wdyt ?

Copy link
Contributor

Choose a reason for hiding this comment

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

No context. The start should be consistent with the normal SharedInformerFactory. It may be helpful to make an interface that contains both. It would have

  1. start
  2. waitforcachesync
  3. forresource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would have to create a new interface that would contain methods that accept the context. Golang doesn't support method overloading :)

f.lock.Lock()
defer f.lock.Unlock()

// TODO: do we want to format the keys ?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to make debugging more informative, especially when using WaitForCacheSync rather than printing something like /v1, Resources=pod

Copy link
Contributor

Choose a reason for hiding this comment

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

to make debugging more informative, especially when using WaitForCacheSync rather than printing something like /v1, Resources=pod

I would key on the natural gvr and then coerce the display however we like

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, good idea.

}

// NewFilteredDynamicInformer constructs a new informer for a dynamic type.
func NewFilteredDynamicInformer(client dynamic.Interface, gvr schema.GroupVersionResource, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions TweakListOptionsFunc) informers.GenericInformer {
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 this method be public ?
should this method return GenericInformer ?

Copy link
Contributor

Choose a reason for hiding this comment

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

should this method be public ?
should this method return GenericInformer ?

this looks reasonable.

WaitForCacheSync(stopCh <-chan struct{}) map[string]bool
}

type TweakListOptionsFunc func(*metav1.ListOptions)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you okay with defining this func here ?
I think it is already defined somewhere here k8s.io/client-go/informers/internalinterfaces

Copy link
Contributor

Choose a reason for hiding this comment

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

are you okay with defining this func here ?
I think it is already defined somewhere here k8s.io/client-go/informers/internalinterfaces

Yes, we want to keep this here. Eventually we are likely to need to snip the links to the typed clients.

@p0lyn0mial
Copy link
Contributor Author

@deads2k waiting for your feedback before adding some tests.

namespace string

lock sync.Mutex
informers map[string]informers.GenericInformer
Copy link
Contributor

Choose a reason for hiding this comment

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

I expected a GVR


// New returns a new shim for Lister.
// It wraps Lister so that it implements cache.GenericLister interface
func NewShim(lister Lister) cache.GenericLister {
Copy link
Contributor

Choose a reason for hiding this comment

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

NewRuntimeObjectShim?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

np

@deads2k
Copy link
Contributor

deads2k commented Oct 2, 2018

This looks really good. Have you been able to think of a good way to test it?

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 2, 2018
@p0lyn0mial
Copy link
Contributor Author

Have you been able to think of a good way to test it?

not much, but I expect it will be messy, I think the flow will be:

  1. create a fake client
  2. create a factory and give it the fake client
  3. create an informer
  4. start and wait for the informer
  5. use the fake client to add a resource
  6. get the lister and see if the resource is there ?

@jennybuckley
Copy link

/cc @yliaog

@deads2k
Copy link
Contributor

deads2k commented Oct 8, 2018

not much, but I expect it will be messy, I think the flow will be:

  1. create a fake client
  2. create a factory and give it the fake client
  3. create an informer
  4. start and wait for the informer
  5. use the fake client to add a resource
  6. get the lister and see if the resource is there ?

/lgtm
pending test

/hold

holding for the test.

@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. lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 8, 2018
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 8, 2018
@p0lyn0mial
Copy link
Contributor Author

added missing test, PTAL

@yliaog
Copy link
Contributor

yliaog commented Oct 9, 2018

the commit "adds dynamic lister" 5c9261294cbcf1e2daab5719bbc8b4cd4dcd0a6c could be removed

@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 10, 2018
@deads2k
Copy link
Contributor

deads2k commented Oct 10, 2018

/lgtm
/hold cancel

@p0lyn0mial great job.

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Oct 10, 2018
@deads2k
Copy link
Contributor

deads2k commented Oct 10, 2018

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, p0lyn0mial

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 Oct 10, 2018
@yue9944882
Copy link
Member

/kind feature

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Oct 11, 2018
@p0lyn0mial
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws

@k8s-ci-robot k8s-ci-robot merged commit effd009 into kubernetes:master Oct 11, 2018
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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.

None yet

6 participants