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

✨ Create a supported way of setting a cache on source.Kind #794

Merged
merged 3 commits into from
Feb 17, 2020
Merged

✨ Create a supported way of setting a cache on source.Kind #794

merged 3 commits into from
Feb 17, 2020

Conversation

jkbschmid
Copy link

Create a wrapper for Kind without InjectCache to create a supported way of setting a cache on source.Kind. This can used, e.g., for watching resources on another cluster.

fixes #650

achawki and others added 2 commits February 10, 2020 13:09
- sourceWithFixedCache does not implement InjectCache
- it does not rely on the current implicit implementation that a cache
is not overwriting in case it was injected before
- see #650

Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
Co-authored-by: Ulrich Kramer <u.kramer@sap.com>
@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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 10, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @jkbschmid!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @jkbschmid. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 10, 2020
@jkbschmid
Copy link
Author

/check-cla

@c0d1ngm0nk3y
Copy link
Contributor

/check-cla

@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 Feb 10, 2020
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

Generally looks good, what becomes a bit weird now though is that some sources get initialized by allocation a var and others by using a constructuctor, IMHO consistenly using one of the two would be better.

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 10, 2020
// NewKindWithFixedCache creates a Source without InjectCache, so that it is assured that the given cache is used
// and not overwritten. It can be used to watch objects in a different cluster by passing the cache
// from that other cluster
func NewKindWithFixedCache(object runtime.Object, cache cache.Cache) Source {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func NewKindWithFixedCache(object runtime.Object, cache cache.Cache) Source {
func NewKindWithCache(object runtime.Object, cache cache.Cache) Source {

@@ -55,6 +55,22 @@ type Source interface {
Start(handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error
}

// NewKindWithFixedCache creates a Source without InjectCache, so that it is assured that the given cache is used
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// NewKindWithFixedCache creates a Source without InjectCache, so that it is assured that the given cache is used
// NewKindWithCache creates a Source without relying on InjectCache, so that it is assured that the given cache is used

@vincepri
Copy link
Member

Minor comments, otherwise lgtm

Copy link

@kensipe kensipe left a comment

Choose a reason for hiding this comment

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

agree with vincepri comments otherwise lgtm

@gerred
Copy link
Contributor

gerred commented Feb 17, 2020

agreed with @alvaroaleman - if all a constructor doing here is instantiating a struct, I don't think we should use one. Why can't this be a public struct, or why can't we just change Cache to be exported as well?

cache cache.Cache

Furthermore, if that's the direction we're going, we should probably embed the struct into kindWithCache rather than creating an entirely new struct. The only difference between the two is the extra bytes for the reference.

Simplifying this enables us to create a DefaultKind that in effect preserves the existing functionality, rather than new structs and new constructors.

@gerred
Copy link
Contributor

gerred commented Feb 17, 2020

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 17, 2020
@gerred
Copy link
Contributor

gerred commented Feb 17, 2020

I just read the linked thread and while I think we should look for a cleaner long term solution, I understand the problem and the reason we have this solution.

/hold cancel
/approve

Still a little concerned since it's going to be harder to remove this API once people start depending on it.

@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 Feb 17, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gerred, jkbschmid

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 Feb 17, 2020
@c0d1ngm0nk3y
Copy link
Contributor

Why can't this be a public struct, or why can't we just change Cache to be exported as well

But then we would end up with a struct that cannot be used until the cache is set. You would have to document this. With the constructor, it is safe to use and you cannot use it in a wrong way.

@alvaroaleman
Copy link
Member

But then we would end up with a struct that cannot be used until the cache is set. You would have to document this. With the constructor, it is safe to use and you cannot use it in a wrong way.

I agree with that. Maybe we can add constructors for all sources and mark the direct usage of the structs as deprecated, so this is consistent.

@@ -55,6 +55,22 @@ type Source interface {
Start(handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error
}

// NewKindWithCache creates a Source without InjectCache, so that it is assured that the given cache is used
Copy link
Member

Choose a reason for hiding this comment

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

Nit: the first sentence of this godoc is basically for ppl who know how its implemented and not explaining the purpose which is far more important. It would be nice to just say sth like NewKindWithCache is used to create a Wach for a different cluster, then go on with the implementation details like "this is achieved by intentionally not implementing InjectCache" etc. Would be great if someone could create a followup for that.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 17, 2020
@alvaroaleman
Copy link
Member

/retest

We should probably throw more CPU at this job and hope that stabilizes it.

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Define a supported way of setting a cache on source.Kind
9 participants