From: francisco.garcia Date: Mon, 29 Jan 2024 13:04:23 +0000 (+0100) Subject: k8s: Fix 0010669: When a node have not any pvc X-Git-Tag: Release-15.0.2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dd8bd7c7b2eeac4e0f70f4953cfa7162a0edd82;p=thirdparty%2Fbacula.git k8s: Fix 0010669: When a node have not any pvc --- diff --git a/bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/k8sbackend/pvcdata.py b/bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/k8sbackend/pvcdata.py index 17780d99f..0773ff3ca 100644 --- a/bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/k8sbackend/pvcdata.py +++ b/bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/k8sbackend/pvcdata.py @@ -48,19 +48,20 @@ def pvcdata_list_update_node_names(corev1api, namespace, pvcdatalist): dict: updated pvc data list as dictionary """ # here we collect node_names for proper backup pod deployment + logging.debug('Init PVCDATALIST: {}'.format(pvcdatalist)) pods = pods_namespaced_specs(corev1api, namespace=namespace) - logging.debug('[CUSTOM] Get pods:{}'.format(pods)) + logging.debug('Get pods:{}'.format(pods)) for pod in pods: - logging.debug('[CUSTOM] Pod: {}'.format(pod)) - logging.debug('[CUSTOM] Pod Specs: {}'.format(pod.spec)) - if pod.spec is not None: - logging.debug('[CUSTOM] POD SPEC is None') - for vol in pod.spec.volumes: - if vol.persistent_volume_claim is not None: - pvcname = vol.persistent_volume_claim.claim_name - for pvcf in pvcdatalist: - if pvcname == pvcdatalist[pvcf].get('name') and pvcdatalist[pvcf].get('node_name') is None: - pvcdatalist[pvcf]['node_name'] = pod.spec.node_name + if pod.spec is not None and pod.spec.volumes is not None: + for vol in pod.spec.volumes: + if vol.persistent_volume_claim is not None: + pvcname = vol.persistent_volume_claim.claim_name + for pvcf in pvcdatalist: + if pvcname == pvcdatalist[pvcf].get('name') and pvcdatalist[pvcf].get('node_name') is None: + logging.debug('[CUSTOM] Enter in pvcdatalist') + logging.debug('Pvcf: {} -- Node_name: {}'.format(pvcf, pod.spec.node_name)) + pvcdatalist[pvcf]['node_name'] = pod.spec.node_name + logging.debug('END PVCDATALIST: {}'.format(pvcdatalist)) return pvcdatalist @@ -77,12 +78,10 @@ def pvcdata_get_namespaced(corev1api, namespace, pvcname, pvcalias=None): dict: pvc data dict """ pvc = persistentvolumeclaims_read_namespaced(corev1api, namespace, pvcname) - logging.debug('[CUSTOM] Read PVC: ') - logging.debug(pvc) + logging.debug('Read PVC: {}'.format(pvc)) pvcspec = pvc.spec storageclassname = pvcspec.storage_class_name - logging.debug('[CUSTOM] Get size:' + str(pvcspec.resources)) pvcsize = pvcspec.resources.requests.get('storage', '-1') pvcdata = { 'name': pvcname, @@ -96,7 +95,7 @@ def pvcdata_get_namespaced(corev1api, namespace, pvcname, pvcalias=None): size=pvcsize), } pvcdatalist = pvcdata_list_update_node_names(corev1api, namespace, {pvcname: pvcdata}) - logging.debug('[CUSTOM] Read persistent volume claim completed') + logging.debug('Read persistent volume claim completed') return pvcdatalist.get(pvcname) 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 cff02907b..814764af3 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 @@ -544,7 +544,7 @@ class KubernetesPlugin(Plugin): def check_pvc_compatiblity_with_vsnapshot(self, namespace, pvc_name): pvc = self.get_pvcdata_namespaced(namespace, pvc_name) - logging.debug('[CUSTOM] Check Compatibilidy with Snapshots. Name: {}'.format(pvc_name, pvc)) + logging.debug('[CUSTOM] Check Compatibilidy with Snapshots. Name: {}'.format(pvc_name)) logging.debug('[CUSTOM] PVC: {}'.format(pvc)) return self.check_storage_compatibility_with_vsnapshot(pvc.get('storage_class_name'))