@@ -44,6 +44,26 @@ def __init__(self, helmizer_config, arguments):
44
44
if dict_get_common_labels :
45
45
self .yaml ['commonLabels' ] = dict_get_common_labels
46
46
47
+ # crds
48
+ list_crds = self .get_files (arguments , 'crds' )
49
+ if list_crds :
50
+ self .yaml ['crds' ] = list_crds
51
+
52
+ # components
53
+ list_components = self .get_files (arguments , 'components' )
54
+ if list_components :
55
+ self .yaml ['components' ] = list_components
56
+
57
+ # namePrefix
58
+ str_name_prefix = self .get_name_prefix ()
59
+ if str_name_prefix :
60
+ self .yaml ['namePrefix' ] = str_name_prefix
61
+
62
+ # nameSuffix
63
+ str_name_suffix = self .get_name_suffix ()
64
+ if str_name_suffix :
65
+ self .yaml ['nameSuffix' ] = str_name_suffix
66
+
47
67
# patchesStrategicMerge
48
68
list_patches_strategic_merge = self .get_files (arguments , 'patchesStrategicMerge' )
49
69
if list_patches_strategic_merge :
@@ -72,29 +92,33 @@ def print_kustomization(self):
72
92
73
93
74
94
def write_kustomization (self , arguments ):
75
- # identify kustomization file's parent directory
76
- str_kustomization_directory = path .dirname (path .abspath (path .normpath (arguments .helmizer_config )))
77
-
78
- # identify kustomization file name
79
- str_kustomization_file_name = str ()
80
- try :
81
- str_kustomization_file_name = self .helmizer_config ['helmizer' ]['kustomization-file-name' ].get (str )
82
- except KeyError :
83
- str_kustomization_file_name = 'kustomization.yaml'
84
-
85
- # write to file
86
- try :
87
- kustomization_file_path = path .normpath (f'{ str_kustomization_directory } /{ str_kustomization_file_name } ' )
88
- with open (kustomization_file_path , 'w' ) as file :
89
- file .write (yaml .dump (self .yaml ))
90
- logging .debug (f'Successfully wrote to file: { path .abspath (kustomization_file_path )} ' )
91
- except IsADirectoryError as e :
92
- raise e
93
- except TypeError :
94
- pass
95
+ if self .helmizer_config ['helmizer' ]['dry-run' ].get (bool ) or arguments .dry_run :
96
+ logging .debug ('Performing dry-run, not writing to a file system' )
97
+ else :
98
+ # identify kustomization file's parent directory
99
+ str_kustomization_directory = path .dirname (path .abspath (path .normpath (arguments .helmizer_config )))
100
+
101
+ # identify kustomization file name
102
+ str_kustomization_file_name = str ()
103
+ try :
104
+ str_kustomization_file_name = self .helmizer_config ['helmizer' ]['kustomization-file-name' ].get (str )
105
+ except KeyError :
106
+ str_kustomization_file_name = 'kustomization.yaml'
107
+
108
+ # write to file
109
+ try :
110
+ kustomization_file_path = path .normpath (f'{ str_kustomization_directory } /{ str_kustomization_file_name } ' )
111
+ with open (kustomization_file_path , 'w' ) as file :
112
+ file .write (yaml .dump (self .yaml ))
113
+ logging .debug (f'Successfully wrote to file: { path .abspath (kustomization_file_path )} ' )
114
+ except IsADirectoryError as e :
115
+ raise e
116
+ except TypeError :
117
+ pass
95
118
96
119
97
120
def render_template (self , arguments ):
121
+ logging .debug ('Rendering template' )
98
122
self .sort_keys ()
99
123
self .print_kustomization ()
100
124
self .write_kustomization (arguments )
@@ -147,6 +171,30 @@ def get_common_labels(self):
147
171
return dict_common_labels
148
172
149
173
174
+ def get_name_prefix (self ):
175
+ str_name_prefix = str ()
176
+ try :
177
+ if len (self .helmizer_config ['kustomize' ]['namePrefix' ].get (str )) > 0 :
178
+ str_name_prefix = self .helmizer_config ['kustomize' ]['namePrefix' ].get (str )
179
+ logging .debug (f'namespace: { str_name_prefix } ' )
180
+ except TypeError :
181
+ pass
182
+ finally :
183
+ return str_name_prefix
184
+
185
+
186
+ def get_name_suffix (self ):
187
+ str_name_suffix = str ()
188
+ try :
189
+ if len (self .helmizer_config ['kustomize' ]['nameSuffix' ].get (str )) > 0 :
190
+ str_name_suffix = self .helmizer_config ['kustomize' ]['nameSuffix' ].get (str )
191
+ logging .debug (f'namespace: { str_name_suffix } ' )
192
+ except TypeError :
193
+ pass
194
+ finally :
195
+ return str_name_suffix
196
+
197
+
150
198
def get_files (self , arguments , key ):
151
199
list_target_paths = list ()
152
200
list_final_target_paths = list ()
@@ -183,6 +231,7 @@ def get_files(self, arguments, key):
183
231
# remove any ignored files
184
232
try :
185
233
for ignore in self .helmizer_config ['helmizer' ]['ignore' ].get (list ):
234
+ logging .debug (f'Removing ignored file from final list: { ignore } ' )
186
235
list_final_target_paths .remove (ignore )
187
236
except ValueError :
188
237
pass
@@ -238,21 +287,20 @@ def init_arg_parser():
238
287
args = parser .add_argument_group ()
239
288
args .add_argument ('--debug' , dest = 'debug' , action = 'store_true' , help = 'enable debug logging' , default = False )
240
289
args .add_argument ('--dry-run' , dest = 'dry_run' , action = 'store_true' , help = 'do not write to a file system' , default = False )
290
+ args .add_argument ('--skip-commands' , dest = 'skip_commands' , action = 'store_true' ,
291
+ help = 'skip executing commandSequence, just generate kustomization file' , default = False )
241
292
args .add_argument ('--quiet' , '-q' , dest = 'quiet' , action = 'store_true' , help = 'quiet output from subprocesses' ,
242
- default = False )
243
- args .add_argument ('--version' , action = 'version' , version = 'v0.7 .0' )
293
+ default = False )
294
+ args .add_argument ('--version' , action = 'version' , version = 'v0.8 .0' )
244
295
args .add_argument ('helmizer_config' , action = 'store' , type = str , help = 'path to helmizer config file' )
245
296
arguments = parser .parse_args ()
246
297
247
298
if arguments .quiet :
248
- logging .basicConfig (level = logging .INFO , datefmt = None , stream = None ,
249
- format = '[%(asctime)s %(levelname)s] %(message)s' )
299
+ logging .basicConfig (level = logging .INFO , datefmt = None , stream = None , format = '[%(asctime)s %(levelname)s] %(message)s' )
250
300
if arguments .debug :
251
- logging .basicConfig (level = logging .DEBUG , datefmt = None , stream = stdout ,
252
- format = '[%(asctime)s %(levelname)s] %(message)s' )
301
+ logging .basicConfig (level = logging .DEBUG , datefmt = None , stream = stdout , format = '[%(asctime)s %(levelname)s] %(message)s' )
253
302
else :
254
- logging .basicConfig (level = logging .INFO , datefmt = None , stream = stdout ,
255
- format = '[%(asctime)s %(levelname)s] %(message)s' )
303
+ logging .basicConfig (level = logging .INFO , datefmt = None , stream = stdout , format = '[%(asctime)s %(levelname)s] %(message)s' )
256
304
257
305
return arguments
258
306
except argparse .ArgumentError as e :
@@ -291,7 +339,8 @@ def init_helmizer_config(arguments):
291
339
def main ():
292
340
arguments = init_arg_parser ()
293
341
helmizer_config = init_helmizer_config (arguments )
294
- run_subprocess (helmizer_config , arguments )
342
+ if not arguments .skip_commands :
343
+ run_subprocess (helmizer_config , arguments )
295
344
kustomization = Kustomization (helmizer_config , arguments )
296
345
kustomization .render_template (arguments )
297
346
0 commit comments