]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
k8s: Fix 0010669: When a node have not any pvc
authorfrancisco.garcia <francisco.garcia@baculasystems.com>
Mon, 29 Jan 2024 13:04:23 +0000 (14:04 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 21 Mar 2024 16:13:40 +0000 (17:13 +0100)
bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/k8sbackend/pvcdata.py
bacula/src/plugins/fd/kubernetes-backend/baculak8s/plugins/kubernetes_plugin.py

index 17780d99f180fd7cef31b1755ae4357c458e29c9..0773ff3ca25f38b68b08d073b3200dff1ce6412b 100644 (file)
@@ -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)
 
index cff02907b503770742543d9d83e7bb2c73ec7e87..814764af313b1c48037d859d5e953bfef2a7ffe6 100644 (file)
@@ -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'))