Allow disabling /runner emptydir mounts and setting storage volume (#674)

* Allow disabling /runner emptydir mounts

* Support defining storage medium for emptydirs

* Fix typos
This commit is contained in:
Rolf Ahrenberg
2021-07-15 00:29:58 +03:00
committed by GitHub
parent 7f2795b5d6
commit 14564c7b8e
13 changed files with 58 additions and 18 deletions

View File

@@ -886,32 +886,49 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
// When you're NOT using dindWithinRunner=true,
// it must also be shared with the dind container as it seems like required to run docker steps.
//
// Setting VolumeSizeLimit to zero will disable /runner emptydir mount
//
// VolumeStorageMedium defines ways that storage can be allocated to a volume: "", "Memory", "HugePages", "HugePages-<size>"
//
runnerVolumeName := "runner"
runnerVolumeMountPath := "/runner"
runnerVolumeEmptyDir := &corev1.EmptyDirVolumeSource{}
if runnerSpec.VolumeStorageMedium != nil {
runnerVolumeEmptyDir.Medium = corev1.StorageMedium(*runnerSpec.VolumeStorageMedium)
}
if runnerSpec.VolumeSizeLimit != nil {
runnerVolumeEmptyDir.SizeLimit = runnerSpec.VolumeSizeLimit
}
pod.Spec.Volumes = append(pod.Spec.Volumes,
corev1.Volume{
Name: runnerVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: runnerVolumeEmptyDir,
if runnerSpec.VolumeSizeLimit == nil || !runnerSpec.VolumeSizeLimit.IsZero() {
pod.Spec.Volumes = append(pod.Spec.Volumes,
corev1.Volume{
Name: runnerVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: runnerVolumeEmptyDir,
},
},
},
)
)
runnerContainer.VolumeMounts = append(runnerContainer.VolumeMounts,
corev1.VolumeMount{
Name: runnerVolumeName,
MountPath: runnerVolumeMountPath,
},
)
runnerContainer.VolumeMounts = append(runnerContainer.VolumeMounts,
corev1.VolumeMount{
Name: runnerVolumeName,
MountPath: runnerVolumeMountPath,
},
)
}
if !dockerdInRunner && dockerEnabled {
if runnerSpec.VolumeSizeLimit != nil && runnerSpec.VolumeSizeLimit.IsZero() {
return *pod, fmt.Errorf(
"%s volume can't be disabled because it is required to share the working directory between the runner and the dockerd containers",
runnerVolumeName,
)
}
pod.Spec.Volumes = append(pod.Spec.Volumes,
corev1.Volume{
Name: "work",