vapor-ware / kubetest

Kubernetes integration testing in Python via pytest
https://kubetest.readthedocs.io/en/latest/
GNU General Public License v3.0
206 stars 57 forks source link

How to test CRD's #158

Open Frankkkkk opened 4 years ago

Frankkkkk commented 4 years ago

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

edaniszewski commented 4 years ago

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.

Frankkkkk commented 4 years ago

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,

Frankkkkk commented 4 years ago

FYI: I'm putting my work on hold for some weeks because of:

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.

bukowa commented 4 years ago

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
YiannisGkoufas commented 3 years ago

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!

Frankkkkk commented 3 years ago

FYI: I've created pykorm, which is a python ORM for kubernetes. It was originally meant for CRDs, but supports native objects too !

Cheers

YiannisGkoufas commented 3 years ago

Nice @Frankkkkk ! looks good! Do you have an example with kubetest as well?

Frankkkkk commented 3 years ago

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

YiannisGkoufas commented 3 years ago

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
Frankkkkk commented 3 years ago

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 :-)

eshepelyuk commented 3 years ago

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

guidoiaquinti commented 2 years ago

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 🙇

Frankkkkk commented 2 years ago

Hi @guidoiaquinti Nothing from my part on kubetest. We're principally using pykorm for CRD resources now. Cheers !

guidoiaquinti commented 2 years ago

Thank you for the prompt reply @Frankkkkk ! 🙇