From: Alain Spineux Date: Thu, 8 Dec 2022 09:31:17 +0000 (+0100) Subject: k8s: Fix #9727 NoneType object is not subscriptable X-Git-Tag: Beta-15.0.0~327 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=901668010792c054cc3cedfc5c4201bd4d8adbd9;p=thirdparty%2Fbacula.git k8s: Fix #9727 NoneType object is not subscriptable - 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 --- diff --git a/bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/kubernetes_plugin.py b/bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/kubernetes_plugin.py index 1c52ec6df..e404cf4c8 100644 --- a/bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/kubernetes_plugin.py +++ b/bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/kubernetes_plugin.py @@ -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,