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

Move workingDir initialization after script conversion #1644

Merged
merged 1 commit into from
Nov 29, 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
10 changes: 5 additions & 5 deletions pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ func MakePod(images pipeline.Images, taskRun *v1alpha1.TaskRun, taskSpec v1alpha
volumes = append(volumes, secretsVolumes...)
}

// Initialize any workingDirs under /workspace.
if workingDirInit := workingDirInit(images.ShellImage, taskSpec.Steps, implicitVolumeMounts); workingDirInit != nil {
initContainers = append(initContainers, *workingDirInit)
}

// Merge step template with steps.
// TODO(#1605): Move MergeSteps to pkg/pod
steps, err := v1alpha1.MergeStepsWithStepTemplate(taskSpec.StepTemplate, taskSpec.Steps)
Expand All @@ -121,6 +116,11 @@ func MakePod(images pipeline.Images, taskRun *v1alpha1.TaskRun, taskSpec v1alpha
volumes = append(volumes, scriptsVolume)
}

// Initialize any workingDirs under /workspace.
if workingDirInit := workingDirInit(images.ShellImage, stepContainers, implicitVolumeMounts); workingDirInit != nil {
initContainers = append(initContainers, *workingDirInit)
}

// Resolve entrypoint for any steps that don't specify command.
stepContainers, err = resolveEntrypoints(entrypointCache, taskRun.Namespace, taskRun.Spec.ServiceAccountName, stepContainers)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func TestMakePod(t *testing.T) {
want: &corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: []corev1.Container{{
Name: "working-dir-initializer-9l9zj",
Name: "working-dir-initializer-mz4c7",
Image: images.ShellImage,
Command: []string{"sh"},
Args: []string{"-c", fmt.Sprintf("mkdir -p %s", filepath.Join(workspaceDir, "test"))},
Expand Down
9 changes: 2 additions & 7 deletions pkg/pod/workingdir_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"sort"
"strings"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/names"
corev1 "k8s.io/api/core/v1"
)
Expand All @@ -32,14 +31,10 @@ import (
//
// If no such directories need to be created (i.e., no relative workingDirs
// are specified), this method returns nil, as no init container is necessary.
//
// TODO(#1605): 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, volumeMounts []corev1.VolumeMount) *corev1.Container {
func workingDirInit(shellImage string, stepContainers []corev1.Container, volumeMounts []corev1.VolumeMount) *corev1.Container {
// Gather all unique workingDirs.
workingDirs := map[string]struct{}{}
for _, step := range steps {
for _, step := range stepContainers {
if step.WorkingDir != "" {
workingDirs[step.WorkingDir] = struct{}{}
}
Expand Down
14 changes: 1 addition & 13 deletions pkg/pod/workingdir_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/test/names"
corev1 "k8s.io/api/core/v1"
)
Expand Down Expand Up @@ -69,18 +68,7 @@ func TestWorkingDirInit(t *testing.T) {
},
}} {
t.Run(c.desc, func(t *testing.T) {
// TODO(#1605): WorkingDirInit should take
// Containers instead of Steps, but while we're
// cleaning up pod.go it's easier to have it take
// Steps. This test doesn't care, so let's hide this
// conversion in the test where it's easier to remove
// later.
var steps []v1alpha1.Step
for _, c := range c.stepContainers {
steps = append(steps, v1alpha1.Step{Container: c})
}

got := workingDirInit(images.ShellImage, steps, volumeMounts)
got := workingDirInit(images.ShellImage, c.stepContainers, volumeMounts)
if d := cmp.Diff(c.want, got); d != "" {
t.Fatalf("Diff (-want, +got): %s", d)
}
Expand Down