-
Notifications
You must be signed in to change notification settings - Fork 1.2k
✨ Add support for creating namespaced watches #694
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
Conversation
* If informer cache is configured to handle all namespaces - use it as key in all lookups to avoid cache duplication * If informer cache is configured to handle a specific namespace - create separate cache which will be used for lookups
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. |
Hi @lulf. 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 Once the patch is verified, the new status will be reflected by the 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lulf The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
listOpts.ApplyOptions(opts) | ||
|
||
// If configured using a global namespace, use its cache to avoid duplication | ||
if ip.namespace == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So generally this looks like it will work and I like the overall idea of "use specific cache unless configured to use global one" :)
There are however some things to consider:
- If I read this correctly, using a
source.Kind
with aNamespace
setting and a non-namespacedspecificInformersMap
will result in getting events from all namespaces, which is not expected - The current approach means that as soon as any namespace is configured, caches will get established for all namespaces an object was ever requested from which is also unexpected
- When thinking about this approach in the context of label selectors I think just a binary "cache for everything if global cache, else distinct cache for every label selector ever used" is not enough, as it may lead to quite a bit of duplication again. Maybe a list of label selectors for which we want a distinct cache and then have the client internally either use the specific cache or do the label-selecting after receiving the objects from the cache?
- More of a nit, but I think it will be better to not re-use
client.ListOptions
for theGet
on the cache map, as that forces us to keep their feature set on par
At the end of the day thought, this is the point where I can not give you any further feedback if the approach is feasible or has more issues I didn't consider, we will have to wait for @DirectXMan12 to chime in.
But thanks a lot for pushing this forward, its really great to see some movement here :)
@lulf would this solve your issue? https://godoc.org/sigs.k8s.io/controller-runtime/pkg/manager#example-New--MultinamespaceCache I think that this is a large enough feature with enough gotchas that it might be nice to write down the design for the proposed changes and maybe another option so that we can compare? I would use the 2 ok's here as a starting point. |
@shawn-hurley What I need specifically is a way to use a global cache for some objects, and a specific namespace for other resources. The multi-namespace cache would not give me the ability to select which cache to use when creating a watch for a particular resource. That being said, I have attempted another approach to solve my use case, where I create a 'delegating cache', which delegates either to global or a default namespaced cache based on the object type : https://github.com/EnMasseProject/enmasse/blob/2db9469529254274c90117b1f6fad360b8081857/pkg/cache/delegate_cache.go So, I think I have a workaround for now. I could generalize the delegate cache and submit a PR for that if you think that would be interesting. |
That delegating cache starts to sound like the first option in the list of OK's to me. We would have to add more scenarios to cover because dynamic watches could change what is being watched during run time. We also would have to handle the case where 1 controller asks for a namespaced watch/cache BUT we already had that in the global lists. I think you would want to add a predicate for that at that time to do the correct filter for that watch. I think there are some other scenarios where we need to protect folks from scenarios where the behavior maybe not obvious. But it seems like it could be a good start! I second what @alvaroaleman said, thank you for driving this forward! Is there any way to add what that code does to a proposal that we can iterate on in words to make sure we can cover these different scenarios? |
I've been focusing our own needs for this functionality so far, as we had to investigate whether or not something like this could be done in controller-runtime and how much time it would take. With the delegate cache, we have a solution that allows us to simply implement the cache interface until a more generalized approach is available in controller-runtime, so I'm happy with that. However, I'd love to improve on that and make it into something that could be included in controller-runtime itself.
Is that best driven through #244 ? I can make a more general design document as a starting point, if desired. |
Closing this for now based on feedback, thanks! |
Another variant of #692 . Extend source.Kind with taking ListOptions, and pass these on to the informer map. In this PR, only namespace is used, but I think it could be extended to labels as well.
I don't know yet if this works, its just a prototype of an API that I as a user would like to have supported. Will add an integration test, but early feedback is welcomed.