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

TypeMeta is empty on .List() resources #1328

Closed
gprossliner opened this issue Jan 15, 2024 · 10 comments
Closed

TypeMeta is empty on .List() resources #1328

gprossliner opened this issue Jan 15, 2024 · 10 comments
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. triage/duplicate Indicates an issue is a duplicate of other open issue.

Comments

@gprossliner
Copy link

This is basically a reopen from #541 because I did not see why @shsjshentao closed this in the first place.

After listing / getting resources with client-go (tested with Deployments, StatefulSets and DaemonSets), obj.TypeMeta is empty. The fields Kind and ApiVersion are empty strings.

After the REST call and JSON deserialisation the data is still available, but is is explicitly cleared:

https://github.com/kubernetes/apimachinery/blob/02a41040d88da08de6765573ae2b1a51f424e1ca/pkg/runtime/helper.go#L255C8-L263

// 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
}

Is there any specific reason while this is necessary? This is valuable information that I need later to set OwnerReferences and for logging. I tried with git blame to check for the commit / PR this was introduced, but there was no information.

@dprotaso
Copy link
Contributor

dprotaso commented Feb 1, 2024

Does the API server return the type meta for list entries?

@gprossliner
Copy link
Author

Yes. It is returned, but reset by client-go. After fetching from the server all information is present, but the func (d WithoutVersionDecoder) Decode func (see posting) clear that information.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/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 May 6, 2024
petr-muller added a commit to petr-muller/oc that referenced this issue May 18, 2024
Previous code used `GroupVersionKind` method on actual resources to determine group/kind strings for them, but client-go unfortunately drops `TypeMeta` on resources processed by typed client (kubernetes/client-go#1328, kubernetes/client-go#541). Fortunately we know what types we build insights for, so we can use appropriate strings from client code for groups and hardcode kinds ourselves.
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/oc that referenced this issue Jun 4, 2024
Previous code used `GroupVersionKind` method on actual resources to determine group/kind strings for them, but client-go unfortunately drops `TypeMeta` on resources processed by typed client (kubernetes/client-go#1328, kubernetes/client-go#541). Fortunately we know what types we build insights for, so we can use appropriate strings from client code for groups and hardcode kinds ourselves.
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 5, 2024
@petr-muller
Copy link
Member

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Jun 6, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/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 Sep 4, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 4, 2024
@dprotaso
Copy link
Contributor

dprotaso commented Oct 7, 2024

/lifecycle frozen

Should this issue be in k/k repo?

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Oct 7, 2024
@liggitt
Copy link
Member

liggitt commented Oct 7, 2024

I think this is a duplicate of kubernetes/kubernetes#3030 and kubernetes/kubernetes#80609

@liggitt liggitt added the triage/duplicate Indicates an issue is a duplicate of other open issue. label Oct 7, 2024
@liggitt liggitt closed this as completed Oct 7, 2024
@liggitt
Copy link
Member

liggitt commented Oct 7, 2024

closing as a duplicate, see the two existing k/k issues (one tracking how now all server responses include apiVersion / kind data on individual items in lists, the other tracking how the client decoding methods clear those fields when they are populated in the server as part of decoding into typed go structs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. triage/duplicate Indicates an issue is a duplicate of other open issue.
Projects
None yet
Development

No branches or pull requests

6 participants