devopsspiral / KubeLibrary

Kubernetes library for Robot Framework
MIT License
138 stars 37 forks source link

Failed to list cronjobs #72

Closed triceras closed 3 years ago

triceras commented 3 years ago

HI All, I have posted this message as a comment but I think this will get a better exposure an issue is created to report this issue. I am unable to get all cron jobs in a namespace by calling the keyword Get Cron Jobs In Namespace. It seems that the Python function get_cron_jobs_in_namespace can not be looked up from the keywords file cronjob_kw.robot. Is there a way to make the function work?

robot -e prerelease .
==============================================================================
Cronjob
==============================================================================
Cronjob.Cronjob
==============================================================================
Job test case example                                                 | FAIL |
No keyword with name 'Get Cron Jobs In Namespace' found. Did you mean:
    KubeLibrary.Get Jobs In Namespace
------------------------------------------------------------------------------
Cronjob.Cronjob                                                       | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Cronjob                                                               | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
triceras commented 3 years ago

Since the function get_cron_jobs_in_namespace connects to the API BatchV2alpha1Api I went to check if the API endpoint was reachable from my script

def get_cron_jobs_in_namespace(self, namespace, label_selector=""):
        """Gets cron jobs in given namespace.

        Can be optionally filtered by label. e.g. label_selector=label_key=label_value

        Returns list of strings.

        - ``namespace``:
          Namespace to check
        """
        ret = self.batchv1_beta1.list_namespaced_cron_job(namespace, watch=False, label_selector=label_selector)
        return [item.metadata.name for item in ret.items]

After increasing the debug level on the framework I have found out that Python object client.BatchV1beta1Api representing the API failed to load by the main script KubeLibrary.py.

20210407 17:07:17.809 | INFO  | In library 'KubeLibrary': Adding keyword 'batchv1' failed: Not a method or function

Is there a way we could safely load the Python library and used within the script so we could list the K8s cronjobs ?

Nilsty commented 3 years ago

Hi @triceras For me it's working. Could you check what version of kubelibrary and what version of the python kubernetes client are you running? For me it's the following:

pip3 list | grep kube                                      
kubernetes                                       12.0.1              
robotframework-kubelibrary                       0.4.0 
triceras commented 3 years ago

Hi @Nilsty,

Thanks for looking into this issue. I checked the version of the pip packages you listed above and I saw that I was using version 0.3.0 of the package robotframework-kubelibrary

kubeconfig                 1.1.1
kubernetes                 12.0.1
kubetest                   0.9.4
robotframework-kubelibrary 0.3.0

After I upgraded the package robotframework-kubelibrary to its latest version 0.4.0 I was able to list the K8s cluster cronjobs.

robot -L debug -e prerelease .
==============================================================================
Cronjob
==============================================================================
Cronjob.Cronjob
==============================================================================
Job test case example                                                 

Cron Jobs in namespace runtime-service-broker:
runtime-service-broker-metadata-cron
Job test case example                                                 | PASS |
------------------------------------------------------------------------------
Cronjob.Cronjob                                                       | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Cronjob                                                               | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================

Thanks for looking into it. Rafael