@@ -31,23 +31,35 @@ def filter_defaults(base, user_provided, root_diff, path=[], strict=False):
31
31
if base != user_provided :
32
32
traverse_and_set (user_provided , root_diff , path )
33
33
34
-
35
34
if __name__ == "__main__" :
36
35
root_diff = {}
37
36
path = []
38
37
39
38
parser = argparse .ArgumentParser (description = "Tool to identify diffs between values.yaml and default" )
40
- parser .add_argument ("default_values" , metavar = "default_values.yaml" , type = str ,
41
- help = "Base values.yaml for the helm chart version you're using" )
42
39
parser .add_argument ("user_customized_values" , metavar = "customized.yaml" , type = str , help = "Customized values.yaml" )
43
40
parser .add_argument ("-o" , "--output" , default = None , type = str ,
44
41
help = "Write to filename. If not specified, output is written to stdout." )
45
42
parser .add_argument ("-s" , "--strict" , default = False , action = argparse .BooleanOptionalAction , type = bool ,
46
43
help = "strict mode will drop all options not in default values.yaml." )
44
+ parser .add_argument ("--default_values" , metavar = "default_values.yaml" , type = str ,
45
+ help = "Base values.yaml for the helm chart version you're using" )
46
+ parser .add_argument ("--chart" , type = str , help = "Helm chart name" )
47
+ parser .add_argument ("--version" , type = str , help = "Helm chart version" )
47
48
args = parser .parse_args ()
48
49
49
- with open (args .default_values , 'r' ) as default_values :
50
- default_v = yaml .safe_load (default_values )
50
+ if args .default_values :
51
+ with open (args .default_values , 'r' ) as default_values :
52
+ default_v = yaml .safe_load (default_values )
53
+ elif args .chart and args .version :
54
+ import subprocess
55
+ result = subprocess .run (
56
+ ["helm" , "show" , "values" , args .chart , "--version" , args .version ],
57
+ capture_output = True , text = True , check = True
58
+ )
59
+ default_v = yaml .safe_load (result .stdout )
60
+ print (type (default_v ))
61
+ else :
62
+ raise ValueError ("Either --default_values or both --chart and --version must be specified" )
51
63
52
64
with open (args .user_customized_values , 'r' ) as overwritten_values :
53
65
overwritten_v = yaml .safe_load (overwritten_values )
@@ -58,4 +70,4 @@ def filter_defaults(base, user_provided, root_diff, path=[], strict=False):
58
70
with open (args .output , 'w' ) as outfile :
59
71
yaml .dump (root_diff , outfile , sort_keys = False )
60
72
else :
61
- yaml .dump (root_diff , sys .stdout , sort_keys = False )
73
+ yaml .dump (root_diff , sys .stdout , sort_keys = False )
0 commit comments