client-go icon indicating copy to clipboard operation
client-go copied to clipboard

object return by client-go informer don't have api Kind info

Open wangweihong opened this issue 6 years ago • 33 comments

When I use informer to watch cluster resource infos, I find runtime.Object return by informer don't include object Kind info. fmt.Println(obj.GetObjectKind().GetVersionKind().String()) print /, Kind=

wangweihong avatar Oct 10 '17 03:10 wangweihong

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.

Prevent issues from auto-closing with an /lifecycle frozen comment.

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

fejta-bot avatar Jan 08 '18 04:01 fejta-bot

/remove-lifecycle stale

krmayankk avatar Jan 12 '18 07:01 krmayankk

@smarterclayton i am also seeing this issue. If you know how to fix it ,i would like to take a stab at it

krmayankk avatar Jan 12 '18 07:01 krmayankk

/assign @krmayankk

krmayankk avatar Jan 12 '18 07:01 krmayankk

I don't think the Kind is returned either with List

thomastaylor312 avatar Feb 05 '18 22:02 thomastaylor312

The k8s REST API does not provide the Kind value. kubectl (or one of its dependencies) inserts the Kind information. Perhaps the code that figures the Kind info can be moved to client-go? Just for example, see get cmd and how it inserts the List value.

bostrt avatar Feb 09 '18 16:02 bostrt

This occurs because the gvk is cleared during decoding: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go#L256.

This is intentional. See https://github.com/kubernetes/kubernetes/pull/59264#issuecomment-362575608 for more details.

nikhita avatar Apr 03 '18 08:04 nikhita

Reported in kubernetes/kubernetes#3030

Fix in progress in kubernetes/kubernetes#63972

nikhita avatar Jun 24 '18 16:06 nikhita

Thank you for the update @nikhita!

thomastaylor312 avatar Jun 25 '18 22:06 thomastaylor312

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

fejta-bot avatar Sep 23 '18 23:09 fejta-bot

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

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 rotten

fejta-bot avatar Oct 23 '18 23:10 fejta-bot

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen. Mark the issue as fresh with /remove-lifecycle rotten.

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

fejta-bot avatar Nov 23 '18 00:11 fejta-bot

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen. Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /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.

k8s-ci-robot avatar Nov 23 '18 00:11 k8s-ci-robot

/reopen

aermakov-zalando avatar May 20 '19 13:05 aermakov-zalando

@aermakov-zalando: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen

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.

k8s-ci-robot avatar May 20 '19 13:05 k8s-ci-robot

For those of us still looking for a concise way to add TypeMeta information to runtime objects, here you go!

// addTypeInformationToObject adds TypeMeta information to a runtime.Object based upon the loaded scheme.Scheme
// inspired by: https://github.com/kubernetes/cli-runtime/blob/v0.19.2/pkg/printers/typesetter.go#L41
func addTypeInformationToObject(obj runtime.Object) error {
    gvks, _, err := scheme.Scheme.ObjectKinds(obj)
    if err != nil {
        return fmt.Errorf("missing apiVersion or kind and cannot assign it; %w", err)
    }

    for _, gvk := range gvks {
        if len(gvk.Kind) == 0 {
            continue
        }
        if len(gvk.Version) == 0 || gvk.Version == runtime.APIVersionInternal {
            continue
        }
        obj.GetObjectKind().SetGroupVersionKind(gvk)
        break
    }

    return nil
}

hjkatz avatar Sep 28 '20 15:09 hjkatz

/reopen

szuecs avatar Jul 28 '22 14:07 szuecs

@szuecs: Reopened this issue.

In response to this:

/reopen

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.

k8s-ci-robot avatar Jul 28 '22 14:07 k8s-ci-robot

Example what everyone needs to do in order to use owner reference with informers and client-go https://github.com/zalando-incubator/stackset-controller/blob/ec093f68f18c7c21ae03e44a14666fc6e8d4a5d3/controller/stackset.go#L1084-L1096

szuecs avatar Jul 28 '22 14:07 szuecs

/remove-lifecycle rotten

szuecs avatar Aug 01 '22 17:08 szuecs

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

This bot triages issues and PRs 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 or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

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

/lifecycle stale

k8s-triage-robot avatar Oct 30 '22 17:10 k8s-triage-robot

/remove-lifecycle stale

szuecs avatar Nov 02 '22 18:11 szuecs

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

This bot triages issues and PRs 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 or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

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

/lifecycle stale

k8s-triage-robot avatar Jan 31 '23 19:01 k8s-triage-robot

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-triage-robot avatar Mar 02 '23 19:03 k8s-triage-robot

/remove-lifecycle rotten

szuecs avatar Mar 02 '23 19:03 szuecs

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-triage-robot avatar May 31 '23 21:05 k8s-triage-robot

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-triage-robot avatar Jun 30 '23 21:06 k8s-triage-robot

/remove-lifecycle rotten

szuecs avatar Jul 01 '23 06:07 szuecs

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-triage-robot avatar Jan 23 '24 15:01 k8s-triage-robot

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-triage-robot avatar Feb 22 '24 15:02 k8s-triage-robot