]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
k8s: Fix #9935 name 'response' is not defined in get_pods()
authorAlain Spineux <alain@baculasystems.com>
Thu, 9 Mar 2023 13:57:14 +0000 (14:57 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:01 +0000 (13:57 +0200)
- the previous fix #9727 was buggy, I fixed get_pvcs() but
  broke the "weak" get_pods()
- the problem is that __execute() wrapper intercept exceptions
  and return and error dict() or the expected response when no
  exception are generated

bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/kubernetes_plugin.py

index e404cf4c82269dd7049d555c176c17d56fec8541..87b5b65651f8ace17c140e1e947fd563aa5d96d5 100644 (file)
@@ -335,14 +335,21 @@ class KubernetesPlugin(Plugin):
                                                                 self.config['labels']))
 
     def get_pods(self, namespace, estimate=False):
-        pods = self.__execute(lambda: pods_list_namespaced(self.corev1api, namespace, estimate, self.config['labels']))
-        if not isinstance(response, dict) or "error" not in response:
+        # the __execute() wrapper intercept exceptions and return and error dict()
+        # instead of the expected response
+        response = self.__execute(lambda: pods_list_namespaced(self.corev1api, namespace, estimate, self.config['labels']))
+        if not isinstance(response, dict) or not "error" in response:
+            pods = reponse
             nrpods = len(pods)
             logging.debug("get_pods[{}]:pods:{}".format(namespace, nrpods))
             self.pods_counter += nrpods
-        return pods
+            return pods
+        else:
+            return response # it is a dictionary with an error
 
     def get_pvcs(self, namespace, estimate=False):
+        # the __execute() wrapper intercept exceptions and return and error dict()
+        # instead of the expected response
         response = self.__execute(lambda: persistentvolumeclaims_list_namespaced(self.corev1api, namespace, estimate,
                                                                              self.config['labels']))
         if isinstance(response, tuple) and len(response) == 2: