kubetest
kubetest copied to clipboard
How to test CRD's
Hi, First of all, thanks for your library, it's great !
We'd like to tests our custom CRDs + Custom Resources with kubetest.
When created our custom resources automatically create some services, pods, etc. These can be tested with kubetest methods, but how can we test the existence/metadata of these custom resources themselves ?
I'd be willing to create some more definitions (i.e. objects/customresources.py and objects/customresourcedefinition.py), but do you think that it would be the right choice ?
Thanks, Cheers
Hi, thanks for the question and for using the library! The idea of adding support for CRDs + Custom Resources sounds great to me. I haven't personally dealt with CRDs very much, but from my knowledge of them and a quick reading on the CRD docs, I think having additional definitions like you mentioned (object/customresources, ...) makes sense.
If you want to work on support for this, or get that work started, that would be awesome! I could eventually work on adding support for it as well, but it may take a little while to get started on it.
Hi, It's "good" to see that nobody's working on it for now. I'll probably start implementing these features in January as we'll need them ;-) I'll ping you once that I have a working POC. Cheers,
FYI: I'm putting my work on hold for some weeks because of:
- https://github.com/kubernetes-client/python/issues/740#issuecomment-572653530
It's already implemented on python openshift's API https://github.com/openshift/openshift-restclient-python and with some hope should be soon implemented in kubernetes' API.
Couldn't we auto generate ApiObjects from kubernetes library? All of this looks very generic. Maybe ApiObjects can be made more generic also.
def load_configmap(self, path, set_namespace=True):
"""Load a manifest YAML into a ConfigMap object.
By default, this will augment the ConfigMap object with
the generated test case namespace. This behavior can be
disabled with the ``set_namespace`` flag.
Args:
path (str): The path to the ConfigMap manifest.
set_namespace (bool): Enable/disable the automatic
augmentation of the ConfigMap namespace.
Returns:
objects.ConfigMap: The ConfigMap for the specified manifest.
"""
log.info('loading configmap from path: %s', path)
configmap = objects.ConfigMap.load(path)
if set_namespace:
configmap.namespace = self.namespace
return configmap
def load_deployment(self, path, set_namespace=True):
"""Load a manifest YAML into a Deployment object.
By default, this will augment the Deployment object with
the generated test case namespace. This behavior can be
disabled with the ``set_namespace`` flag.
Args:
path (str): The path to the Deployment manifest.
set_namespace (bool): Enable/disable the automatic
augmentation of the Deployment namespace.
Returns:
objects.Deployment: The Deployment for the specified manifest.
"""
log.info('loading deployment from path: %s', path)
deployment = objects.Deployment.load(path)
if set_namespace:
deployment.namespace = self.namespace
return deployment
Would it be possible instead to retrieve the kubernetes client.ApiClient ? So then we would at least create/delete CRDs like it's described here: https://github.com/kubernetes-client/python/issues/740
Thanks!
FYI: I've created pykorm, which is a python ORM for kubernetes. It was originally meant for CRDs, but supports native objects too !
Cheers
Nice @Frankkkkk ! looks good! Do you have an example with kubetest as well?
There's an example from pykorm's tests: https://github.com/Frankkkkk/pykorm/blob/master/tests/test_filter.py#L4
It's not fully integrated yet into kubetest, sadly. I should propose a MR someday but sadly my priorities aren't these for the moment..
Will definitely give it a shot! How can I install it though? pip install pykorm
fails with:
ERROR: Could not find a version that satisfies the requirement pykorm
ERROR: No matching distribution found for pykorm
Maybe you're using python <= 3.6 (pykorm is python >= 3.7) ? Don't hesitate to open an issue there so we can't track the bug :-)
Hello, is there any improvements on this issue, except the link from above ? https://github.com/Frankkkkk/pykorm/blob/master/tests/test_filter.py#L4
Hello, is there any improvements on this issue, except the link from above ?
Bump on this. @Frankkkkk can you provide an update on this when you have some time? I can also try to tackle this once I know the status 🙇
Hi @guidoiaquinti Nothing from my part on kubetest. We're principally using pykorm for CRD resources now. Cheers !
Thank you for the prompt reply @Frankkkkk ! 🙇