-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
🌱 Add a design document to filter cache by selectors #1419
🌱 Add a design document to filter cache by selectors #1419
Conversation
Hi @qinqon. 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. |
@qinqon thanks for putting this up! Could you join the kubebuilder and controller-runtime biweekly meeting this Thursday 18 CET and show it briefly? |
@alvaroaleman sure, I will be there. |
@alvaroaleman do I have to add a bullet to the agenda or just rise a hand on the meeting ? |
@qinqon a bullet would be great |
Let me know if I have to pin someone else here, so we can discuss it. |
69c3cbf
to
e2bc322
Compare
force-push: Removed pkg/cache changes from this PR, converted map value to |
e2bc322
to
95dbc43
Compare
force-push: Added an additional proposal to pass the selector using the builder instead of manager.Options as implemented in #1425 |
95dbc43
to
abadf65
Compare
force-push: Removed proposal 2 and adapterd former proposal to use |
Does it make sense to include labels in this proposal ?, the interfaces to use labels are almost identicall to fields and we will be able to close the issue. UPDATE: Created a PoC adding labels too #1435 |
/hold |
designs/use-selectors-at-cache.md
Outdated
// SelectorsByObject associate a GroupResource to a field/label selector | ||
type SelectorsByGVK map[schema.GVK]Selector |
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.
Nit
// SelectorsByObject associate a GroupResource to a field/label selector | |
type SelectorsByGVK map[schema.GVK]Selector | |
// SelectorsByGVK associate a GroupVersionKind to a field/label selector | |
type SelectorsByGVK map[schema.GroupVersionKind]Selector |
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.
Done
... | ||
|
||
// SelectorsByObject associate a client.Object to a field/label selector | ||
type SelectorsByObject map[client.Object]Selector |
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.
This should be restricted to runtime.Object
so users don't get the idea that you can filter by object name/namespace via SetName()
and SetNamespace()
.
type SelectorsByObject map[client.Object]Selector | |
type SelectorsByObject map[runtime.Object]Selector |
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.
Done
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.
@estroz why? It is a map, the values can not access the keys. Making this runtime.Object
means we have to deal with stuff like ppl putting List types in there
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.
@alvaroaleman don't we have the same problem with client.Object since it's embedding runtime.Object ?
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.
@alvaroaleman it may be confusing to users to have all these object fields exposed by the metav1.Object
, since they may assume the key can actually apply its own selector values, ex. by SetName()
. Instead it would be better to constrain the contract to just GroupVersionKind()
.
There can be some internal validation step to make sure the object is not a list type.
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.
Using GVK is inconvenient. Using the smaller interface (runtime.Object) doesn't prevent ppl from putting in objects that fulfill a lager interface (client.Object). It does however keep them from putting something like List types in there and makes the compiler verify that rather than getting a runtime error. Also, I think the idea that ppl might think the map key has any further relevance for filtering when the value is a Selector
struct seems a bit far fetched to me.
We also have plenty of prior art where we use client.Object to only derive the type, e.G. in source.Kind or the clients delete method.
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.
You could similarly argue that someone would not try to map a selector to a list type because that's not the type they add to For()
, Owns()
, or Watches()
.
However since there is prior art I am fine with client.Object
. There can always be another selector map type added later for runtime.Object
without breakage if we see bugs filed because of confusion. It's not worth worrying about too much now.
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.
Going back to client.Object
as proposed originally.
designs/use-selectors-at-cache.md
Outdated
} | ||
|
||
// FillInListOpts fill in ListOptions LabelSelector and FieldSelector if needed | ||
func (s Selector) FillInListOpts(listOpts *metav1.ListOptions) { |
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.
How about
func (s Selector) FillInListOpts(listOpts *metav1.ListOptions) { | |
func (s Selector) ApplyToList(listOpts *client.ListOptions) { |
so it implements client.ListOption
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.
Since we are receiving metav1.ListOptions
at ListWatch functions I will keep the type so we don't have to do convertions, but changing the name to ApplyToList
feels good.
Mapper meta.RESTMapper | ||
Resync *time.Duration | ||
Namespace string | ||
SelectorsByObject SelectorsByObject |
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.
It would be nice to generalize this to something like
SelectorsByObject SelectorsByObject | |
Selectors SelectorSet |
Where SelectorSet
is any set of selectors that implements
type SelectorSet interface {
client.ListOption
Select()
}
where Select()
is just an identifier method so users don't pass in other client.ListOption
s.
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.
We apply options per GVK so it does not make sense to implement ListOption at the map level.
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.
Sure, get rid of client.ListOption
from that interface. Regardless, I may want to construct a GVK myself instead of using a typed object or Unstructured
, so why not also expose SelectorsByGVK
?
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.
As we have previously stated we are going to expose the map key as client.Object
, internally will be GVK, in fact at the implementation PR I will remove SelectorsByObject from internal and use it only as a type to pass to the cache Options, at Options parsing it will be converted to the SelectorsByGVK.
e9f3b9d
to
3c3313f
Compare
The controller-runtime is caching all the resource instance even if not all of them end up being reconciled, this design document describe a proposal to that problem by use selectors at the ListWatch informers mechanism. Signed-off-by: Quique Llorente <ellorent@redhat.com>
3c3313f
to
141ddd6
Compare
Before we merge this, can you confirm that we don't want to have something like |
What other options exist that we could filter by? Only the namespace or not? |
The other options are more dangerous than useful, so yes. |
Yeah, the namespace is a bit redundant as its also a global option. Generally, we can easily extend the Selector in the future in a backwards-compatible way if we see a reason, so I am not too concerned about missing something there. |
@estroz are you ok with the changes ? |
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, estroz, qinqon 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 |
/hold cancel |
/retest |
/retest I think we can override the job clearly is not related |
/test pull-controller-runtime-test-master |
/retest |
The controller-runtime is caching all the resource instance even if not
all of them end up being reconciled, this design document describe a
proposal to that problem by use selectors at the ListWatch informers
mechanism.
This is related to #1404