Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid panic when validate enum param with special matrix task #8465

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading