Skip to content

Fix PVC volume config generation in Kubernetes executor

What does this MR do?

This MR fixes volume config generation - in case that a single PVC is mounted multiple times, the current GitLab Runner version generates Pod config with duplicate volumes which causes duplicate value errors.

This MR also removes ReadOnly flag from the volume config so that it is possible to mount different paths from a single PVC and configure a different ReadOnly flag for each mount. The ReadOnly flag is set on VolumeMounts so it is not necessary to set it on Volumes.

Why was this MR needed?

Because the current GitLab Runner generates invalid Pod config when a single PVC is mounted multiple times.

What's the best way to test this MR?

Configure GitLab Runner to mount single PVC to multiple mount paths:

[[runners.kubernetes.volumes.pvc]]
name = "pvc"
sub_path = "foo"
mount_path = "/mnt/foo
read_only = true
[[runners.kubernetes.volumes.pvc]]
name = "pvc"
sub_path = "bar"
mount_path = "/mnt/bar"
read_only = false

The current GitLab Runner version generates Pod config with duplicate volumes which causes error:

ERROR: Job failed (system failure): prepare environment: setting up build pod: Pod "runner-2jxgyndb-project-304-concurrent-0q5kbj" is invalid: [spec.volumes[2].name: Duplicate value: "pvc", spec.volumes[3].name: Duplicate value: "pvc", spec.volumes[5].name: Duplicate value: "pvc"]. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

What are the relevant issue numbers?

#28088 - There is the same problem with ConfigMaps which probably has the same cause.

Edited by Romuald Atchadé

Merge request reports