-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 field selector enabled fake client #800
✨add field selector enabled fake client #800
Conversation
Welcome @answer1991! |
Hi @answer1991. 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: answer1991 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 |
:sparkles:
add field selector enabled fake client
:sparkles:
add field selector enabled fake client
Not sure how to print the icon in title :-P |
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.
Thanks for picking this up!
I wrote a similarish issue a while ago: #657
Generally speaking I think it would be great if we extended the existing fakeClient and allowed to configure indexers on it, rather than adding a new constructor. WDYT?
var _ client.Client = &fieldSelectorEnableClient{} | ||
|
||
// NewFieldSelectorEnableClient wrapper a fake client that List method enables field selector | ||
func NewFieldSelectorEnableClient(client client.Client, scheme *runtime.Scheme, obj runtime.Object, field string, indexerFunc client.IndexerFunc) (client.Client, error) { |
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 means we can set up only one indexer, I think it would be better if ppl could set up any number
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.
No, we can set up multi indexes like that:
fakeClient := NewFakeClientWithScheme(scheme.Scheme)
fieldSelectorClient, err := NewFieldSelectorEnableClient(fakeClient, scheme.Scheme, &corev1.Pod{}, "spec.nodeName", func(o runtime.Object) []string {
po, ok := o.(*corev1.Pod)
if !ok {
return nil
}
return []string{po.Spec.NodeName}
})
fieldSelectorClient, err = NewFieldSelectorEnableClient(fieldSelectorClient, scheme.Scheme, &corev1.Node{}, "spec.podCIDR", func(o runtime.Object) []string {
no, ok := o.(*corev1.Node)
if !ok {
return nil
}
return []string{no.Spec.PodCIDR}
})
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.
I had already add multi indexer cases in test codes.
} | ||
|
||
if gvk, err := apiutil.GVKForObject(objs[0], f.scheme); err != nil { | ||
return nil |
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.
Why do we swallow this error?
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.
fixed, thanks!
bba3bdd
to
0b410af
Compare
Because of setting up indexer need lots of parameters, and indexer only required in only some cases or scenes. I think function |
0b410af
to
d7e5b8e
Compare
d7e5b8e
to
b5f85d2
Compare
+1 on extending the existing fake client somehow, rather than creating a separate one. We can probably find ways to make sure it's opt-in, and only needs to be configured when needed. |
Agreed, we shouldn't extend the signature. Possibilities to allow adding indexers without doing that include:
But: Lets give folks time over the next week to express an opinion or ideas before you end up changing it back and forth depending on what the last reviewer thought :) |
The func signature is same with the func my PR |
/ok-to-test |
If this is living within the fake package I think it's a neat way of achieving this without causing issues with interfaces etc elsewhere. My concern with the other suggestion is that if people declare their variables ahead of time as |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Having
with a super-interface should be backward compatible (apart from the function signature) |
/remove-lifecycle stale |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closed this PR. In response to this:
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. |
Real API Server client could set up indexer using
Manager
provided methodGetFieldIndexer
:And then we can list objects using field selector:
But fake client can not, this PR enable us wrapper fake client and got a field selector enable client.