@@ -63,7 +63,7 @@ type TestOptions struct {
6363	logsExportDir        string 
6464	operatorConfigPath   string 
6565	logsExportOnSuccess  bool 
66- 	withIPPool           bool 
66+ 	debugLog              bool 
6767}
6868
6969var  testOptions  TestOptions 
@@ -304,148 +304,6 @@ func (data *TestData) deleteNamespace(namespace string, timeout time.Duration) e
304304
305305type  PodCondition  func (* corev1.Pod ) (bool , error )
306306
307- // waitForSecurityPolicyReady polls the K8s apiServer until the specified CR is in the "True" state (or until 
308- // the provided timeout expires). 
309- func  (data  * TestData ) waitForCRReadyOrDeleted (timeout  time.Duration , cr  string , namespace  string , name  string , status  Status ) error  {
310- 	err  :=  wait .PollUntilContextTimeout (context .TODO (), 1 * time .Second , timeout , false , func (ctx  context.Context ) (bool , error ) {
311- 		cmd  :=  fmt .Sprintf ("kubectl get %s %s -n %s -o jsonpath='{.status.conditions[?(@.type==\" Ready\" )].status}'" , cr , name , namespace )
312- 		rc , stdout , stderr , err  :=  RunCommandOnNode (clusterInfo .masterNodeName , cmd )
313- 		log .Printf ("Command: %s\n , result: %d, stdout: %s, stderr:%s, error: %+v\n " , cmd , rc , stdout , stderr , err )
314- 		if  err  !=  nil  ||  rc  !=  0  {
315- 			if  status  ==  Deleted  {
316- 				return  true , nil 
317- 			}
318- 			return  false , fmt .Errorf ("error when running the following command `%s` on master Node: %v, %s" , cmd , err , stdout )
319- 		} else  {
320- 			if  status  ==  Ready  {
321- 				if  stdout  ==  "True"  {
322- 					return  true , nil 
323- 				}
324- 				return  false , nil 
325- 			}
326- 			return  false , nil 
327- 		}
328- 	})
329- 	if  err  !=  nil  {
330- 		return  err 
331- 	}
332- 	return  nil 
333- }
334- 
335- func  (data  * TestData ) getCRPropertiesByJson (timeout  time.Duration , crType , crName , namespace , key  string ) (string , error ) {
336- 	value  :=  "" 
337- 	err  :=  wait .PollUntilContextTimeout (context .TODO (), 1 * time .Second , timeout , false , func (ctx  context.Context ) (bool , error ) {
338- 		cmd  :=  "" 
339- 		// for cluster scope resource, namespace is empty 
340- 		if  namespace  ==  ""  {
341- 			cmd  =  fmt .Sprintf ("kubectl get %s %s -o json | jq '%s'" , crType , crName , key )
342- 		} else  {
343- 			cmd  =  fmt .Sprintf ("kubectl get %s %s -n %s -o json | jq '%s'" , crType , crName , namespace , key )
344- 		}
345- 		log .Printf ("%s" , cmd )
346- 		rc , stdout , _ , err  :=  RunCommandOnNode (clusterInfo .masterNodeName , cmd )
347- 		if  err  !=  nil  ||  rc  !=  0  {
348- 			return  false , fmt .Errorf ("error when running the following command `%s` on master Node: %v, %s" , cmd , err , stdout )
349- 		} else  {
350- 			// check if 'null' in stdout 
351- 			if  strings .Contains (stdout , "null" ) {
352- 				return  false , nil 
353- 			}
354- 			value  =  stdout 
355- 			return  true , nil 
356- 		}
357- 	})
358- 	if  err  !=  nil  {
359- 		return  value , err 
360- 	}
361- 	return  value , nil 
362- }
363- 
364- // For CRs that we do not know the name, return the CR list for upper logic to identify 
365- func  (data  * TestData ) getCRResources (timeout  time.Duration , crtype , namespace  string ) (map [string ]string , error ) {
366- 	crs  :=  map [string ]string {}
367- 	err  :=  wait .PollUntilContextTimeout (context .TODO (), 1 * time .Second , timeout , false , func (ctx  context.Context ) (bool , error ) {
368- 		cmd  :=  "" 
369- 		if  namespace  ==  ""  { // for cluster scope resources 
370- 			cmd  =  fmt .Sprintf ("kubectl get %s" , crtype )
371- 		} else  if  crtype  ==  "namespaces"  {
372- 			cmd  =  fmt .Sprintf ("kubectl get %s %s" , crtype , namespace )
373- 		} else  {
374- 			cmd  =  fmt .Sprintf ("kubectl get %s -n %s" , crtype , namespace )
375- 		}
376- 		log .Printf ("%s" , cmd )
377- 		rc , stdout , _ , err  :=  RunCommandOnNode (clusterInfo .masterNodeName , cmd )
378- 		if  err  !=  nil  ||  rc  !=  0  {
379- 			return  false , fmt .Errorf ("error when running the following command `%s` on master Node: %v, %s" , cmd , err , stdout )
380- 		} else  {
381- 			crs_raw  :=  strings .Split (stdout , "\n " )
382- 			// for each resource, get json structure as value 
383- 			for  i , c  :=  range  crs_raw  {
384- 				if  i  ==  0  {
385- 					// first line is table header 
386- 					continue 
387- 				}
388- 				r  :=  regexp .MustCompile ("[^\\ s]+" )
389- 				parts  :=  r .FindAllString (c , - 1 )
390- 				if  len (parts ) <  1  { // to avoid empty lines 
391- 					continue 
392- 				}
393- 				uid_cmd  :=  "" 
394- 				if  namespace  ==  ""  ||  crtype  ==  "namespaces"  {
395- 					uid_cmd  =  fmt .Sprintf ("kubectl get %s %s -o yaml | grep uid" , crtype , parts [0 ])
396- 				} else  {
397- 					uid_cmd  =  fmt .Sprintf ("kubectl get %s %s -n %s -o yaml | grep uid" , crtype , parts [0 ], namespace )
398- 				}
399- 				log .Printf ("trying to get uid for cr: %s" , uid_cmd )
400- 				rc , stdout , _ , err  :=  RunCommandOnNode (clusterInfo .masterNodeName , uid_cmd )
401- 				if  err  !=  nil  ||  rc  !=  0  {
402- 					return  false , fmt .Errorf ("error when running the following command `%s` on master Node: %v, %s" , uid_cmd , err , stdout )
403- 				}
404- 				uid  :=  strings .Split (stdout , ":" )[1 ]
405- 				crs [parts [0 ]] =  uid 
406- 			}
407- 			return  true , nil 
408- 		}
409- 	})
410- 	if  err  !=  nil  {
411- 		return  crs , err 
412- 	}
413- 	return  crs , nil 
414- }
415- 
416- // Return a singe CR via CR name 
417- func  (data  * TestData ) getCRResource (timeout  time.Duration , crtype , crname , namespace  string ) (string , error ) {
418- 	ret  :=  "" 
419- 	err  :=  wait .PollUntilContextTimeout (context .TODO (), 1 * time .Second , timeout , false , func (ctx  context.Context ) (bool , error ) {
420- 		// If namespace is empty, then this is a cluster scope resource. 
421- 		uid_cmd  :=  "" 
422- 		if  namespace  ==  ""  {
423- 			uid_cmd  =  fmt .Sprintf ("kubectl get %s %s -o yaml | grep uid" , crtype , crname )
424- 		} else  if  crtype  ==  "namespaces"  {
425- 			uid_cmd  =  fmt .Sprintf ("kubectl get %s %s -o yaml | grep uid" , crtype , namespace )
426- 		} else  {
427- 			uid_cmd  =  fmt .Sprintf ("kubectl get %s %s -n %s -o yaml | grep uid" , crtype , crname , namespace )
428- 		}
429- 		log .Printf ("%s" , uid_cmd )
430- 		rc , stdout , _ , err  :=  RunCommandOnNode (clusterInfo .masterNodeName , uid_cmd )
431- 		if  err  !=  nil  ||  rc  !=  0  {
432- 			return  false , fmt .Errorf ("error when running the following command `%s` on master Node: %v, %s" , uid_cmd , err , stdout )
433- 		} else  {
434- 			parts  :=  strings .Split (stdout , ":" )
435- 			if  len (parts ) <  2  {
436- 				return  false , nil 
437- 			}
438- 			uid  :=  parts [1 ]
439- 			ret  =  uid 
440- 		}
441- 		return  true , nil 
442- 	})
443- 	if  err  !=  nil  {
444- 		return  "" , err 
445- 	}
446- 	return  ret , nil 
447- }
448- 
449307// deploymentWaitForNames polls the K8s apiServer once the specific pods are created, no matter they are running or not. 
450308func  (data  * TestData ) deploymentWaitForNames (timeout  time.Duration , namespace , deployment  string ) ([]string , error ) {
451309	var  podNames  []string 
0 commit comments