Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readd mounting volumes in workingdir #1609

Merged
merged 1 commit into from
Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}
21 changes: 15 additions & 6 deletions pkg/pod/workingdir_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ import (
const shellImage = "shell-image"

func TestWorkingDirInit(t *testing.T) {
volumeMounts := []corev1.VolumeMount{{
chmouel marked this conversation as resolved.
Show resolved Hide resolved
Name: "workspace",
MountPath: "/workspace",
}, {
Name: "home",
MountPath: "/builder/home",
}}

names.TestingSeed()
for _, c := range []struct {
desc string
Expand Down Expand Up @@ -57,11 +65,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 +85,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
11 changes: 6 additions & 5 deletions pkg/reconciler/taskrun/resources/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,12 @@ func TestMakePod(t *testing.T) {
want: &corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: []corev1.Container{{
Name: "working-dir-initializer-9l9zj",
Image: shellImage,
Command: []string{"sh"},
Args: []string{"-c", fmt.Sprintf("mkdir -p %s", filepath.Join(workspaceDir, "test"))},
WorkingDir: workspaceDir,
Name: "working-dir-initializer-9l9zj",
Image: shellImage,
Command: []string{"sh"},
Args: []string{"-c", fmt.Sprintf("mkdir -p %s", filepath.Join(workspaceDir, "test"))},
WorkingDir: workspaceDir,
VolumeMounts: implicitVolumeMounts,
}},
Containers: []corev1.Container{{
Name: "step-name",
Expand Down