Skip to content

Commit b08b965

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 1eadef6 commit b08b965

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,10 @@ func createResultsCacheMatrixedTaskRuns(rpt *ResolvedPipelineTask) (resultsCache
848848
// ValidateParamEnumSubset finds the referenced pipeline-level params in the resolved pipelineTask.
849849
// It then validates if the referenced pipeline-level param enums are subsets of the resolved pipelineTask-level param enums
850850
func ValidateParamEnumSubset(pipelineTaskParams []v1.Param, pipelineParamSpecs []v1.ParamSpec, rt *resources.ResolvedTask) error {
851+
// When the matrix Task has no TaskRun, the rt will be nil, we should skip the validation.
852+
if rt == nil {
853+
return nil
854+
}
851855
for _, p := range pipelineTaskParams {
852856
// calculate referenced param enums
853857
res, present, errString := substitution.ExtractVariablesFromString(p.Value.StringVal, "params")

pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,6 +5236,29 @@ func TestValidateParamEnumSubset_Valid(t *testing.T) {
52365236
},
52375237
},
52385238
},
5239+
}, {
5240+
name: "rt is nil - pass",
5241+
params: []v1.Param{
5242+
{
5243+
Name: "resolved-task-p1",
5244+
Value: v1.ParamValue{
5245+
StringVal: "$(params.p1) and $(params.p2)",
5246+
},
5247+
},
5248+
},
5249+
pipelinePs: []v1.ParamSpec{
5250+
{
5251+
Name: "p1",
5252+
Type: v1.ParamTypeString,
5253+
Enum: []string{"v1", "v2"},
5254+
},
5255+
{
5256+
Name: "p2",
5257+
Type: v1.ParamTypeString,
5258+
Enum: []string{"v3", "v4"},
5259+
},
5260+
},
5261+
rt: nil,
52395262
},
52405263
}
52415264

@@ -5320,6 +5343,7 @@ func TestValidateParamEnumSubset_Invalid(t *testing.T) {
53205343
},
53215344
},
53225345
},
5346+
rt: &resources.ResolvedTask{},
53235347
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."),
53245348
}}
53255349

0 commit comments

Comments
 (0)