From: Alain Spineux Date: Thu, 9 Mar 2023 13:57:14 +0000 (+0100) Subject: k8s: Fix #9935 name 'response' is not defined in get_pods() X-Git-Tag: Beta-15.0.0~230 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0511f6e1d7aa66681101f291d2665417e2b054ec;p=thirdparty%2Fbacula.git k8s: Fix #9935 name 'response' is not defined in get_pods() - 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 --- 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 e404cf4c8..87b5b6565 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 @@ -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: