Skip to content

Commit

Permalink
Fix Crash due to Matrix Validation in non Matrix Pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
khrm committed Jul 3, 2024
1 parent ba287f5 commit 062097f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/apis/pipeline/v1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,13 @@ func validateMatrix(ctx context.Context, tasks []PipelineTask) (errs *apis.Field
// by another PipelineTask that the entire array of results produced by a matrix is consumed in aggregate
// since consuming a singular result produced by a matrix is currently not supported
func findAndValidateResultRefsForMatrix(tasks []PipelineTask, taskMapping map[string]PipelineTask) (resultRefs []*ResultRef, errs *apis.FieldError) {
hasMatrixTask := false
for _, t := range tasks {
if !t.IsMatrixed() && !hasMatrixTask {
continue
}
hasMatrixTask = true

for _, p := range t.Params {
if expressions, ok := p.GetVarSubstitutionExpressions(); ok {
if LooksLikeContainsResultRefs(expressions) {
Expand All @@ -812,6 +818,9 @@ func validateMatrixedPipelineTaskConsumed(expressions []string, taskMapping map[
for _, expression := range expressions {
// ie. "tasks.<pipelineTaskName>.results.<resultName>[*]"
subExpressions := strings.Split(expression, ".")
if len(subExpressions) < 2 {
continue
}
pipelineTask := subExpressions[1] // pipelineTaskName
taskConsumed := taskMapping[pipelineTask]
if taskConsumed.IsMatrixed() {
Expand Down
16 changes: 16 additions & 0 deletions test/e2e-tests-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,30 @@ header "Create resources at previous release version"
kubectl create namespace upgrade
trap "kubectl delete namespace upgrade" EXIT
kubectl create -f ./test/upgrade/simpleResources.yaml || fail_test
kubectl create -f ./test/upgrade/resultRefResources.yaml || fail_test

# Upgrade to the current release.
header "Upgrade to the current release of Tekton pipeline"
install_pipeline_crd

initRestartCount=$(kubectl get pods -o=jsonpath='{.items[?(@.metadata.labels.app=="tekton-pipelines-controller")].status.containerStatuses[0].restartCount}' -n ${SYSTEM_NAMESPACE})

# Create runs from the Task and Pipeline resources created at the previous release version
header "Creating TaskRuns and PipelineRuns referencing existing Tasks and Pipelines"
kubectl create -f ./test/upgrade/simpleRuns.yaml || fail_test
kubectl create -f ./test/upgrade/resultRefRuns.yaml || fail_test

for i in $(kc get pr -o=custom-columns=NAMENAME:.metadata.name --no-headers);
do kubectl wait --for=jsonpath='{.status.conditions[0].reason}'=Succeeded pipelinerun $i;
done

curRestartCount=$(kubectl get pods -o=jsonpath='{.items[?(@.metadata.labels.app=="tekton-pipelines-controller")].status.containerStatuses[0].restartCount}' -n ${SYSTEM_NAMESPACE})

if [ ${initRestartCount} -ne ${curRestartCount} ];
echo "controller restarted"
then fail_test;
fi


# Run the post-integration tests. We do not need to install the resources again, since
# they are installed before the upgrade. We verify if they still work, after going through
Expand Down
64 changes: 64 additions & 0 deletions test/upgrade/resultRefResources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: add-task
spec:
params:
- name: first
description: the first operand
- name: second
description: the second operand
results:
- name: sum
description: the sum of the first and second operand
steps:
- name: add
image: alpine
env:
- name: OP1
value: $(params.first)
- name: OP2
value: $(params.second)
command: ["/bin/sh", "-c"]
args:
- echo -n $((${OP1}+${OP2})) | tee $(results.sum.path);
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: sum-three-pipeline
spec:
params:
- name: first
description: the first operand
- name: second
description: the second operand
- name: third
description: the third operand
tasks:
- name: first-add
taskRef:
name: add-task
params:
- name: first
value: $(params.first)
- name: second
value: $(params.second)
- name: second-add
taskRef:
name: add-task
params:
- name: first
value: $(tasks.first-add.results.sum)
- name: second
value: $(tasks.first-add.results.sum) - $(sum)
results:
- name: sum
description: the sum of all three operands
value: $(tasks.second-add.results.sum)
- name: partial-sum
description: the sum of first two operands
value: $(tasks.first-add.results.sum)
- name: all-sum
description: the sum of everything
value: $(tasks.second-add.results.sum)-$(tasks.first-add.results.sum)
14 changes: 14 additions & 0 deletions test/upgrade/resultRefRuns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: resultRefRun
spec:
pipelineRef:
name: sum-three-pipeline
params:
- name: first
value: "2"
- name: second
value: "10"
- name: third
value: "10"

0 comments on commit 062097f

Please sign in to comment.