Skip to content

Commit

Permalink
Plumb the "TEKTON_RESOURCE_NAME" environment variable into more resou…
Browse files Browse the repository at this point in the history
…rce containers.

As part of TEP-0025 (hermetic builds), we need to know which containers/steps are part
of the "Tekton system" and which ones are part of the Task definition. This PR adds
the TEKTON_RESOURCE_NAME environment variable to the injected copy containers.

This variable is already used by several of the existing resources (git, image).
  • Loading branch information
Dan Lorenc authored and tekton-robot committed Nov 17, 2020
1 parent 5ed55aa commit 6bb399a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/apis/resource/v1alpha1/storage/artifact_pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func (p *ArtifactPVC) GetCopyFromStorageToSteps(name, sourcePath, destinationPat
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("source-copy-%s", name)),
Image: p.ShellImage,
Command: []string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath},
Env: []corev1.EnvVar{{
Name: "TEKTON_RESOURCE_NAME",
Value: name,
}},
}}}
}

Expand All @@ -69,6 +73,10 @@ func (p *ArtifactPVC) GetCopyToStorageFromSteps(name, sourcePath, destinationPat
Image: p.ShellImage,
Command: []string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath},
VolumeMounts: []corev1.VolumeMount{GetPvcMount(p.Name)},
Env: []corev1.EnvVar{{
Name: "TEKTON_RESOURCE_NAME",
Value: name,
}},
}}}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestPVCGetCopyFromContainerSpec(t *testing.T) {
Image: "busybox",

Command: []string{"cp", "-r", "src-path/.", "/workspace/destination"},
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "workspace"}},
}}}

got := pvc.GetCopyFromStorageToSteps("workspace", "src-path", "/workspace/destination")
Expand All @@ -65,6 +66,7 @@ func TestPVCGetCopyToContainerSpec(t *testing.T) {
Image: "busybox",
Command: []string{"cp", "-r", "src-path/.", "/workspace/destination"},
VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}},
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "workspace"}},
}}}

got := pvc.GetCopyToStorageFromSteps("workspace", "src-path", "/workspace/destination")
Expand Down
2 changes: 2 additions & 0 deletions pkg/reconciler/taskrun/resources/input_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ func TestAddInputResourceToTask(t *testing.T) {
Image: "busybox",
Command: []string{"cp", "-r", "prev-task-path/.", "/workspace/gitspace"},
VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}},
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "gitspace"}},
}}},
Volumes: []corev1.Volume{{
Name: "pipelinerun-pvc",
Expand Down Expand Up @@ -727,6 +728,7 @@ gsutil cp gs://fake-bucket/rules.zip /workspace/gcs-dir
Image: "busybox",
Command: []string{"cp", "-r", "prev-task-path/.", "/workspace/gcs-dir"},
VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}},
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "workspace"}},
}}},
Volumes: []corev1.Volume{{
Name: "pipelinerun-pvc",
Expand Down
5 changes: 4 additions & 1 deletion pkg/reconciler/taskrun/resources/output_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func TestValidOutputResources(t *testing.T) {
Name: "pipelinerun-pvc",
MountPath: "/pvc",
}},
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-git"}},
}}},
wantVolumes: []corev1.Volume{
{
Expand Down Expand Up @@ -311,6 +312,7 @@ func TestValidOutputResources(t *testing.T) {
Name: "pipelinerun-pvc",
MountPath: "/pvc",
}},
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-git"}},
}}},
wantVolumes: []corev1.Volume{
{
Expand Down Expand Up @@ -483,6 +485,7 @@ func TestValidOutputResources(t *testing.T) {
Image: "busybox",
Command: []string{"cp", "-r", "/workspace/output/source-workspace/.", "pipeline-task-path"},
VolumeMounts: []corev1.VolumeMount{{Name: "pipelinerun-parent-pvc", MountPath: "/pvc"}},
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-gcs"}},
}},
{Container: corev1.Container{
Name: "upload-source-gcs-78c5n",
Expand Down Expand Up @@ -573,6 +576,7 @@ func TestValidOutputResources(t *testing.T) {
Image: "busybox",
Command: []string{"cp", "-r", "/workspace/output/source-workspace/.", "pipeline-task-path"},
VolumeMounts: []corev1.VolumeMount{{Name: "pipelinerun-pvc", MountPath: "/pvc"}},
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-gcs"}},
}},
{Container: corev1.Container{
Name: "upload-source-gcs-78c5n",
Expand Down Expand Up @@ -1471,7 +1475,6 @@ func TestInputOutputBucketResources(t *testing.T) {
VolumeMounts: nil,
Command: []string{"gsutil"},
Args: []string{"rsync", "-d", "-r", "/workspace/output/source-workspace", "gs://some-bucket"},
Env: nil,
}},
},
wantVolumes: []corev1.Volume{{
Expand Down

0 comments on commit 6bb399a

Please sign in to comment.