@@ -91,7 +91,9 @@ def create_pvc_pod(
9191 """
9292 # 1. Create PersistantVolumeClaim
9393 logger .debug (f"create pvc: { pvc_name } " )
94+
9495 creationflag = 2
96+
9597 pvc_meta = client .V1ObjectMeta (name = pvc_name )
9698 pvc_resources = client .V1ResourceRequirements (
9799 requests = {"storage" : "1Gi" },
@@ -108,9 +110,16 @@ def create_pvc_pod(
108110 api_response = k8s_api_instance .create_namespaced_persistent_volume_claim (
109111 namespace , body_pvc
110112 )
111- if k8s_api_instance .read_namespaced_persistent_volume_claim (name = pvc_name , namespace = namespace ):
112- creationflag -= 1
113+ try k8s_api_instance .read_namespaced_persistent_volume_claim (name = pvc_name , namespace = namespace ):
113114 logger .debug (f"created pvc successfully { creationflag } " )
115+ except ApiException as api_exception :
116+ logger .info (f"code { api_exception .status } " )
117+ if api_exception .status == 404 :
118+ logger .info (
119+ "pod not found, "
120+ "failed to build resources correctly"
121+ )
122+ return 43
114123
115124 # 2. Create a pod which makes use of the PersistantVolumeClaim
116125 logger .debug (f"create pod: { pod_name } " )
@@ -138,9 +147,17 @@ def create_pvc_pod(
138147 api_response = k8s_api_instance .create_namespaced_pod (
139148 namespace , pod_body , _preload_content = False ,
140149 )
141- if k8s_api_instance .read_namespaced_pod (name = pod_name , namespace = namespace ):
142- creationflag -= 1
143- logger .debug (f"created pod successfully { creationflag } " )
150+ try :
151+ k8s_api_instance .read_namespaced_pod (name = pod_name , namespace = namespace ):
152+ logger .debug (f"created pod successfully" )
153+ except ApiException as api_exception :
154+ logger .info (f"code { api_exception .status } " )
155+ if api_exception .status == 404 :
156+ logger .info (
157+ "pod not found, "
158+ "failed to build resources correctly"
159+ )
160+ return 44
144161 pod_info = json .loads (api_response .read ().decode ("utf-8" ))
145162 pod_status = pod_info ["status" ]["phase" ]
146163
0 commit comments