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

Decoding should not clear apiVersion/kind #80609

Open
liggitt opened this issue Jul 25, 2019 · 17 comments · Fixed by kubernetes-sigs/cluster-api#4466
Open

Decoding should not clear apiVersion/kind #80609

liggitt opened this issue Jul 25, 2019 · 17 comments · Fixed by kubernetes-sigs/cluster-api#4466
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@liggitt
Copy link
Member

liggitt commented Jul 25, 2019

What would you like to be added:
When using a typed client, decoding to a versioned struct (not an internal API type), the apiVersion/kind information returned from the server should not be dropped.

Why is this needed:
The GroupVersionKind() method included in the ObjectKind interface is largely useless when dealing with arbitrary runtime.Object instances, since typed instances drop this information here:

// WithoutVersionDecoder clears the group version kind of a deserialized object.
type WithoutVersionDecoder struct {
Decoder
}
// Decode does not do conversion. It removes the gvk during deserialization.
func (d WithoutVersionDecoder) Decode(data []byte, defaults *schema.GroupVersionKind, into Object) (Object, *schema.GroupVersionKind, error) {
obj, gvk, err := d.Decoder.Decode(data, defaults, into)
if obj != nil {
kind := obj.GetObjectKind()
// clearing the gvk is just a convention of a codec
kind.SetGroupVersionKind(schema.GroupVersionKind{})
}
return obj, gvk, err
}

This is the decoder used when a client requests a decoder that does not do conversion:

// WithoutConversion returns a NegotiatedSerializer that performs no conversion, even if the
// caller requests it.
func (f CodecFactory) WithoutConversion() runtime.NegotiatedSerializer {
return WithoutConversionCodecFactory{f}
}

I could see clearing group/version/kind information when converting to an internal version, but I don't see the benefit of stripping it on decode if we're only dealing with a versioned struct.

/sig api-machinery
/cc @smarterclayton

Note that #3030 still needs to be resolved before apiVersion/kind could be depended on for individual objects for all API responses, but this would at least solve the issue with an update of an object clearing the apiVersion/kind in an update response (xref kubernetes-sigs/controller-runtime#526)

@liggitt liggitt added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 25, 2019
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jul 25, 2019
@YoubingLi
Copy link

If the apiVersion is not specified, GroupVersoinKind can be dropped when decoding the data.

Anyway, I will dig more about related issues before filing a PR.

@liggitt liggitt self-assigned this Jul 26, 2019
@liggitt
Copy link
Member Author

liggitt commented Jul 26, 2019

I think dropping WithoutVersionDecoder might be sufficient to accomplish this. I am looking into fixing #3030 in conversion, and adding tests to ensure conversion populates the apiVersion/kind appropriately

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 24, 2019
@liggitt liggitt added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Nov 14, 2019
@povsister
Copy link
Contributor

Is there a real million stone for this issue? I see you moved this from v1.19 to v1.20

Although typed resource is already known to user, it's a bit weird to explicitly remove the GVK from de-serialized struct.
The explicit behavior sometimes makes things harder, eg: Printing struct Kind and version, without filled TypeMeta, I need reflect package to do so. Any comments or suggestion?

@matteoolivi
Copy link

matteoolivi commented Mar 21, 2021

@liggitt what's the status of this (or #80618)? Is there any concrete plan to move it forward?

@liggitt liggitt removed their assignment Mar 23, 2021
@liggitt liggitt added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Mar 23, 2021
@liggitt
Copy link
Member Author

liggitt commented Mar 23, 2021

It's not on my list of items to push on for 1.22. If someone wanted to pick up #80618 (or an alternate approach) and resolve the items I identified, that would be excellent.

@alvaroaleman
Copy link
Member

/reopen

I doubt a PR to cluster-api fixed this

@k8s-ci-robot k8s-ci-robot reopened this Apr 13, 2021
@k8s-ci-robot
Copy link
Contributor

@cici37: Closing this issue.

In response to this:

Closing due to age and inactivity. Please reopen if it's still a problem on the latest supported version.

/close

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.

@liggitt liggitt reopened this Feb 28, 2023
@liggitt
Copy link
Member Author

liggitt commented Feb 28, 2023

it is still an issue on the latest version :)

@cici37
Copy link
Contributor

cici37 commented Mar 9, 2023

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 9, 2023
ack-prow bot pushed a commit to aws-controllers-k8s/runtime that referenced this issue Mar 22, 2023
Description of changes:
Some version of K8s do not reliably return `TypeMeta` information when you call `apiReader.Get()` (see kubernetes/kubernetes#3030 and kubernetes/kubernetes#80609). This is a [known bug](kubernetes-sigs/controller-runtime#1517) in `controller-runtime` that they don't plan on fixing. 

Parts of the code, namely around setting up the user agent, currently rely on these fields - and they are currently being given an empty struct (with empty strings for all values). To work around this bug, this PR has introduced a new `GroupVersionKind()` getter in the `ResourceDescriptor` (replacing the existing `GroupKind`), which returns a static description of the GVK. Then, rather than referencing the `RuntimeObject` `TypeMeta` properties, we can reference this new GVK getter anywhere in the runtime. It also replaces any existing use of `GroupKind` to now use `GroupVersionKind`.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
@camilamacedo86
Copy link

camilamacedo86 commented May 8, 2023

HI folks, this issue makes it not possible properly test the controllers. Any idea when it would be fixed? Could we try to add some labels as a priority or add them in the next milestone?

@BenTheElder
Copy link
Member

We can add priority/milestone labels but they only indicate intended priority/milestone, if nobody is signing up to fix this issue adding the label/milestone won't do anything and the milestone would be misleading.

With ~2k issues in this repo alone, it's hard to get to everything. This one is marked "help wanted" so I think the SIG Owners are looking for someone to pitch in #80609 (comment)

@caozhuozi
Copy link

/reopen

@YoniRomm
Copy link

YoniRomm commented Dec 5, 2023

Is there any progress on this issue?

dilyar85 added a commit to vmware-tanzu/vm-operator that referenced this issue Feb 3, 2024
This patch adds GVK into the bootstrap secret resources during backup, so that they can be recreated successfully during the restore.
It appears that the Decoder used for getting K8s core resources clears the GVK info (see kubernetes/kubernetes#80609 for more details).

- CloudInit with inlined secret data
```
$ govc vm.info -e "test-ubuntu-impish-inlined-cloud-config" | grep "vmservice.virtualmachine.additional.resources.yaml" | awk '{print $2}' | base64 -d | gunzip
apiVersion: v1
kind: Secret
...
```
- Sysprep with inlined secret data 
```
$ govc vm.info -e "test-windows-inlined-sysprep" | grep "vmservice.virtualmachine.additional.resources.yaml" | awk '{print $2}' | base64 -d | gunzip
apiVersion: v1
kind: Secret
...
fabianburth added a commit to openfluxcd/artifact that referenced this issue Aug 6, 2024
Since decoding clears the apiversion and kind information (kubernetes/kubernetes#80609), the index does not work consistently.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet