771: Not able to connect to k8s api
882: Kubeconfig not set
993: Conflicting Resources
10+ 4: Resource not found
1011
111231: Default storage class has no provisioner
121332: None or more then one default Storage Class is defined
@@ -105,6 +106,8 @@ def create_pvc_pod(
105106 api_response = k8s_api_instance .create_namespaced_persistent_volume_claim (
106107 namespace , body_pvc
107108 )
109+ k8s_api_instance .read_namespaced_persistent_volume_claim (name = pvc_name , namespace = namespace )
110+ logger .debug (f"created pvc successfully" )
108111
109112 # 2. Create a pod which makes use of the PersistantVolumeClaim
110113 logger .debug (f"create pod: { pod_name } " )
@@ -132,9 +135,12 @@ def create_pvc_pod(
132135 api_response = k8s_api_instance .create_namespaced_pod (
133136 namespace , pod_body , _preload_content = False ,
134137 )
138+ k8s_api_instance .read_namespaced_pod (name = pod_name , namespace = namespace )
139+ logger .debug (f"created pod successfully" )
135140 pod_info = json .loads (api_response .read ().decode ("utf-8" ))
136141 pod_status = pod_info ["status" ]["phase" ]
137142
143+
138144 retries = 0
139145 while pod_status != "Running" and retries <= num_retries :
140146 api_response = k8s_api_instance .read_namespaced_pod (
@@ -255,13 +261,13 @@ def prepare(self):
255261 return True
256262 return False
257263 except ApiException as e :
258- logger .error (f"Error preparing Environment: { e } " )
259- return False
264+ logger .error (f"Error preparing Environment: { e } " )
265+ return False
260266
261267 def clean (self ):
262268 api_response = None
263269 try :
264- logger .debug (f"delete pod:{ self .pod_name } " )
270+ logger .debug (f"delete pod: { self .pod_name } " )
265271 api_response = self .k8s_core_api .delete_namespaced_pod (
266272 self .pod_name , self .namespace
267273 )
@@ -280,10 +286,10 @@ def __enter__(self):
280286 retries = 0
281287 while retries <= 2 :
282288 if self .prepare ():
283- self .clean ()
284289 logger .debug (
285290 f"Deleting Leftovers in namespace { self .namespace } from previous test runs"
286291 )
292+ self .clean ()
287293 time .sleep (2 )
288294 else :
289295 logger .debug (f"Entering the context { self .k8s_core_api } " )
@@ -355,7 +361,16 @@ def main(argv):
355361 try :
356362 env .return_code = create_pvc_pod (k8s_core_api , default_class_name )
357363 except ApiException as api_exception :
358- if api_exception .status == 409 :
364+ logger .info (f"code { api_exception .status } " )
365+ if api_exception .status == 404 :
366+ logger .info (
367+ "resource not found, "
368+ "failed to build resources correctly"
369+ )
370+ env .return_code = 4
371+ env .return_message = "(404) resource not found"
372+ return
373+ elif api_exception .status == 409 :
359374 logger .info (
360375 "conflicting resources, "
361376 "try to clean up left overs, then start again"
@@ -365,7 +380,8 @@ def main(argv):
365380 return
366381 else :
367382 logger .info (f"An API error occurred: { api_exception } " )
368- env .return_code = 1
383+ env .return_code = api_exception .status
384+ return
369385
370386 logger .info (
371387 "Check if default_persistent volume has ReadWriteOnce defined (MANDATORY)"
0 commit comments