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

Add a test for custom object operations #930

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ def conditions(self, conditions):
:param conditions: The conditions of this V1beta1CustomResourceDefinitionStatus.
:type: list[V1beta1CustomResourceDefinitionCondition]
"""
if conditions is None:
raise ValueError("Invalid value for `conditions`, must not be `None`")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is generated, and will be overwritten in next release, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the proper fix will come in 1.16 kubernetes/kubernetes#64996

somehow in the test, the response is deserialized into a dict instead of a CRD object, which causes the attribute assertion to fail. Perhaps this workaround isn't ideal either. I will abandon this pull and verify the CR patch methods manually in the next couple of releases

/close


self._conditions = conditions

Expand Down
64 changes: 64 additions & 0 deletions kubernetes/e2e_test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

from kubernetes.client import api_client
from kubernetes.client.apis import core_v1_api
from kubernetes.client.apis import apiextensions_v1beta1_api
from kubernetes.client.apis import custom_objects_api
from kubernetes.e2e_test import base
from kubernetes.stream import stream
from kubernetes.stream.ws_client import ERROR_CHANNEL
Expand Down Expand Up @@ -234,3 +236,65 @@ def test_node_apis(self):
node = api.read_node(name=item.metadata.name)
self.assertTrue(len(node.metadata.labels) > 0)
self.assertTrue(isinstance(node.metadata.labels, dict))

def test_custom_objects_apis(self):
"""
It should be able to create and patch a namespaced custom object.
"""
client = api_client.ApiClient(configuration=self.config)
crd_api = apiextensions_v1beta1_api.ApiextensionsV1beta1Api(client)
cr_api = custom_objects_api.CustomObjectsApi(client)

# create a CRD that defines a namespace-scoped custom resource Foo
# TODO: The test objects in this test file are unstructured. Verify
# if it makes more sense to switch to typed objects defined under
# kubernetes.client.models
group_prefix = 'test-crd-' + short_uuid()
group = group_prefix + '.test.e2e.com'
api_version = group + '/v1'
name = 'foos.' + group
test_crd = {
'kind': 'CustomResourceDefinition',
'apiVersion': 'apiextensions.k8s.io/v1beta1',
'metadata': {
'name': name,
},
'spec': {
'group': group,
'versions': [{
'name': 'v1',
'served': True,
'storage': True
}],
'names': {
'kind': 'Foo',
'plural': 'foos'
},
'scope': 'Namespaced'
}
}
resp = crd_api.create_custom_resource_definition(body=test_crd)
self.assertEqual(name, resp.metadata.name)
print('E2E test CRD created')

# wait for the CRD to be ready
time.sleep(5)

# create a custom object
name = 'test-foo-' + short_uuid()
resp = cr_api.create_namespaced_custom_object(group=group,
version='v1',
plural='foos',
namespace='default',
body={'kind':'Foo', 'apiVersion':api_version, 'metadata':{'name':name}})
self.assertEqual(name, resp.metadata.name)
print('E2E test CR created')

# perform an emtpy JSON merge patch on the custom object
resp = cr_api.patch_namespaced_custom_object(group=group,
version='v1',
plural='foos',
namespace='default',
name=name,
body={})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to check the resp? does it succeed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added .metadata.name check to make sure that the response is a CRD, not a metav1.Status

also added a commit to make the CRD deserializer usable before we fix the upstream openapi spec: kubernetes/kubernetes#64996

self.assertEqual(name, resp.metadata.name)