]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
k8s: Fix #9727 NoneType object is not subscriptable
authorAlain Spineux <alain@baculasystems.com>
Thu, 8 Dec 2022 09:31:17 +0000 (10:31 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:00 +0000 (13:57 +0200)
- the code for get_pvcs() has changed and expect a tuple instead
  of a dictionary
- also change get_pods() that don't handle error correctly
- the upstream code can handle a missing self.k8s['pvcs']
  and will handle better pvcs_counter=0 and pods_counter=0 than
  with an invalid value

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

index 1c52ec6df0d676600159a7cc9cd54a41e35aa13e..e404cf4c82269dd7049d555c176c17d56fec8541 100644 (file)
@@ -336,20 +336,25 @@ class KubernetesPlugin(Plugin):
 
     def get_pods(self, namespace, estimate=False):
         pods = self.__execute(lambda: pods_list_namespaced(self.corev1api, namespace, estimate, self.config['labels']))
-        nrpods = len(pods)
-        logging.debug("get_pods[{}]:pods:{}".format(namespace, nrpods))
-        self.pods_counter += nrpods
+        if not isinstance(response, dict) or "error" not in response:
+            nrpods = len(pods)
+            logging.debug("get_pods[{}]:pods:{}".format(namespace, nrpods))
+            self.pods_counter += nrpods
         return pods
 
     def get_pvcs(self, namespace, estimate=False):
-        pvcs, totalsize = self.__execute(lambda: persistentvolumeclaims_list_namespaced(self.corev1api, namespace, estimate,
+        response = self.__execute(lambda: persistentvolumeclaims_list_namespaced(self.corev1api, namespace, estimate,
                                                                              self.config['labels']))
-        self.k8s['pvcs'] = pvcs
-        nrpvcs = len(pvcs)
-        logging.debug("get_pvcs[{}]:pvcs:{}".format(namespace, nrpvcs))
-        self.pvcs_counter += nrpvcs
-        self.pvcs_totalsize += totalsize
-        return pvcs
+        if isinstance(response, tuple) and len(response) == 2:
+            pvcs, totalsize = response
+            nrpvcs = len(pvcs)
+            self.pvcs_counter += nrpvcs
+            self.pvcs_totalsize += totalsize
+            self.k8s['pvcs'] = pvcs
+            logging.debug("get_pvcs[{}]:pvcs:{}".format(namespace, nrpvcs))
+            return pvcs
+        else:
+            return response # it should be a dictionary with an error
 
     def get_podtemplates(self, namespace, estimate=False):
         return self.__execute(lambda: podtemplates_list_namespaced(self.corev1api, namespace, estimate,