2323
2424HERE = os .path .dirname (__file__ )
2525SCS_SONOBUOY_CONFIG_PATH = os .path .join (HERE , 'scs-sonobuoy-config-v1.yaml' )
26+ KUBECONFIG_ROOT = os .path .join (os .path .expanduser ('~' ), '.local' , 'share' , 'scs' , 'clusters' )
2627
2728logger = logging .getLogger (__name__ )
2829
@@ -31,35 +32,35 @@ def usage(rcode=1, file=sys.stderr):
3132 """help output"""
3233 print ("Usage: k8s_test.py [options] testcase-id1 ... testcase-idN" , file = file )
3334 print ("Options:" , file = file )
34- print (" [-k /--kubeconfig KUBECONFIG_PATH ] (required)" , file = file )
35+ print (" [-c /--cluster-id CLUSTER_ID ] (required)" , file = file )
3536 print (" [-s/--subject SUBJECT]" , file = file )
3637 print (" [--execution-mode MODE] Sonobuoy mode: serial, parallel, or dry" , file = file )
37- print ("Runs specified testcases against the default context in kubeconfig provided " , file = file )
38- print ("via -k. Reports inconsistencies, errors etc.; returns 0 on success." , file = file )
38+ print ("Runs specified testcases against the kubeconfig specified via cluster_id. " , file = file )
39+ print ("Reports inconsistencies, errors etc.; returns 0 on success." , file = file )
3940 print ("Instead of listing testcase-ids, you can supply a single dash (-)" , file = file )
4041 print ("to have them read from stdin, one testcase-id per line." , file = file )
4142 sys .exit (rcode )
4243
4344
4445class Config :
4546 def __init__ (self ):
46- self .kubeconfig_path = os . environ . get ( "KUBECONFIG" )
47+ self .cluster_id = None
4748 self .subject = None
4849 self .mode = 'serial'
4950 self .testcases = []
5051
5152 def apply_argv (self , argv ):
5253 """Parse cli arguments from the script call"""
5354 try :
54- opts , args = getopt .gnu_getopt (argv , "k :s:" , ("kubeconfig =" , "subject=" , "execution-mode=" ))
55+ opts , args = getopt .gnu_getopt (argv , "c :s:" , ("cluster-id =" , "subject=" , "execution-mode=" ))
5556 except getopt .GetoptError as exc :
5657 print (f"CRITICAL: { exc !r} " , file = sys .stderr )
5758 usage (1 )
5859 for opt in opts :
5960 if opt [0 ] == "-h" or opt [0 ] == "--help" :
6061 usage (0 )
61- elif opt [0 ] == "-k " or opt [0 ] == "--kubeconfig " :
62- self .kubeconfig_path = opt [1 ]
62+ elif opt [0 ] == "-c " or opt [0 ] == "--cluster-id " :
63+ self .cluster_id = opt [1 ]
6364 elif opt [0 ] == "-s" or opt [0 ] == "--subject" :
6465 self .subject = opt [1 ]
6566 elif opt [0 ] == "--execution-mode" :
@@ -72,11 +73,15 @@ def apply_argv(self, argv):
7273 if len (self .testcases ) != len (args ):
7374 unknown = [a for a in args if a not in self .testcases ]
7475 logger .warning (f"ignoring unknown testcases: { ',' .join (unknown )} " )
75- if not self .kubeconfig_path :
76+ if not self .cluster_id :
7677 print ("CRITICAL: You need to have KUBECONFIG set or pass --kubeconfig=KUBECONFIG." , file = sys .stderr )
7778 sys .exit (1 )
7879 if not self .subject :
79- self .subject = self .kubeconfig_path
80+ self .subject = self .cluster_id
81+
82+ @property
83+ def kubeconfig_path (self ):
84+ return os .path .join (KUBECONFIG_ROOT , self .cluster_id , 'kubeconfig.yaml' )
8085
8186 def compute_sono_args (self , * args ):
8287 if self .mode == 'parallel' :
0 commit comments