kubetest icon indicating copy to clipboard operation
kubetest copied to clipboard

How to test CRD's

Open Frankkkkk opened this issue 4 years ago • 14 comments

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

Frankkkkk avatar Dec 23 '19 13:12 Frankkkkk

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.

edaniszewski avatar Dec 26 '19 17:12 edaniszewski

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 avatar Dec 27 '19 17:12 Frankkkkk

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.

Frankkkkk avatar Jan 10 '20 14:01 Frankkkkk

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

bukowa avatar Jan 19 '20 18:01 bukowa

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!

YiannisGkoufas avatar Jan 18 '21 17:01 YiannisGkoufas

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

Cheers

Frankkkkk avatar Jan 19 '21 08:01 Frankkkkk

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

YiannisGkoufas avatar Jan 19 '21 08:01 YiannisGkoufas

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

Frankkkkk avatar Jan 19 '21 14:01 Frankkkkk

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

YiannisGkoufas avatar Jan 19 '21 15:01 YiannisGkoufas

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

Frankkkkk avatar Jan 19 '21 15:01 Frankkkkk

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

eshepelyuk avatar Jun 18 '21 12:06 eshepelyuk

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 🙇

guidoiaquinti avatar Dec 10 '21 13:12 guidoiaquinti

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

Frankkkkk avatar Dec 10 '21 14:12 Frankkkkk

Thank you for the prompt reply @Frankkkkk ! 🙇

guidoiaquinti avatar Dec 10 '21 15:12 guidoiaquinti