Skip to content

Commit 7f5d9a4

Browse files
author
Dan Lorenc
committed
Plumb the "TEKTON_RESOURCE_NAME" environment variable into more resource 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).
1 parent 5ec9b00 commit 7f5d9a4

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

pkg/apis/resource/v1alpha1/storage/artifact_pvc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func (p *ArtifactPVC) GetCopyFromStorageToSteps(name, sourcePath, destinationPat
5454
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("source-copy-%s", name)),
5555
Image: p.ShellImage,
5656
Command: []string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath},
57+
Env: []corev1.EnvVar{{
58+
Name: "TEKTON_RESOURCE_NAME",
59+
Value: name,
60+
}},
5761
}}}
5862
}
5963

@@ -69,6 +73,10 @@ func (p *ArtifactPVC) GetCopyToStorageFromSteps(name, sourcePath, destinationPat
6973
Image: p.ShellImage,
7074
Command: []string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath},
7175
VolumeMounts: []corev1.VolumeMount{GetPvcMount(p.Name)},
76+
Env: []corev1.EnvVar{{
77+
Name: "TEKTON_RESOURCE_NAME",
78+
Value: name,
79+
}},
7280
}}}
7381
}
7482

pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func TestPVCGetCopyFromContainerSpec(t *testing.T) {
4040
Image: "busybox",
4141

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

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

7072
got := pvc.GetCopyToStorageFromSteps("workspace", "src-path", "/workspace/destination")

pkg/reconciler/taskrun/resources/input_resource_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ func TestAddInputResourceToTask(t *testing.T) {
594594
Image: "busybox",
595595
Command: []string{"cp", "-r", "prev-task-path/.", "/workspace/gitspace"},
596596
VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}},
597+
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "gitspace"}},
597598
}}},
598599
Volumes: []corev1.Volume{{
599600
Name: "pipelinerun-pvc",
@@ -727,6 +728,7 @@ gsutil cp gs://fake-bucket/rules.zip /workspace/gcs-dir
727728
Image: "busybox",
728729
Command: []string{"cp", "-r", "prev-task-path/.", "/workspace/gcs-dir"},
729730
VolumeMounts: []corev1.VolumeMount{{MountPath: "/pvc", Name: "pipelinerun-pvc"}},
731+
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "workspace"}},
730732
}}},
731733
Volumes: []corev1.Volume{{
732734
Name: "pipelinerun-pvc",

pkg/reconciler/taskrun/resources/output_resource_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ func TestValidOutputResources(t *testing.T) {
238238
Name: "pipelinerun-pvc",
239239
MountPath: "/pvc",
240240
}},
241+
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-git"}},
241242
}}},
242243
wantVolumes: []corev1.Volume{
243244
{
@@ -311,6 +312,7 @@ func TestValidOutputResources(t *testing.T) {
311312
Name: "pipelinerun-pvc",
312313
MountPath: "/pvc",
313314
}},
315+
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-git"}},
314316
}}},
315317
wantVolumes: []corev1.Volume{
316318
{
@@ -483,6 +485,7 @@ func TestValidOutputResources(t *testing.T) {
483485
Image: "busybox",
484486
Command: []string{"cp", "-r", "/workspace/output/source-workspace/.", "pipeline-task-path"},
485487
VolumeMounts: []corev1.VolumeMount{{Name: "pipelinerun-parent-pvc", MountPath: "/pvc"}},
488+
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-gcs"}},
486489
}},
487490
{Container: corev1.Container{
488491
Name: "upload-source-gcs-78c5n",
@@ -573,6 +576,7 @@ func TestValidOutputResources(t *testing.T) {
573576
Image: "busybox",
574577
Command: []string{"cp", "-r", "/workspace/output/source-workspace/.", "pipeline-task-path"},
575578
VolumeMounts: []corev1.VolumeMount{{Name: "pipelinerun-pvc", MountPath: "/pvc"}},
579+
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "source-gcs"}},
576580
}},
577581
{Container: corev1.Container{
578582
Name: "upload-source-gcs-78c5n",
@@ -1471,7 +1475,6 @@ func TestInputOutputBucketResources(t *testing.T) {
14711475
VolumeMounts: nil,
14721476
Command: []string{"gsutil"},
14731477
Args: []string{"rsync", "-d", "-r", "/workspace/output/source-workspace", "gs://some-bucket"},
1474-
Env: nil,
14751478
}},
14761479
},
14771480
wantVolumes: []corev1.Volume{{

0 commit comments

Comments
 (0)