Skip to content

Commit b97462e

Browse files
committed
Don't add projects volumeMount if container mounts it manually
This avoids an issue where a container can mount the projects volume directly and have `mountSources: true`, which results in a duplicate mount and invalid deployment. Related to issue devfile/api#290 and how projects volume should be handled with `mountSources`. Signed-off-by: Angel Misevski <[email protected]>
1 parent de41d08 commit b97462e

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

pkg/library/container/mountSources.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,23 @@ func handleMountSources(k8sContainer *corev1.Container, devfileContainer *devwor
4040
if !HasMountSources(devfileContainer) {
4141
return
4242
}
43-
sourceMapping := devfileContainer.SourceMapping
43+
var sourceMapping string
44+
if vm := getProjectsVolumeMount(k8sContainer); vm != nil {
45+
// Container already mounts projects volume; need to set env vars according to mountPath
46+
// TODO: see issue https://github.com/devfile/api/issues/290
47+
sourceMapping = vm.MountPath
48+
} else {
49+
k8sContainer.VolumeMounts = append(k8sContainer.VolumeMounts, corev1.VolumeMount{
50+
Name: constants.ProjectsVolumeName,
51+
MountPath: sourceMapping,
52+
})
53+
sourceMapping = devfileContainer.SourceMapping
54+
}
4455
if sourceMapping == "" {
4556
// Sanity check -- this value should be defaulted to `/projects` but may not be
4657
// if struct was not processed by k8s
4758
sourceMapping = config.DefaultProjectsSourcesRoot
4859
}
49-
k8sContainer.VolumeMounts = append(k8sContainer.VolumeMounts, corev1.VolumeMount{
50-
Name: constants.ProjectsVolumeName,
51-
MountPath: sourceMapping,
52-
})
5360
k8sContainer.Env = append(k8sContainer.Env, corev1.EnvVar{
5461
Name: constants.ProjectsRootEnvVar,
5562
Value: sourceMapping,
@@ -58,3 +65,14 @@ func handleMountSources(k8sContainer *corev1.Container, devfileContainer *devwor
5865
Value: sourceMapping, // TODO: Unclear how this should be handled in case of multiple projects
5966
})
6067
}
68+
69+
// getProjectsVolumeMount returns the projects volumeMount in a container, if it is defined; if it does not exist,
70+
// returns nil.
71+
func getProjectsVolumeMount(k8sContainer *corev1.Container) *corev1.VolumeMount {
72+
for _, vm := range k8sContainer.VolumeMounts {
73+
if vm.Name == constants.ProjectsVolumeName {
74+
return &vm
75+
}
76+
}
77+
return nil
78+
}

0 commit comments

Comments
 (0)