-
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
fakeClient.List tries to populate UnstructuredList with objects of underlying type #1511
Comments
@wbrefvem I am a bit surprised this fails, we have testcases for this: controller-runtime/pkg/client/fake/client_test.go Lines 124 to 142 in 745c7c9
We don't do that, we serialize and deserialize: controller-runtime/pkg/client/fake/client.go Lines 333 to 338 in 745c7c9
|
Yes.
controller-runtime version: v0.9.0-beta.0 I'll try to be as brief as possible:
The test case is configured with a resource of this type already created. The expected behavior is that the call to
Running the test suite fails:
|
I should also add that the GVK is generated by decoding the request into |
Hello, I don't know if I do something wrong or if it's another issue, but I think we can easily reach this issue using the following example :
I also found that the tests seem not testing the case when tracked objects by the client are As far as I could go, the problem seems coming from this line : sigs.k8s.io/controller-runtime/pkg/client/fake/client.go#L332 and more precisely k8s.io/client-go/testing/fixture.go#L257.
@wbrefvem during your tests, do you create resources using I don't know if my thinking is correct or if I misunderstood something, but I think the issue could be really tricky to fix; because @alvaroaleman what do you think ? EDIT: fix my investigation |
There are, for example
If you can provide a fix together with a testcase that demonstonstrates the issue (i.E. doesn't pass right now) we'd be happy to take it. If you don't have a fix but a testcase, that might also help already. k8s.io/apimachinery is part of kubernetes/kubernetes btw, so if that needs changing, you'd need to propose a patch there. |
Test case for kubernetes-sigs#1511 tries to list objects created from unstructured.Unstructured type Signed-off-by: Alexandre Nicolaie dit Clairville <anicolaie@ippon.fr>
Thanks for your response.
Sorry, I misspoke; I wanted to talk about listing unstructured objects and not listing using unstructured objects. I can provide a testcase that could demonstrates the issue: master...xunleii:issues/1511-no-assign-or-convert-on-unstructured, but I don't know if this test is enough. About the fix, I will propose a patch for k8s.io/apimachinery, referencing this issue. I just want to check with you if it's a real issue or if I misuse the package. |
So what doesn't work is listing an object that is registered in the scheme after it was created through unstructured? If yes yeah, sounds like a bug (although it is slightly questionable why you are using |
Yep, that is it. I know, it is a bit weird to do that. I have this case for a testing library using human readable sentences (Gherkin in my case): in order to create/read/update/delete Kubernetes resources (like we do with API) in a generic way and with less code as possible, I use |
Similar issue encountered as @xunleii said. |
Its quite handy during unit tests to load a bunch of resources as |
#1662 should fix this |
If I have an UnstructuredList with a known GVK, passing it to
fakeClient.List
returns an error:Running in the debugger revealed that
fakeClient.List
passes the underlying type toclient-go
, which returns a list of the underlying type. So it makes sense that fake client would error when trying to populate theUnstructuredList
with objects it gets fromclient-go
.There should be some way for
fakeClient.List
to handleUnstructured*
objects. IIUC the real client delegates to an unstructured client. That seems heavy-handed here, but it may be the only way to avoid a bunch of spaghetti infakeClient.List
just to handleUnstructuredList
as a special case.This is related to #702 but is not the same issue.
The text was updated successfully, but these errors were encountered: