Skip to content

Commit

Permalink
Remove index usage in create and copy resource containers 🎛
Browse files Browse the repository at this point in the history
A random suffix is generated for the name of the pod, so we don't need
to add the index as part of the name to make sure they are unique.

Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester authored and knative-prow-robot committed Feb 28, 2019
1 parent 5813d84 commit 19dbd0d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
16 changes: 8 additions & 8 deletions pkg/reconciler/v1alpha1/taskrun/resources/input_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ func TestAddResourceToBuild(t *testing.T) {
wantErr: false,
want: buildv1alpha1.BuildSpec{
Steps: []corev1.Container{{
Name: "create-dir-gitspace-0-0-mz4c7",
Name: "create-dir-gitspace-mz4c7",
Image: "override-with-bash-noop:latest",
Args: []string{"-args", "mkdir -p /workspace/gitspace"},
}, {
Name: "source-copy-gitspace-0-9l9zj",
Name: "source-copy-gitspace-9l9zj",
Image: "override-with-bash-noop:latest",
Args: []string{"-args", "cp -r prev-task-path/. /workspace/gitspace"},
VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}},
Expand Down Expand Up @@ -522,11 +522,11 @@ func TestAddResourceToBuild(t *testing.T) {
wantErr: false,
want: buildv1alpha1.BuildSpec{
Steps: []corev1.Container{{
Name: "create-dir-workspace-0-0-mz4c7",
Name: "create-dir-workspace-mz4c7",
Image: "override-with-bash-noop:latest",
Args: []string{"-args", "mkdir -p /workspace/gcs-dir"},
}, {
Name: "source-copy-workspace-0-9l9zj",
Name: "source-copy-workspace-9l9zj",
Image: "override-with-bash-noop:latest",
Args: []string{"-args", "cp -r prev-task-path/. /workspace/gcs-dir"},
VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}},
Expand Down Expand Up @@ -1023,11 +1023,11 @@ func TestAddStepsToBuild_WithBucketFromConfigMap(t *testing.T) {
build: build(),
want: buildv1alpha1.BuildSpec{
Steps: []corev1.Container{{
Name: "artifact-dest-mkdir-gitspace-0-mssqb",
Name: "artifact-dest-mkdir-gitspace-mssqb",
Image: "override-with-bash-noop:latest",
Args: []string{"-args", "mkdir -p /workspace/gitspace"},
}, {
Name: "artifact-copy-from-gitspace-0-78c5n",
Name: "artifact-copy-from-gitspace-78c5n",
Image: "override-with-gsutil-image:latest",
Args: []string{"-args", "cp -r gs://fake-bucket/prev-task-path/** /workspace/gitspace"},
}},
Expand Down Expand Up @@ -1059,11 +1059,11 @@ func TestAddStepsToBuild_WithBucketFromConfigMap(t *testing.T) {
build: build(),
want: buildv1alpha1.BuildSpec{
Steps: []corev1.Container{{
Name: "artifact-dest-mkdir-workspace-0-6nl7g",
Name: "artifact-dest-mkdir-workspace-6nl7g",
Image: "override-with-bash-noop:latest",
Args: []string{"-args", "mkdir -p /workspace/gcs-dir"},
}, {
Name: "artifact-copy-from-workspace-0-j2tds",
Name: "artifact-copy-from-workspace-j2tds",
Image: "override-with-gsutil-image:latest",
Args: []string{"-args", "cp -r gs://fake-bucket/prev-task-path/** /workspace/gcs-dir"},
}},
Expand Down
9 changes: 4 additions & 5 deletions pkg/reconciler/v1alpha1/taskrun/resources/input_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ func AddInputResource(
// if taskrun is fetching resource from previous task then execute copy step instead of fetching new copy
// to the desired destination directory, as long as the resource exports output to be copied
if allowedOutputResources[resource.Spec.Type] && taskRun.HasPipelineRunOwnerReference() {
for i, path := range boundResource.Paths {
cpContainers := as.GetCopyFromContainerSpec(fmt.Sprintf("%s-%d", boundResource.Name, i), path, dPath)
for _, path := range boundResource.Paths {
cpContainers := as.GetCopyFromContainerSpec(boundResource.Name, path, dPath)
if as.GetType() == v1alpha1.ArtifactStoragePVCType {

mountPVC = true
for j, ct := range cpContainers {
for _, ct := range cpContainers {
ct.VolumeMounts = []corev1.VolumeMount{getPvcMount(pvcName)}
name := fmt.Sprintf("%s-%d-%d", boundResource.Name, i, j)
createAndCopyContainers := []corev1.Container{v1alpha1.CreateDirContainer(name, dPath), ct}
createAndCopyContainers := []corev1.Container{v1alpha1.CreateDirContainer(boundResource.Name, dPath), ct}
copyStepsFromPrevTasks = append(copyStepsFromPrevTasks, createAndCopyContainers...)
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions pkg/reconciler/v1alpha1/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,29 +405,29 @@ func TestReconcile(t *testing.T) {
tb.PodRestartPolicy(corev1.RestartPolicyNever),
tb.PodContainer("nop", "override-with-nop:latest"),
getCredentialsInitContainer("vr6ds"),
tb.PodInitContainer("build-step-create-dir-another-git-resource-0-0-78c5n", "override-with-bash-noop:latest",
tb.PodInitContainer("build-step-create-dir-another-git-resource-78c5n", "override-with-bash-noop:latest",
tb.Args("-args", "mkdir -p /workspace/another-git-resource"),
tb.WorkingDir(workspaceDir),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodInitContainer("build-step-source-copy-another-git-resource-0-mssqb", "override-with-bash-noop:latest",
tb.PodInitContainer("build-step-source-copy-another-git-resource-mssqb", "override-with-bash-noop:latest",
tb.Args("-args", "cp -r source-folder/. /workspace/another-git-resource"),
tb.WorkingDir(workspaceDir),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("test-pvc", "/pvc"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodInitContainer("build-step-create-dir-git-resource-0-0-mz4c7", "override-with-bash-noop:latest",
tb.PodInitContainer("build-step-create-dir-git-resource-mz4c7", "override-with-bash-noop:latest",
tb.Args("-args", "mkdir -p /workspace/git-resource"),
tb.WorkingDir(workspaceDir),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodInitContainer("build-step-source-copy-git-resource-0-9l9zj", "override-with-bash-noop:latest",
tb.PodInitContainer("build-step-source-copy-git-resource-9l9zj", "override-with-bash-noop:latest",
tb.Args("-args", "cp -r source-folder/. /workspace/git-resource"),
tb.WorkingDir(workspaceDir),
tb.EnvVar("HOME", "/builder/home"),
Expand Down

0 comments on commit 19dbd0d

Please sign in to comment.