Skip to content

Commit

Permalink
Readd mounting volumes in workingdir
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
chmouel committed Nov 23, 2019
1 parent c9a7a35 commit f5cff36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
13 changes: 7 additions & 6 deletions pkg/pod/workingdir_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
// TODO(jasonhall): This should take []corev1.Container instead of
// []corev1.Step, but this makes it easier to use in pod.go. When pod.go is
// cleaned up, this can take []corev1.Container.
func WorkingDirInit(shellImage string, steps []v1alpha1.Step) *corev1.Container {
func WorkingDirInit(shellImage string, steps []v1alpha1.Step, volumeMounts []corev1.VolumeMount) *corev1.Container {
// Gather all unique workingDirs.
workingDirs := map[string]struct{}{}
for _, step := range steps {
Expand Down Expand Up @@ -75,10 +75,11 @@ func WorkingDirInit(shellImage string, steps []v1alpha1.Step) *corev1.Container
}

return &corev1.Container{
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(workingDirInit),
Image: shellImage,
Command: []string{"sh"},
Args: []string{"-c", "mkdir -p " + strings.Join(relativeDirs, " ")},
WorkingDir: workspaceDir,
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(workingDirInit),
Image: shellImage,
Command: []string{"sh"},
Args: []string{"-c", "mkdir -p " + strings.Join(relativeDirs, " ")},
WorkingDir: workspaceDir,
VolumeMounts: volumeMounts,
}
}
18 changes: 12 additions & 6 deletions pkg/pod/workingdir_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import (
const shellImage = "shell-image"

func TestWorkingDirInit(t *testing.T) {
volumeMounts := []corev1.VolumeMount{{
Name: "workspace",
MountPath: "/workspace",
}}

names.TestingSeed()
for _, c := range []struct {
desc string
Expand Down Expand Up @@ -57,11 +62,12 @@ func TestWorkingDirInit(t *testing.T) {
WorkingDir: "/workspace/bbb",
}},
want: &corev1.Container{
Name: "working-dir-initializer-9l9zj",
Image: shellImage,
Command: []string{"sh"},
Args: []string{"-c", "mkdir -p /workspace/bbb aaa zzz"},
WorkingDir: workspaceDir,
Name: "working-dir-initializer-9l9zj",
Image: shellImage,
Command: []string{"sh"},
Args: []string{"-c", "mkdir -p /workspace/bbb aaa zzz"},
WorkingDir: workspaceDir,
VolumeMounts: volumeMounts,
},
}} {
t.Run(c.desc, func(t *testing.T) {
Expand All @@ -76,7 +82,7 @@ func TestWorkingDirInit(t *testing.T) {
steps = append(steps, v1alpha1.Step{Container: c})
}

got := WorkingDirInit(shellImage, steps)
got := WorkingDirInit(shellImage, steps, volumeMounts)
if d := cmp.Diff(c.want, got); d != "" {
t.Fatalf("Diff (-want, +got): %s", d)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/taskrun/resources/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func MakePod(images pipeline.Images, taskRun *v1alpha1.TaskRun, taskSpec v1alpha
volumes = append(volumes, secretsVolumes...)
}

if workingDirInit := pod.WorkingDirInit(images.ShellImage, taskSpec.Steps); workingDirInit != nil {
if workingDirInit := pod.WorkingDirInit(images.ShellImage, taskSpec.Steps, implicitVolumeMounts); workingDirInit != nil {
initContainers = append(initContainers, *workingDirInit)
}

Expand Down

0 comments on commit f5cff36

Please sign in to comment.