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 :
@@ -192,7 +206,7 @@ def update_nodes(
192
206
193
207
def write_user_appwrapper (user_yaml , output_file_name ):
194
208
with open (output_file_name , "w" ) as outfile :
195
- yaml .dump (user_yaml , outfile , default_flow_style = False )
209
+ yaml .dump (user_yaml , outfile , default_flow_style = False , Dumper = NoAliasDumper )
196
210
print (f"Written to: { output_file_name } " )
197
211
198
212
@@ -210,6 +224,7 @@ def generate_appwrapper(
210
224
instascale : bool ,
211
225
instance_types : list ,
212
226
env ,
227
+ pull_secret : str ,
213
228
):
214
229
user_yaml = read_template (template )
215
230
appwrapper_name , cluster_name = gen_names (name )
@@ -233,6 +248,7 @@ def generate_appwrapper(
233
248
image ,
234
249
instascale ,
235
250
env ,
251
+ pull_secret ,
236
252
)
237
253
update_dashboard_route (route_item , cluster_name , namespace )
238
254
outfile = appwrapper_name + ".yaml"
@@ -314,6 +330,12 @@ def main(): # pragma: no cover
314
330
default = "default" ,
315
331
help = "Set the kubernetes namespace you want to deploy your cluster to. Default. If left blank, uses the 'default' namespace" ,
316
332
)
333
+ parser .add_argument (
334
+ "--pull-secret" ,
335
+ required = False ,
336
+ default = "" ,
337
+ help = "Set pull secret for a private registry" ,
338
+ )
317
339
318
340
args = parser .parse_args ()
319
341
name = args .name
@@ -329,6 +351,7 @@ def main(): # pragma: no cover
329
351
instance_types = args .instance_types
330
352
namespace = args .namespace
331
353
env = {}
354
+ pull_secret = args .pull_secret
332
355
333
356
outfile = generate_appwrapper (
334
357
name ,
@@ -344,6 +367,7 @@ def main(): # pragma: no cover
344
367
instascale ,
345
368
instance_types ,
346
369
env ,
370
+ pull_secret ,
347
371
)
348
372
return outfile
349
373
0 commit comments