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

code-gen: allow specifying custom resync periods for certain informer types #61400

Merged
merged 2 commits into from Apr 6, 2018

Conversation

natronq
Copy link
Contributor

@natronq natronq commented Mar 20, 2018

What this PR does / why we need it:
This PR extends the informer code-generator to allow the consumer to specify a custom resync period for certain informer types and uses the default resync period if none is defined.

Special notes for your reviewer:
Example:

cs := clientset.NewForConfigOrDie(config)
resyncConfig := externalversions.ResyncConfiguration{
  &samplev1alpha1.Sample{}: 30 * time.Second,
}
informer := externalversions.NewSharedInformerFactory(cs, 2*time.Minute, externalversions.WithCustomResyncConfig(resyncConfig))

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 20, 2018
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. 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 Mar 20, 2018
@natronq
Copy link
Contributor Author

natronq commented Mar 20, 2018

/assign @wojtek-t

@dims
Copy link
Member

dims commented Mar 23, 2018

/ok-to-test

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 23, 2018
@natronq
Copy link
Contributor Author

natronq commented Mar 29, 2018

/retest

@natronq
Copy link
Contributor Author

natronq commented Mar 30, 2018

/retest

@natronq
Copy link
Contributor Author

natronq commented Mar 31, 2018

/cc @sttts

@k8s-ci-robot k8s-ci-robot requested a review from sttts March 31, 2018 15:04
}

// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory.
// Listers obtained via this SharedInformerFactory will be subject to the same filters
// as specified here.
func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory {
func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc,
Copy link
Contributor

Choose a reason for hiding this comment

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

why does NewFilteredSharedInformerFactory get the resyncConfig param, but NewSharedInformerFactory doesn't?

Instead of adding more args, we should switch to another extension pattern, maybe informer.WithCustomResyncs.

Copy link
Contributor Author

@natronq natronq Apr 3, 2018

Choose a reason for hiding this comment

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

Adding the parameter to NewSharedInformerFactory would cause a huge refactor accross the Kubernetes code-base, because all consumers of this package exclusivley use this method to instantiate a new factory.

Changing the arguments of NewFilteredSharedInformerFactory does not break any existing functionality as it is not used verbatim. So this seemed like a natural fit as it also already incorporates custom list options.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I wanted to say is that adding another param is the wrong pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so you would suggest adding a seperate method e.g. NewSharedInformerFactoryWithCustomResyncinstead?

Copy link
Contributor

Choose a reason for hiding this comment

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

No. Rather I would prefer some functional style pattern:

NewSharedInformerFactory(...).WithTweakListOptions(...).WithCustomResyncConfig(...).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored accordingly.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 5, 2018
@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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 5, 2018
@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 Apr 5, 2018
func NewFilteredSharedInformerFactory(client internalclientset.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory {
return &sharedInformerFactory{
// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory contained to the specified namespace with additional options.
func NewFilteredSharedInformerFactory(client internalclientset.Interface, defaultResync time.Duration, namespace string, options ...SharedInformerOption) SharedInformerFactory {
Copy link
Contributor

@sttts sttts Apr 5, 2018

Choose a reason for hiding this comment

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

we have to leave the old func and reimplement it with NewInformerFactoryWithOptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Disregard my previous comment. it's compatible. But still, I would not add the options here. Instead I would even deprecate it in favor of the generic other variant with options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As NewFilteredSharedInformerFactory is not used anywhere I deleted it and introdued NewSharedInformerFactoryWithOptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's used by 3rdparties. Would leave it and just deprecate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -44,36 +44,63 @@ import (
storage "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion/storage"
)

type ResyncConfiguration map[v1.Object]time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need a ResyncConfiguration type? Sounds "over-abstracted".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, removed it.

@@ -13651,7 +13651,7 @@ msgstr "Imposta il current-context in un file kubeconfig"

#: pkg/kubectl/cmd/describe.go:86
msgid "Show details of a specific resource or group of resources"
msgstr "Mostra i dettagli di una specifiche risorsa o un gruppo di risorse"
msgstr "Mostra i dettagli di una specifica risorsa o un gruppo di risorse"
Copy link
Contributor

Choose a reason for hiding this comment

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

unexpected change. Make it another commit at least if this fix is right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was not intended. I think it was caused by running update-codegen.sh against the current master.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a spell checker included now? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Wow. Anyway, saw the same issue. The checked in bindata is broken it seems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Separated it in another commit.

@natronq natronq force-pushed the master branch 2 times, most recently from 75e85e5 to 5025e4a Compare April 5, 2018 12:52
}

// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options.
func NewSharedInformerFactoryWithOptions(client internalclientset.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory {
Copy link
Contributor

Choose a reason for hiding this comment

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

While not exactly the same type, this is compatible with NewSharedInformerFactory calls. It might be worth to merge those two again. I think the chance is high that nobody passes around constructors such that this change will make any trouble.

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 agree that compatibility is probably not an issue here, but I actually prefer having a separate method for passing the options. It is more verbose and immediately clear to the caller that this method accepts additional options.

@sttts
Copy link
Contributor

sttts commented Apr 5, 2018

/cc @caesarxuchao @ncdc any opinion about this style? I like this much more than adding more and more constructors. This pattern is much more idiomatic.

@ncdc
Copy link
Member

ncdc commented Apr 5, 2018

Style is great. Let's do this!

@@ -98,36 +99,78 @@ func (g *factoryGenerator) GenerateType(c *generator.Context, t *types.Type, w i
}

var sharedInformerFactoryStruct = `
type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory
Copy link
Member

Choose a reason for hiding this comment

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

Add godoc?


informers map[{{.reflectType|raw}}]{{.cacheSharedIndexInformer|raw}}
// startedInformers is used for tracking which informers have been started.
// This allows Start() to be called multiple times safely.
startedInformers map[{{.reflectType|raw}}]bool
}

// NewSharedInformerFactory constructs a new instance of sharedInformerFactory
// Sets a custom resync period for the specified informer types.
Copy link
Member

Choose a reason for hiding this comment

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

Please use the function name as the beginning of the comment, i.e. // WithCustomResyncConfig sets a ...

}
}

// Sets a custom filter on all listers of the configured SharedInformerFactory.
Copy link
Member

Choose a reason for hiding this comment

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

Please use the function name as the beginning of the comment, i.e. // WithTweakListOptions sets a ...

}
}

// Limits the SharedInformerFactory to the specified namespace.
Copy link
Member

Choose a reason for hiding this comment

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

Please use the function name as the beginning of the comment, i.e. // WithNamespace limits the ...

@ncdc
Copy link
Member

ncdc commented Apr 5, 2018

@natronq thanks for this - I really like it.

… types and switch to functional option pattern for SharedInformerFactory
@natronq
Copy link
Contributor Author

natronq commented Apr 5, 2018

@ncdc Refactored according to your comments.

@natronq
Copy link
Contributor Author

natronq commented Apr 6, 2018

/retest

@ncdc
Copy link
Member

ncdc commented Apr 6, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 6, 2018
@sttts
Copy link
Contributor

sttts commented Apr 6, 2018

/approve

@ncdc
Copy link
Member

ncdc commented Apr 6, 2018

/assign @deads2k for approval

@k8s-ci-robot
Copy link
Contributor

@ncdc: GitHub didn't allow me to assign the following users: for, approval.

Note that only kubernetes members and repo collaborators can be assigned.

In response to this:

/assign @deads2k for approval

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.

@deads2k
Copy link
Contributor

deads2k commented Apr 6, 2018

/cc @caesarxuchao @ncdc any opinion about this style? I like this much more than adding more and more constructors. This pattern is much more idiomatic.

I dislike the style, but as long as the types remain private to make it impossible to write "trust me, I'm doing good things" functions I won't fight it.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, natronq, ncdc, sttts

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 Apr 6, 2018
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 61400, 61048). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 7daaa82 into kubernetes:master Apr 6, 2018
@k8s-ci-robot
Copy link
Contributor

@natronq: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-verify a923acd link /test pull-kubernetes-verify

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

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. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants