@@ -29,7 +29,7 @@ func runInjectionMadness(tempPath tempPaths) {
29
29
defer spinner .Stop ()
30
30
31
31
var err error
32
- var images [] string
32
+ var images k8s. ImageNodeMap
33
33
var envVars []corev1.EnvVar
34
34
var payloadConfigmaps []string
35
35
var sha256sum string
@@ -72,19 +72,19 @@ func runInjectionMadness(tempPath tempPaths) {
72
72
zarfImageRegex := regexp .MustCompile (`(?m)^127\.0\.0\.1:` )
73
73
74
74
// Try to create an injector pod using an existing image in the cluster
75
- for _ , image := range images {
75
+ for image , node := range images {
76
76
// Don't try to run against the seed image if this is a secondary zarf init run
77
77
if zarfImageRegex .MatchString (image ) {
78
78
continue
79
79
}
80
80
81
- spinner .Updatef ("Attempting to bootstrap with the %s" , image )
81
+ spinner .Updatef ("Attempting to bootstrap with the %s/%s" , node , image )
82
82
83
83
// Make sure the pod is not there first
84
84
_ = k8s .DeletePod (k8s .ZarfNamespace , "injector" )
85
85
86
- // Update the podspec image path
87
- pod := buildInjectionPod (image , envVars , payloadConfigmaps , sha256sum )
86
+ // Update the podspec image path and use the first node found
87
+ pod := buildInjectionPod (node [ 0 ], image , envVars , payloadConfigmaps , sha256sum )
88
88
89
89
// Create the pod in the cluster
90
90
pod , err = k8s .CreatePod (pod )
@@ -177,8 +177,8 @@ func createPayloadConfigmaps(tempPath tempPaths, spinner *message.Spinner) ([]st
177
177
// Add the configmap to the configmaps slice for later usage in the pod
178
178
configMaps = append (configMaps , fileName )
179
179
180
- // Give the control plane a slight buffeer
181
- time .Sleep (100 * time .Millisecond )
180
+ // Give the control plane a 250ms buffer between each configmap
181
+ time .Sleep (250 * time .Millisecond )
182
182
}
183
183
184
184
return configMaps , sha256sum , nil
@@ -301,21 +301,30 @@ func buildEnvVars(tempPath tempPaths) ([]corev1.EnvVar, error) {
301
301
}
302
302
303
303
// buildInjectionPod return a pod for injection with the appropriate containers to perform the injection
304
- func buildInjectionPod (image string , envVars []corev1.EnvVar , payloadConfigmaps []string , payloadShasum string ) * corev1.Pod {
304
+ func buildInjectionPod (node , image string , envVars []corev1.EnvVar , payloadConfigmaps []string , payloadShasum string ) * corev1.Pod {
305
305
pod := k8s .GeneratePod ("injector" , k8s .ZarfNamespace )
306
306
executeMode := int32 (0777 )
307
307
seedImage := config .GetSeedImage ()
308
308
309
309
pod .Labels ["app" ] = "zarf-injector"
310
310
311
+ // Bind the pod to the node the image was found on
312
+ pod .Spec .NodeSelector = map [string ]string {"kubernetes.io/hostname" : node }
313
+
314
+ // Do not try to restart the pod as it will be deleted/re-created instead
311
315
pod .Spec .RestartPolicy = corev1 .RestartPolicyNever
316
+
317
+ // Init container used to combine and decompress the split tarball into the stage2 directory for use in the main container
312
318
pod .Spec .InitContainers = []corev1.Container {
313
319
{
314
- Name : "init-injector" ,
315
- Image : image ,
316
- ImagePullPolicy : corev1 .PullNever ,
317
- WorkingDir : "/zarf-stage1" ,
318
- Command : []string {"/zarf-stage1/zarf-injector" , payloadShasum },
320
+ Name : "init-injector" ,
321
+ // An existing image already present on the cluster
322
+ Image : image ,
323
+ // PullIfNotPresent because some distros provide a way (even in airgap) to pull images from local or direct-connected registries
324
+ ImagePullPolicy : corev1 .PullIfNotPresent ,
325
+ // This directory is filled via the configmap injections
326
+ WorkingDir : "/zarf-stage1" ,
327
+ Command : []string {"/zarf-stage1/zarf-injector" , payloadShasum },
319
328
320
329
VolumeMounts : []corev1.VolumeMount {
321
330
{
@@ -329,6 +338,7 @@ func buildInjectionPod(image string, envVars []corev1.EnvVar, payloadConfigmaps
329
338
},
330
339
},
331
340
341
+ // Keep resources as light as possible as we aren't actually running the container's other binaries
332
342
Resources : corev1.ResourceRequirements {
333
343
Requests : corev1.ResourceList {
334
344
corev1 .ResourceCPU : resource .MustParse (".5" ),
@@ -344,26 +354,32 @@ func buildInjectionPod(image string, envVars []corev1.EnvVar, payloadConfigmaps
344
354
},
345
355
}
346
356
357
+ // Container definition for the injector pod
347
358
pod .Spec .Containers = []corev1.Container {
348
359
{
349
- Name : "injector" ,
350
- Image : image ,
351
- ImagePullPolicy : corev1 .PullNever ,
352
- WorkingDir : "/zarf-stage2" ,
360
+ Name : "injector" ,
361
+ // An existing image already present on the cluster
362
+ Image : image ,
363
+ // PullIfNotPresent because some distros provide a way (even in airgap) to pull images from local or direct-connected registries
364
+ ImagePullPolicy : corev1 .PullIfNotPresent ,
365
+ // This directory's contents come from the init container output
366
+ WorkingDir : "/zarf-stage2" ,
353
367
Command : []string {
354
368
"/zarf-stage2/zarf-registry" ,
355
369
"/zarf-stage2/seed-image.tar" ,
356
370
seedImage ,
357
371
utils .SwapHost (seedImage , "127.0.0.1:5001" ),
358
372
},
359
373
374
+ // Shared mount between the init and regular containers
360
375
VolumeMounts : []corev1.VolumeMount {
361
376
{
362
377
Name : "stage2" ,
363
378
MountPath : "/zarf-stage2" ,
364
379
},
365
380
},
366
381
382
+ // Keep resources as light as possible as we aren't actually running the container's other binaries
367
383
Resources : corev1.ResourceRequirements {
368
384
Requests : corev1.ResourceList {
369
385
corev1 .ResourceCPU : resource .MustParse (".5" ),
@@ -380,7 +396,7 @@ func buildInjectionPod(image string, envVars []corev1.EnvVar, payloadConfigmaps
380
396
}
381
397
382
398
pod .Spec .Volumes = []corev1.Volume {
383
- // Bin volume hosts the injector binary and init script
399
+ // Stage1 contains the rust binary and collection of configmaps from the tarball (go binary + seed image)
384
400
{
385
401
Name : "stage1" ,
386
402
VolumeSource : corev1.VolumeSource {
@@ -392,6 +408,7 @@ func buildInjectionPod(image string, envVars []corev1.EnvVar, payloadConfigmaps
392
408
},
393
409
},
394
410
},
411
+ // Stage2 is an emtpy directory shared between the containers
395
412
{
396
413
Name : "stage2" ,
397
414
VolumeSource : corev1.VolumeSource {
@@ -402,6 +419,7 @@ func buildInjectionPod(image string, envVars []corev1.EnvVar, payloadConfigmaps
402
419
403
420
// Iterate over all the payload configmaps and add their mounts
404
421
for _ , filename := range payloadConfigmaps {
422
+ // Create the configmap volume from the given filename
405
423
pod .Spec .Volumes = append (pod .Spec .Volumes , corev1.Volume {
406
424
Name : filename ,
407
425
VolumeSource : corev1.VolumeSource {
@@ -413,6 +431,7 @@ func buildInjectionPod(image string, envVars []corev1.EnvVar, payloadConfigmaps
413
431
},
414
432
})
415
433
434
+ // Create the volume mount to place the new volume in the stage1 directory
416
435
pod .Spec .InitContainers [0 ].VolumeMounts = append (pod .Spec .InitContainers [0 ].VolumeMounts , corev1.VolumeMount {
417
436
Name : filename ,
418
437
MountPath : fmt .Sprintf ("/zarf-stage1/%s" , filename ),
0 commit comments