@@ -409,49 +409,55 @@ func isNotRestartAlwaysMirrorPod(p *v1.Pod) bool {
409
409
return p .Spec .RestartPolicy != v1 .RestartPolicyAlways
410
410
}
411
411
412
- // NewExecPodSpec returns the pod spec of hostexec pod
413
- func NewExecPodSpec (ns , name string , hostNetwork bool ) * v1.Pod {
412
+ // NewAgnhostPod returns a pod that uses the agnhost image. The image's binary supports various subcommands
413
+ // that behave the same, no matter the underlying OS. If no args are given, it defaults to the pause subcommand.
414
+ // For more information about agnhost subcommands, see: https://github.com/kubernetes/kubernetes/tree/master/test/images/agnhost#agnhost
415
+ func NewAgnhostPod (ns , podName string , volumes []v1.Volume , mounts []v1.VolumeMount , ports []v1.ContainerPort , args ... string ) * v1.Pod {
414
416
immediate := int64 (0 )
415
417
pod := & v1.Pod {
416
418
ObjectMeta : metav1.ObjectMeta {
417
- Name : name ,
419
+ Name : podName ,
418
420
Namespace : ns ,
419
421
},
420
422
Spec : v1.PodSpec {
421
423
Containers : []v1.Container {
422
- {
423
- Name : "agnhost" ,
424
- Image : imageutils .GetE2EImage (imageutils .Agnhost ),
425
- ImagePullPolicy : v1 .PullIfNotPresent ,
426
- },
424
+ NewAgnhostContainer ("agnhost-container" , mounts , ports , args ... ),
427
425
},
428
- HostNetwork : hostNetwork ,
426
+ Volumes : volumes ,
429
427
SecurityContext : & v1.PodSecurityContext {},
430
428
TerminationGracePeriodSeconds : & immediate ,
431
429
},
432
430
}
433
431
return pod
434
432
}
435
433
434
+ // NewAgnhostContainer returns the container Spec of an agnhost container.
435
+ func NewAgnhostContainer (containerName string , mounts []v1.VolumeMount , ports []v1.ContainerPort , args ... string ) v1.Container {
436
+ if len (args ) == 0 {
437
+ args = []string {"pause" }
438
+ }
439
+ return v1.Container {
440
+ Name : containerName ,
441
+ Image : imageutils .GetE2EImage (imageutils .Agnhost ),
442
+ Args : args ,
443
+ VolumeMounts : mounts ,
444
+ Ports : ports ,
445
+ SecurityContext : & v1.SecurityContext {},
446
+ ImagePullPolicy : v1 .PullIfNotPresent ,
447
+ }
448
+ }
449
+
450
+ // NewExecPodSpec returns the pod spec of hostexec pod
451
+ func NewExecPodSpec (ns , name string , hostNetwork bool ) * v1.Pod {
452
+ pod := NewAgnhostPod (ns , name , nil , nil , nil )
453
+ pod .Spec .HostNetwork = hostNetwork
454
+ return pod
455
+ }
456
+
436
457
// newExecPodSpec returns the pod spec of exec pod
437
458
func newExecPodSpec (ns , generateName string ) * v1.Pod {
438
- immediate := int64 (0 )
439
- pod := & v1.Pod {
440
- ObjectMeta : metav1.ObjectMeta {
441
- GenerateName : generateName ,
442
- Namespace : ns ,
443
- },
444
- Spec : v1.PodSpec {
445
- TerminationGracePeriodSeconds : & immediate ,
446
- Containers : []v1.Container {
447
- {
448
- Name : "agnhost-pause" ,
449
- Image : imageutils .GetE2EImage (imageutils .Agnhost ),
450
- Args : []string {"pause" },
451
- },
452
- },
453
- },
454
- }
459
+ pod := NewAgnhostPod (ns , "agnhost-pod" , nil , nil , nil )
460
+ pod .ObjectMeta .GenerateName = generateName
455
461
return pod
456
462
}
457
463
0 commit comments