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