Skip to content

Conversation

@chancez
Copy link
Contributor

@chancez chancez commented May 23, 2019

When the Kubernetes REST API returns a list of objects, it returns a
resource list object with an apiVersion and kind set to "KindList" where
"Kind" is the Kind of object queried, rather than an simple array of
objects.

The items property contains the array of resources returned. Each
resource in this list does not contain the GVK information, only the
resource list has an apiVersion or kind property set.

This ensures when a resource list is returned, each resource within the
list has it's apiVersion and kind set, to make it similar to other
Kubernetes clients, and easier to work with the returned resources.

My primary reason for contributing this is because in the k8s_facts module in
Ansible pulls the items out of a resource list
(https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/k8s/common.py#L211-L212), but each item in a resource
list doesn't have the apiVersion/kind information, only the list object itself
does, so you can't inspect the
kind of the objects returned, which is problematic.

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 23, 2019
When the Kubernetes REST API returns a list of objects, it returns a
resource list object with an apiVersion and kind set to "KindList" where
"Kind" is the Kind of object queried, rather than an simple array of
objects.

The `items` property contains the array of resources returned.  Each
resource in this list does not contain the GVK information, only the
resource list has an apiVersion or kind property set.

This ensures when a resource list is returned, each resource within the
list has it's apiVersion and kind set, to make it similar to other
Kubernetes clients, and easier to work with the returned resources.
@chancez chancez force-pushed the fix_missing_item_kind branch from 37d9ed5 to 17dd847 Compare May 23, 2019 18:33
@fabianvf
Copy link
Member

/cherrypick release-0.9

@openshift-cherrypick-robot

@fabianvf: once the present PR merges, I will cherry-pick it on top of release-0.9 in a new PR and assign it to you.

In response to this:

/cherrypick release-0.9

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.

@fabianvf
Copy link
Member

/cherrypick release-0.8

@openshift-cherrypick-robot

@fabianvf: once the present PR merges, I will cherry-pick it on top of release-0.8 in a new PR and assign it to you.

In response to this:

/cherrypick release-0.8

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.

@openshift-cherrypick-robot

@fabianvf: new pull request created: #301

In response to this:

/cherrypick release-0.9

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.

@openshift-cherrypick-robot

@fabianvf: #298 failed to apply on top of branch "release-0.8":

Applying: Just do one big serialization at the end of a ResourceList operation
error: Failed to merge in the changes.
Using index info to reconstruct a base tree...
M	openshift/dynamic/client.py
Falling back to patching base and 3-way merge...
Auto-merging openshift/dynamic/client.py
CONFLICT (content): Merge conflict in openshift/dynamic/client.py
Patch failed at 0002 Just do one big serialization at the end of a ResourceList operation

In response to this:

/cherrypick release-0.8

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.

fabianvf pushed a commit to fabianvf/openshift-restclient-python that referenced this pull request May 28, 2019
…penshift#298)

* Always set apiVersion and kind for resources within a resource list

When the Kubernetes REST API returns a list of objects, it returns a
resource list object with an apiVersion and kind set to "KindList" where
"Kind" is the Kind of object queried, rather than an simple array of
objects.

The `items` property contains the array of resources returned.  Each
resource in this list does not contain the GVK information, only the
resource list has an apiVersion or kind property set.

This ensures when a resource list is returned, each resource within the
list has it's apiVersion and kind set, to make it similar to other
Kubernetes clients, and easier to work with the returned resources.

* Just do one big serialization at the end of a ResourceList operation

(cherry picked from commit 68cc0e3)
fabianvf added a commit that referenced this pull request May 28, 2019
…298) (#302)

* Always set apiVersion and kind for resources within a resource list

When the Kubernetes REST API returns a list of objects, it returns a
resource list object with an apiVersion and kind set to "KindList" where
"Kind" is the Kind of object queried, rather than an simple array of
objects.

The `items` property contains the array of resources returned.  Each
resource in this list does not contain the GVK information, only the
resource list has an apiVersion or kind property set.

This ensures when a resource list is returned, each resource within the
list has it's apiVersion and kind set, to make it similar to other
Kubernetes clients, and easier to work with the returned resources.

* Just do one big serialization at the end of a ResourceList operation

(cherry picked from commit 68cc0e3)
chancez pushed a commit to chancez/operator-metering that referenced this pull request Jun 6, 2019
Includes a fix from openshift/openshift-restclient-python#298
which ensures resources returned in a list have GVK information
populated.
willthames pushed a commit to willthames/openshift-restclient-python that referenced this pull request Nov 22, 2019
…penshift#298)

* Always set apiVersion and kind for resources within a resource list

When the Kubernetes REST API returns a list of objects, it returns a
resource list object with an apiVersion and kind set to "KindList" where
"Kind" is the Kind of object queried, rather than an simple array of
objects.

The `items` property contains the array of resources returned.  Each
resource in this list does not contain the GVK information, only the
resource list has an apiVersion or kind property set.

This ensures when a resource list is returned, each resource within the
list has it's apiVersion and kind set, to make it similar to other
Kubernetes clients, and easier to work with the returned resources.

* Just do one big serialization at the end of a ResourceList operation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants