@@ -98,9 +98,10 @@ def _wait_until(predicate, timeoutSeconds, delaySeconds=0.25, *args, **kwargs):
9898 except Exception :
9999 pass
100100 time .sleep (delaySeconds )
101-
101+
102102 print ("Condition not met within " + str (timeoutSeconds ))
103- raise
103+ raise Exception ("Condition not met within " + str (timeoutSeconds ))
104+
104105
105106def _utf_encode_list (list ):
106107 return [s .encode ("UTF8" ) for s in list ]
@@ -197,6 +198,9 @@ def _verifyConfig(tfvars_file, no_create=None, no_destroy=None):
197198 numWorkers = len (outputJSON ["value" ])
198199 workerPublicAddressList = _utf_encode_list (outputJSON ["value" ])
199200
201+ outputJSON = json .loads (_terraform ("output -json control_plane_subnet_access" ))
202+ controlPlaneSubnetAccess = outputJSON ["value" ]
203+
200204 _log ("K8s Master Public LB Address: " + masterPublicLBAddress )
201205 _log ("K8s Worker Public Addresses: " + str (workerPublicAddressList ))
202206
@@ -225,29 +229,32 @@ def _verifyConfig(tfvars_file, no_create=None, no_destroy=None):
225229 _log ("Sleeping 30 seconds to let pods initialize" , as_banner = True )
226230 time .sleep (30 )
227231
228- _kubectl ("apply -f " + TEST_ROOT_DIR + "/resources/ hello-service.yml " , exit_on_error = True )
229- _kubectl ( "apply -f " + TEST_ROOT_DIR + "/resources/frontend-service.yml" , exit_on_error = True )
232+ helloServicePort = _kubectl ("get svc/ hello -o jsonpath={.spec.ports[0].nodePort} " , exit_on_error = True )
233+ _log ( "Hello service port: " + str ( helloServicePort ) )
230234
231- _log ("Waiting for the LoadBalancer to initialize" , as_banner = True )
232- externalIPReady = lambda : _kubectl ("get svc/frontend -o jsonpath={.status.loadBalancer.ingress[0].ip}" , exit_on_error = True ) != ""
233- _wait_until (externalIPReady , 600 )
234- externalIP = _kubectl ("get svc/frontend -o jsonpath={.status.loadBalancer.ingress[0].ip}" , exit_on_error = True )
235- _log ("Frontend service IP (OCI Load Balancer): " + str (externalIP ))
235+ frontendServicePort = _kubectl ("get svc/frontend -o jsonpath={.spec.ports[0].nodePort}" , exit_on_error = True )
236+ _log ("Frontend service port: " + str (frontendServicePort ))
236237
237- _log ("Checking " + "http://" + externalIP )
238- applicationAvailable = lambda : requests .get ("http://" + externalIP ).status_code == 200
239- _wait_until (applicationAvailable , 60 )
238+ if controlPlaneSubnetAccess == "public" :
239+ # Ping deployment
240+ _log ("Pinging hello and frontend deployments for each K8s worker" , as_banner = True )
241+ for workerPublicAddress in workerPublicAddressList :
242+ serviceAddressList = ["http://" + workerPublicAddress + ":" + str (helloServicePort ),
243+ "http://" + workerPublicAddress + ":" + str (frontendServicePort )]
244+ for serviceAddress in serviceAddressList :
245+ _log ("Checking " + serviceAddress )
246+ deploymentReady = lambda : requests .get (serviceAddress ).status_code == 200
247+ _wait_until (deploymentReady , 180 )
240248
241249 except Exception , e :
242250 _log ("Unexpected error:" , str (e ))
243251 traceback .print_exc ()
244252 success = False
245253 finally :
246- _log ("Undeploying the hello service" , as_banner = True )
247- _kubectl ("delete -f " + TEST_ROOT_DIR + "/resources/hello-service.yml" , exit_on_error = False )
248- _kubectl ("delete -f " + TEST_ROOT_DIR + "/resources/frontend-service.yml" , exit_on_error = False )
249- # Wait a minute for OCI Load Balancer to be deleted before starting terraform destroy
250- time .sleep (120 )
254+ if masterPublicLBAddress != None :
255+ _log ("Undeploying the hello service" , as_banner = True )
256+ _kubectl ("delete -f " + TEST_ROOT_DIR + "/resources/hello-service.yml" , exit_on_error = False )
257+ _kubectl ("delete -f " + TEST_ROOT_DIR + "/resources/frontend-service.yml" , exit_on_error = False )
251258
252259 if not no_destroy :
253260 _log ("Destroying the K8s cluster from " + str (os .path .basename (tfvars_file )), as_banner = True )
0 commit comments