Skip to content

Commit 4b3f397

Browse files
committed
Tests for podTemplate on Tasks
1 parent b085abf commit 4b3f397

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
kind: PipelineRun
2+
metadata:
3+
generateName: matrixed-pipelinerun-
4+
spec:
5+
pipelineSpec:
6+
tasks:
7+
- name: build-and-push-manifest
8+
matrix:
9+
params:
10+
- name: arch
11+
value:
12+
- "amd64"
13+
- "arm64"
14+
taskSpec:
15+
results:
16+
- name: manifest
17+
type: string
18+
params:
19+
- name: arch
20+
podTemplate:
21+
nodeSelector:
22+
kubernetes.io/arch: $(params.arch)
23+
steps:
24+
- name: build-and-push
25+
image: mirror.gcr.io/ubuntu
26+
script: |
27+
echo "building on $(params.arch)"
28+
echo "testmanifest-$(params.arch)" | tee $(results.manifest.path)
29+
- name: create-manifest-list
30+
params:
31+
- name: manifest
32+
value: $(tasks.build-and-push-manifest.results.manifest[*])
33+
taskSpec:
34+
steps:
35+
- name: echo-manifests
36+
image: mirror.gcr.io/ubuntu
37+
args: ["$(params.manifest[*])"]
38+
script: echo "$@"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: tekton.dev/v1
2+
kind: TaskRun
3+
metadata:
4+
name: podtemplate-task-run
5+
spec:
6+
taskSpec:
7+
params:
8+
- name: arch
9+
value: amd64
10+
podTemplate:
11+
nodeSelector:
12+
kubernetes.io/arch: $(params.arch)
13+
steps:
14+
- name: echo
15+
image: mirror.gcr.io/ubuntu
16+
script: |
17+
#!/usr/bin/env bash
18+
echo "Hello World"

pkg/reconciler/taskrun/resources/apply_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/google/go-cmp/cmp"
24+
"github.com/tektoncd/pipeline/pkg/apis/pipeline/pod"
2425
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
2526
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
2627
"github.com/tektoncd/pipeline/pkg/workspace"
@@ -173,6 +174,17 @@ var (
173174
},
174175
},
175176
}},
177+
PodTemplate: &pod.PodTemplate{
178+
NodeSelector: map[string]string{"key-$(params.FOO)": "value-$(params.FOO)"},
179+
Tolerations: []corev1.Toleration{{
180+
Key: "key-$(params.FOO)",
181+
Value: "value-$(params.FOO)",
182+
Effect: corev1.TaintEffect("effect-$(params.FOO)"),
183+
Operator: corev1.TolerationOperator("operator-$(params.FOO)"),
184+
}},
185+
SchedulerName: "name-$(params.FOO)",
186+
// TODO: the rest of the fields
187+
},
176188
}
177189

178190
stepParamTaskSpec = &v1.TaskSpec{
@@ -333,6 +345,17 @@ var (
333345
},
334346
},
335347
}},
348+
PodTemplate: &pod.PodTemplate{
349+
NodeSelector: map[string]string{"$(params.myObject.key1)": "$(params.myObject.key2)"},
350+
Tolerations: []corev1.Toleration{{
351+
Key: "$(params.myObject.key1)",
352+
Value: "$(params.myObject.key1)",
353+
Effect: corev1.TaintEffect("$(params.myObject.key2)"),
354+
Operator: corev1.TolerationOperator("$(params.myObject.key2)"),
355+
}},
356+
SchedulerName: "$(params.myObject.key1)",
357+
// TODO: the rest of the fields
358+
},
336359
}
337360

338361
simpleTaskSpecArrayIndexing = &v1.TaskSpec{
@@ -475,6 +498,17 @@ var (
475498
},
476499
},
477500
}},
501+
PodTemplate: &pod.PodTemplate{
502+
NodeSelector: map[string]string{"key2-$(params.FOO[1])": "value2-$(params.FOO[1])"},
503+
Tolerations: []corev1.Toleration{{
504+
Key: "key2-$(params.FOO[1])",
505+
Value: "value2-$(params.FOO[1])",
506+
Effect: corev1.TaintEffect("effect2-$(params.FOO[1])"),
507+
Operator: corev1.TolerationOperator("operator2-$(params.FOO[1])"),
508+
}},
509+
SchedulerName: "name2-$(params.FOO[1])",
510+
// TODO: the rest of the fields
511+
},
478512
}
479513

480514
arrayParamTaskSpec = &v1.TaskSpec{
@@ -834,6 +868,15 @@ func TestApplyParameters(t *testing.T) {
834868

835869
spec.Sidecars[0].Image = "bar"
836870
spec.Sidecars[0].Env[0].Value = "world"
871+
872+
spec.PodTemplate.NodeSelector = map[string]string{"key-world": "value-world"}
873+
spec.PodTemplate.Tolerations[0].Effect = "effect-world"
874+
spec.PodTemplate.Tolerations[0].Operator = "operator-world"
875+
spec.PodTemplate.Tolerations[0].Key = "key-world"
876+
spec.PodTemplate.Tolerations[0].Value = "value-world"
877+
spec.PodTemplate.SchedulerName = "name-world"
878+
// TODO: the rest of the fields
879+
837880
})
838881
got := resources.ApplyParameters(simpleTaskSpec, tr, dp...)
839882
if d := cmp.Diff(want, got); d != "" {
@@ -900,6 +943,15 @@ func TestApplyParameters_ArrayIndexing(t *testing.T) {
900943

901944
spec.Sidecars[0].Image = "bar"
902945
spec.Sidecars[0].Env[0].Value = "world"
946+
947+
spec.PodTemplate.NodeSelector = map[string]string{"key2-world": "value2-world"}
948+
spec.PodTemplate.Tolerations[0].Effect = "effect2-world"
949+
spec.PodTemplate.Tolerations[0].Operator = "operator2-world"
950+
spec.PodTemplate.Tolerations[0].Key = "key2-world"
951+
spec.PodTemplate.Tolerations[0].Value = "value2-world"
952+
spec.PodTemplate.SchedulerName = "name2-world"
953+
// TODO: the rest of the fields
954+
903955
})
904956
got := resources.ApplyParameters(simpleTaskSpecArrayIndexing, tr, dp...)
905957
if d := cmp.Diff(want, got); d != "" {
@@ -966,6 +1018,15 @@ func TestApplyObjectParameters(t *testing.T) {
9661018
spec.Volumes[2].VolumeSource.Projected.Sources[0].ServiceAccountToken.Audience = "taskrun-value-for-key2"
9671019
spec.Volumes[3].VolumeSource.CSI.VolumeAttributes["secretProviderClass"] = "taskrun-value-for-key1"
9681020
spec.Volumes[3].VolumeSource.CSI.NodePublishSecretRef.Name = "taskrun-value-for-key1"
1021+
1022+
spec.PodTemplate.NodeSelector = map[string]string{"taskrun-value-for-key1": "taskrun-value-for-key2"}
1023+
spec.PodTemplate.Tolerations[0].Effect = "taskrun-value-for-key2"
1024+
spec.PodTemplate.Tolerations[0].Operator = "taskrun-value-for-key2"
1025+
spec.PodTemplate.Tolerations[0].Key = "taskrun-value-for-key1"
1026+
spec.PodTemplate.Tolerations[0].Value = "taskrun-value-for-key1"
1027+
spec.PodTemplate.SchedulerName = "taskrun-value-for-key1"
1028+
// TODO: the rest of the fields
1029+
9691030
})
9701031
got := resources.ApplyParameters(objectParamTaskSpec, tr, dp...)
9711032
if d := cmp.Diff(want, got); d != "" {

0 commit comments

Comments
 (0)