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

[release-v0.59.x] Perform matrix results validation on only result ref params #8099

Open
wants to merge 1 commit into
base: release-v0.59.x
Choose a base branch
from
Open
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/apis/pipeline/v1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ func findAndValidateResultRefsForMatrix(tasks []PipelineTask, taskMapping map[st
func validateMatrixedPipelineTaskConsumed(expressions []string, taskMapping map[string]PipelineTask) (resultRefs []*ResultRef, errs *apis.FieldError) {
var filteredExpressions []string
for _, expression := range expressions {
// if it is not matrix result ref expression, skip
if !resultref.LooksLikeResultRef(expression) {
continue
}
// ie. "tasks.<pipelineTaskName>.results.<resultName>[*]"
subExpressions := strings.Split(expression, ".")
pipelineTask := subExpressions[1] // pipelineTaskName
Expand Down
123 changes: 123 additions & 0 deletions pkg/apis/pipeline/v1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,129 @@ func TestValidatePipelineWithFinalTasks_Success(t *testing.T) {
}},
},
},
}, {
name: "param with different type of values without matrix",
p: &Pipeline{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinelinename",
},
Spec: PipelineSpec{
Params: ParamSpecs{{
Name: "pipeline-words",
Default: &ParamValue{
Type: ParamTypeObject,
ObjectVal: map[string]string{"hello": "pipeline"},
},
Type: ParamTypeObject,
Properties: map[string]PropertySpec{
"hello": {Type: ParamTypeString},
},
}},
Tasks: []PipelineTask{{
Name: "echoit",
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
Steps: []Step{{
Name: "echo",
Image: "ubuntu",
Command: []string{"echo"},
Args: []string{"$(params.pipeline-words.hello)"},
}},
}},
Params: Params{
{
Name: "name",
Value: ParamValue{
Type: ParamTypeString,
StringVal: "$(params.pipeline-words.hello)",
},
},
{
Name: "name2",
Value: ParamValue{
Type: ParamTypeString,
StringVal: "$(tasks.pipeline-words.results.hello) + $(pipeline-words)",
},
},
},
RunAfter: []string{"pipeline-words"},
}, {
Name: "pipeline-words",
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
Steps: []Step{{
Name: "echo",
Image: "ubuntu",
Command: []string{"echo"},
Args: []string{"$(params.pipeline-words.hello)"},
}},
}},
}},
},
},
}, {
name: "param with different type of values with matrix",
p: &Pipeline{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinelinename",
},
Spec: PipelineSpec{
Params: ParamSpecs{{
Name: "pipeline-words",
Default: &ParamValue{
Type: ParamTypeObject,
ObjectVal: map[string]string{"hello": "pipeline"},
},
Type: ParamTypeObject,
Properties: map[string]PropertySpec{
"hello": {Type: ParamTypeString},
},
}},
Tasks: []PipelineTask{{
Name: "echoit",
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
Steps: []Step{{
Name: "echo",
Image: "ubuntu",
Command: []string{"echo"},
Args: []string{"$(params.pipeline-words.hello)"},
}},
}},
Params: Params{
{
Name: "name",
Value: ParamValue{
Type: ParamTypeString,
StringVal: "$(params.pipeline-words.hello)",
},
},
{
Name: "name2",
Value: ParamValue{
Type: ParamTypeString,
StringVal: "$(tasks.pipeline-words.results.hello[*]) + $(pipeline-words)",
},
},
},
RunAfter: []string{"pipeline-words"},
}, {
Name: "pipeline-words",
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
Steps: []Step{{
Name: "echo",
Image: "ubuntu",
Command: []string{"echo"},
Args: []string{"$(params.pipeline-words.hello)"},
}},
}},
Matrix: &Matrix{
Params: Params{{
Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}},
}, {
Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}},
}},
Include: IncludeParamsList{{}}},
}},
},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down