23
23
import uuid
24
24
25
25
26
+ class NoAliasDumper (yaml .Dumper ):
27
+ def ignore_aliases (self , data ):
28
+ return True
29
+
30
+
26
31
def read_template (template ):
27
32
with open (template , "r" ) as stream :
28
33
try :
@@ -130,6 +135,13 @@ def update_image(spec, image):
130
135
container ["image" ] = image
131
136
132
137
138
+ def update_pull_secret (spec , pull_secret ):
139
+ if pull_secret :
140
+ if "imagePullSecrets" not in spec :
141
+ spec ["imagePullSecrets" ] = []
142
+ spec ["imagePullSecrets" ].append (pull_secret )
143
+
144
+
133
145
def update_env (spec , env ):
134
146
containers = spec .get ("containers" )
135
147
for container in containers :
@@ -167,6 +179,7 @@ def update_nodes(
167
179
image ,
168
180
instascale ,
169
181
env ,
182
+ pull_secret ,
170
183
):
171
184
if "generictemplate" in item .keys ():
172
185
head = item .get ("generictemplate" ).get ("spec" ).get ("headGroupSpec" )
@@ -182,6 +195,7 @@ def update_nodes(
182
195
for comp in [head , worker ]:
183
196
spec = comp .get ("template" ).get ("spec" )
184
197
update_affinity (spec , appwrapper_name , instascale )
198
+ update_pull_secret (spec , pull_secret )
185
199
update_image (spec , image )
186
200
update_env (spec , env )
187
201
if comp == head :
@@ -193,7 +207,7 @@ def update_nodes(
193
207
194
208
def write_user_appwrapper (user_yaml , output_file_name ):
195
209
with open (output_file_name , "w" ) as outfile :
196
- yaml .dump (user_yaml , outfile , default_flow_style = False )
210
+ yaml .dump (user_yaml , outfile , default_flow_style = False , Dumper = NoAliasDumper )
197
211
print (f"Written to: { output_file_name } " )
198
212
199
213
@@ -211,6 +225,7 @@ def generate_appwrapper(
211
225
instascale : bool ,
212
226
instance_types : list ,
213
227
env ,
228
+ pull_secret : str ,
214
229
):
215
230
user_yaml = read_template (template )
216
231
appwrapper_name , cluster_name = gen_names (name )
@@ -234,6 +249,7 @@ def generate_appwrapper(
234
249
image ,
235
250
instascale ,
236
251
env ,
252
+ pull_secret ,
237
253
)
238
254
update_dashboard_route (route_item , cluster_name , namespace )
239
255
outfile = appwrapper_name + ".yaml"
@@ -315,6 +331,12 @@ def main(): # pragma: no cover
315
331
default = "default" ,
316
332
help = "Set the kubernetes namespace you want to deploy your cluster to. Default. If left blank, uses the 'default' namespace" ,
317
333
)
334
+ parser .add_argument (
335
+ "--pull-secret" ,
336
+ required = False ,
337
+ default = "" ,
338
+ help = "Set pull secret for a private registry" ,
339
+ )
318
340
319
341
args = parser .parse_args ()
320
342
name = args .name
@@ -330,6 +352,7 @@ def main(): # pragma: no cover
330
352
instance_types = args .instance_types
331
353
namespace = args .namespace
332
354
env = {}
355
+ pull_secret = args .pull_secret
333
356
334
357
outfile = generate_appwrapper (
335
358
name ,
@@ -345,6 +368,7 @@ def main(): # pragma: no cover
345
368
instascale ,
346
369
instance_types ,
347
370
env ,
371
+ pull_secret ,
348
372
)
349
373
return outfile
350
374
0 commit comments