Skip to content

Commit

Permalink
fix: avoid panic when validate enum param with special matrix task
Browse files Browse the repository at this point in the history
fix #8464

If the matrix Task has no TaskRun to execute, the `ResolvedTask` will be
nil, we should skip the validation.
  • Loading branch information
l-qing committed Jan 2, 2025
1 parent 45b56ad commit b942294
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,10 @@ func createResultsCacheMatrixedTaskRuns(rpt *ResolvedPipelineTask) (resultsCache
// ValidateParamEnumSubset finds the referenced pipeline-level params in the resolved pipelineTask.
// It then validates if the referenced pipeline-level param enums are subsets of the resolved pipelineTask-level param enums
func ValidateParamEnumSubset(pipelineTaskParams []v1.Param, pipelineParamSpecs []v1.ParamSpec, rt *resources.ResolvedTask) error {
// When the matrix Task has no TaskRun, the rt will be nil, we should skip the validation.
if rt == nil {
return nil
}
for _, p := range pipelineTaskParams {
// calculate referenced param enums
res, present, errString := substitution.ExtractVariablesFromString(p.Value.StringVal, "params")
Expand Down
24 changes: 24 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5446,6 +5446,29 @@ func TestValidateParamEnumSubset_Valid(t *testing.T) {
},
},
},
}, {
name: "rt is nil - pass",
params: []v1.Param{
{
Name: "resolved-task-p1",
Value: v1.ParamValue{
StringVal: "$(params.p1) and $(params.p2)",
},
},
},
pipelinePs: []v1.ParamSpec{
{
Name: "p1",
Type: v1.ParamTypeString,
Enum: []string{"v1", "v2"},
},
{
Name: "p2",
Type: v1.ParamTypeString,
Enum: []string{"v3", "v4"},
},
},
rt: nil,
},
}

Expand Down Expand Up @@ -5530,6 +5553,7 @@ func TestValidateParamEnumSubset_Invalid(t *testing.T) {
},
},
},
rt: &resources.ResolvedTask{},
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."),
}}

Expand Down

0 comments on commit b942294

Please sign in to comment.