Skip to content

Commit 3a584b5

Browse files
l-qingtekton-robot
authored andcommitted
fix: avoid panic when validate enum param with special matrix task
fix #8464 If the matrix Task has no TaskRun to execute, the `ResolvedTask` will be nil, we should skip the validation.
1 parent 47b776a commit 3a584b5

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go

+4
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,10 @@ func createResultsCacheMatrixedTaskRuns(rpt *ResolvedPipelineTask) (resultsCache
886886
// ValidateParamEnumSubset finds the referenced pipeline-level params in the resolved pipelineTask.
887887
// It then validates if the referenced pipeline-level param enums are subsets of the resolved pipelineTask-level param enums
888888
func ValidateParamEnumSubset(pipelineTaskParams []v1.Param, pipelineParamSpecs []v1.ParamSpec, rt *resources.ResolvedTask) error {
889+
// When the matrix Task has no TaskRun, the rt will be nil, we should skip the validation.
890+
if rt == nil {
891+
return nil
892+
}
889893
for _, p := range pipelineTaskParams {
890894
// calculate referenced param enums
891895
res, present, errString := substitution.ExtractVariablesFromString(p.Value.StringVal, "params")

pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -5446,6 +5446,29 @@ func TestValidateParamEnumSubset_Valid(t *testing.T) {
54465446
},
54475447
},
54485448
},
5449+
}, {
5450+
name: "rt is nil - pass",
5451+
params: []v1.Param{
5452+
{
5453+
Name: "resolved-task-p1",
5454+
Value: v1.ParamValue{
5455+
StringVal: "$(params.p1) and $(params.p2)",
5456+
},
5457+
},
5458+
},
5459+
pipelinePs: []v1.ParamSpec{
5460+
{
5461+
Name: "p1",
5462+
Type: v1.ParamTypeString,
5463+
Enum: []string{"v1", "v2"},
5464+
},
5465+
{
5466+
Name: "p2",
5467+
Type: v1.ParamTypeString,
5468+
Enum: []string{"v3", "v4"},
5469+
},
5470+
},
5471+
rt: nil,
54495472
},
54505473
}
54515474

@@ -5530,6 +5553,7 @@ func TestValidateParamEnumSubset_Invalid(t *testing.T) {
55305553
},
55315554
},
55325555
},
5556+
rt: &resources.ResolvedTask{},
55335557
wantErr: errors.New("unexpected error in ExtractVariablesFromString: Invalid referencing of parameters in \"$(params.p1.aaa.bbb)\"! Only two dot-separated components after the prefix \"params\" are allowed."),
55345558
}}
55355559

0 commit comments

Comments
 (0)