Skip to content

Commit f5cff36

Browse files
committed
Readd mounting volumes in workingdir
Mounting volume was dropped when we did the large refactoring in d7f492c which basically making it ineffective and fails when not running as root. Readding it in there Closes #1608 Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent c9a7a35 commit f5cff36

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

pkg/pod/workingdir_init.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const (
4141
// TODO(jasonhall): This should take []corev1.Container instead of
4242
// []corev1.Step, but this makes it easier to use in pod.go. When pod.go is
4343
// cleaned up, this can take []corev1.Container.
44-
func WorkingDirInit(shellImage string, steps []v1alpha1.Step) *corev1.Container {
44+
func WorkingDirInit(shellImage string, steps []v1alpha1.Step, volumeMounts []corev1.VolumeMount) *corev1.Container {
4545
// Gather all unique workingDirs.
4646
workingDirs := map[string]struct{}{}
4747
for _, step := range steps {
@@ -75,10 +75,11 @@ func WorkingDirInit(shellImage string, steps []v1alpha1.Step) *corev1.Container
7575
}
7676

7777
return &corev1.Container{
78-
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(workingDirInit),
79-
Image: shellImage,
80-
Command: []string{"sh"},
81-
Args: []string{"-c", "mkdir -p " + strings.Join(relativeDirs, " ")},
82-
WorkingDir: workspaceDir,
78+
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(workingDirInit),
79+
Image: shellImage,
80+
Command: []string{"sh"},
81+
Args: []string{"-c", "mkdir -p " + strings.Join(relativeDirs, " ")},
82+
WorkingDir: workspaceDir,
83+
VolumeMounts: volumeMounts,
8384
}
8485
}

pkg/pod/workingdir_init_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import (
2828
const shellImage = "shell-image"
2929

3030
func TestWorkingDirInit(t *testing.T) {
31+
volumeMounts := []corev1.VolumeMount{{
32+
Name: "workspace",
33+
MountPath: "/workspace",
34+
}}
35+
3136
names.TestingSeed()
3237
for _, c := range []struct {
3338
desc string
@@ -57,11 +62,12 @@ func TestWorkingDirInit(t *testing.T) {
5762
WorkingDir: "/workspace/bbb",
5863
}},
5964
want: &corev1.Container{
60-
Name: "working-dir-initializer-9l9zj",
61-
Image: shellImage,
62-
Command: []string{"sh"},
63-
Args: []string{"-c", "mkdir -p /workspace/bbb aaa zzz"},
64-
WorkingDir: workspaceDir,
65+
Name: "working-dir-initializer-9l9zj",
66+
Image: shellImage,
67+
Command: []string{"sh"},
68+
Args: []string{"-c", "mkdir -p /workspace/bbb aaa zzz"},
69+
WorkingDir: workspaceDir,
70+
VolumeMounts: volumeMounts,
6571
},
6672
}} {
6773
t.Run(c.desc, func(t *testing.T) {
@@ -76,7 +82,7 @@ func TestWorkingDirInit(t *testing.T) {
7682
steps = append(steps, v1alpha1.Step{Container: c})
7783
}
7884

79-
got := WorkingDirInit(shellImage, steps)
85+
got := WorkingDirInit(shellImage, steps, volumeMounts)
8086
if d := cmp.Diff(c.want, got); d != "" {
8187
t.Fatalf("Diff (-want, +got): %s", d)
8288
}

pkg/reconciler/taskrun/resources/pod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func MakePod(images pipeline.Images, taskRun *v1alpha1.TaskRun, taskSpec v1alpha
120120
volumes = append(volumes, secretsVolumes...)
121121
}
122122

123-
if workingDirInit := pod.WorkingDirInit(images.ShellImage, taskSpec.Steps); workingDirInit != nil {
123+
if workingDirInit := pod.WorkingDirInit(images.ShellImage, taskSpec.Steps, implicitVolumeMounts); workingDirInit != nil {
124124
initContainers = append(initContainers, *workingDirInit)
125125
}
126126

0 commit comments

Comments
 (0)