-
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
set gvk while getting object using typed-client #2943
set gvk while getting object using typed-client #2943
Conversation
Signed-off-by: Hiranmoy Das Chowdhury <hiranmoy.das70@gmail.com>
Welcome @HiranmoyChowdhury! |
Hi @HiranmoyChowdhury. 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-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: HiranmoyChowdhury 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 |
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 is by design. The GVK fields can never be relied upon to be set in code, if you do for example an pod := &myPod{}
it won't be set. Use apiutil.GVKForObject
if you need to find the gvk for an object.
/hold |
@alvaroaleman yeah, we can do so. But, when we are calling an object using dynamic client we expect that it set this object with gvk or typemeta. Someone already fixed that issue for unstructured client and metadata client.But, this is currently missing in object when we are calling using typed-client. |
In the unstructured and objectmeta case it has to be set because there is no other way to derive it and all client operations on those will fail if it's unset. In the typed case it can be derived from the go types, which is why we deliberately make sure it is unset, so no one comes to the conclusion they can rely on it being set. |
@alvaroaleman Thanks for noticing. And this is true that we can derive GVK from structured object. But, I guess I have a little confusion on this topic. As unstructured client and metadata client and typed client is not exported. So, we can't call these from outside and we are using only one client for these. So, when we try to get unstructured object, we get the GVK. But, for structured object we missed GVK with the same client(from users perspective), this is a little confusion for newcomers like me. I had to find this by a lot of debugging. Also, there is a option to determine what the GVK is: obj.GetObjectKind().GroupVersionKind(). As there is a option I assumed this is fixed and set and we don't need to worry about this. I guess this should be set as expected. I am new in this field and have a lack amount of design sense and knowledge. I have to learn a lot to do so. I will be pleased if you can explain those things to me. |
That might or might not work. It will not work for example if you did a This behavior is by design, we did changes in the past to avoid setting it where it can be avoided so ppl don't think that they can rely on it being set: #2633 |
got this now. thanks for your time |
Signed-off-by: Hiranmoy Das Chowdhury hiranmoy.das70@gmail.com
While getting or creating or patching or updating object using typed-client which is a dynamic client in controller-runtime repository, gvk found empty for that object because of the codec convention. And this is the minimal coding change and might be the optimal solution I found.
Which issue(s) this PR fixes:
kubernetes/kubernetes#80609
kubernetes/kubernetes#3030
Note: the PR need to get merged first: kubernetes/kubernetes#127361
Then I will be able to update the deps.