Skip to content
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

Closed

Conversation

HiranmoyChowdhury
Copy link

@HiranmoyChowdhury HiranmoyChowdhury commented Sep 14, 2024

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.

Signed-off-by: Hiranmoy Das Chowdhury <hiranmoy.das70@gmail.com>
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 14, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @HiranmoyChowdhury!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: HiranmoyChowdhury
Once this PR has been reviewed and has the lgtm label, please assign fillzpp for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Sep 14, 2024
Copy link
Member

@alvaroaleman alvaroaleman left a 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.

@alvaroaleman
Copy link
Member

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 15, 2024
@HiranmoyChowdhury
Copy link
Author

@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.

@alvaroaleman
Copy link
Member

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.

@HiranmoyChowdhury
Copy link
Author

HiranmoyChowdhury commented Sep 16, 2024

@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.
Also, while using structured object, if I use "apiutil.GVKForObject" this increase coding cost I guess and if you see this PR solution which takes a lesser amount of cost and also a time saving effort.
you can have a look on this also: kubernetes/kubernetes#3030

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.

@alvaroaleman
Copy link
Member

alvaroaleman commented Sep 16, 2024

Also, there is a option to determine what the GVK is: obj.GetObjectKind().GroupVersionKind()

That might or might not work. It will not work for example if you did a pod := &corev1.MyPod{}. Always use apiutil.GVKForObject if you need to get the gvk for an object, regardless of unstructured/objectmeta/typed.

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

@HiranmoyChowdhury
Copy link
Author

got this now. thanks for your time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants