Skip to content

results of list API calls have no kind or apiversion set for items #745

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

Closed
juliantaylor opened this issue Feb 1, 2019 · 6 comments
Closed
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@juliantaylor
Copy link
Contributor

juliantaylor commented Feb 1, 2019

list calls do not set the kind of api version of the items:

# works
In [14]: client.list_service_for_all_namespaces().kind
Out[14]: 'ServiceList'

# works
In [18]: client.read_namespaced_service(namespace=namespace, name=name).kind
Out[18]: 'Service'

# wrong
In [16]: type(client.list_service_for_all_namespaces().items[0].kind)
Out[16]: NoneType

I suspect this might be caused by #744 but I am not sure how the de-serialization exactly works.

@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 May 2, 2019
@fejta-bot
Copy link

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

@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 1, 2019
@fejta-bot
Copy link

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

@k8s-ci-robot
Copy link
Contributor

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

@cben
Copy link

cben commented Feb 2, 2020

To add to the observation on #819 (comment) that list kind might not always be item's kind + "List":

Indeed, CRDs have separate field ListKind:

$ kubectl explain crd.spec.names
KIND:     CustomResourceDefinition
VERSION:  apiextensions.k8s.io/v1beta1
...
   kind	<string> -required-
     Kind is the serialized kind of the resource. It is normally CamelCase and
     singular.

   listKind	<string>
     ListKind is the serialized kind of the list for this resource. Defaults to
     <kind>List.
...

It's optional, and I don't know why anyone should want to override it. The CRDs I've see that do set it all followed the "FooList" convention, but there are probably some out there that deviate from it?


In theory, the relation between item kind and list kind can be extracted from swagger.json / openapi.json, following $ref links for the type of items property, mapping both through "x-kubernetes-group-version-kind":

...
    "io.k8s.api.core.v1.Pod": {
      "description": "Pod is a collection of containers that can run on a host. This resource is created by clients and scheduled onto hosts.",
...
      "x-kubernetes-group-version-kind": [
        {
          "group": "",
          "kind": "Pod",
          "version": "v1"
        }
      ]
    },
...
    "io.k8s.api.core.v1.PodList": {
      "description": "PodList is a list of Pods.",
...
      "properties": {
...
        "items": {
          "description": "List of pods. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md",
          "type": "array",
          "items": {
            "$ref": "#/definitions/io.k8s.api.core.v1.Pod"
          }
        },
...
      "x-kubernetes-group-version-kind": [
        {
          "group": "",
          "kind": "PodList",
          "version": "v1"
        }
      ]
    },

IIUC the openapi is autogenerated, so I hard to say how reliable this inference would be into the future, but same structure is present in oldest and newest samples I have at hand:
https://cben.github.io/kubernetes-discovery-samples/kubernetes-v1.7.0/swagger.json and https://cben.github.io/kubernetes-discovery-samples/kubernetes-v1.15.0/openapi/v2/index.json 🤷

@cben
Copy link

cben commented Feb 2, 2020

Personally I don't feel implementing this openapi inference is worth the trouble.

However, it's interesting that kubectl get -o json foos does hide this API ugliness from users: all lists print out kind: List at top level, and it inserts correct kind and apiVersion into each element under items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants