From 6605a41af60045721d47c9d5ab873dbdf6351987 Mon Sep 17 00:00:00 2001 From: Emma Munley Date: Fri, 10 Mar 2023 12:46:30 -0500 Subject: [PATCH] TEP-0118: Update TaskRun Validation for Matrix Include Params This commit updates TaskRun validation to account for Matrix Include Params. Note: This feature is still in preview mode. --- docs/matrix.md | 8 +- docs/pipeline-api.md | 126 +++++---- docs/pipelines.md | 19 ++ pkg/apis/pipeline/v1/matrix_types.go | 103 +++---- pkg/apis/pipeline/v1/matrix_types_test.go | 251 +++++++++--------- pkg/apis/pipeline/v1/openapi_generated.go | 66 ++--- pkg/apis/pipeline/v1/param_types.go | 7 +- pkg/apis/pipeline/v1/param_types_test.go | 39 +++ pkg/apis/pipeline/v1/pipeline_types.go | 6 +- pkg/apis/pipeline/v1/pipeline_types_test.go | 44 +-- .../pipeline/v1/pipeline_validation_test.go | 244 ++++++++--------- pkg/apis/pipeline/v1/resultref_test.go | 2 +- pkg/apis/pipeline/v1/swagger.json | 34 +-- pkg/apis/pipeline/v1/zz_generated.deepcopy.go | 48 +++- pkg/apis/pipeline/v1beta1/matrix_types.go | 109 ++++---- .../pipeline/v1beta1/matrix_types_test.go | 250 ++++++++--------- .../pipeline/v1beta1/openapi_generated.go | 66 ++--- pkg/apis/pipeline/v1beta1/param_types.go | 7 +- pkg/apis/pipeline/v1beta1/param_types_test.go | 39 +++ .../pipeline/v1beta1/pipeline_conversion.go | 4 +- .../v1beta1/pipeline_conversion_test.go | 2 +- pkg/apis/pipeline/v1beta1/pipeline_types.go | 6 +- .../pipeline/v1beta1/pipeline_types_test.go | 54 ++-- .../v1beta1/pipeline_validation_test.go | 244 ++++++++--------- pkg/apis/pipeline/v1beta1/resultref_test.go | 2 +- pkg/apis/pipeline/v1beta1/swagger.json | 34 +-- .../pipeline/v1beta1/zz_generated.deepcopy.go | 48 +++- pkg/reconciler/pipelinerun/pipelinerun.go | 8 +- .../pipelinerun/resources/apply_test.go | 20 +- .../resources/pipelinerunresolution.go | 33 +-- .../resources/pipelinerunresolution_test.go | 2 +- pkg/reconciler/taskrun/validate_taskrun.go | 43 +-- .../taskrun/validate_taskrun_test.go | 65 +++-- 33 files changed, 1094 insertions(+), 939 deletions(-) diff --git a/docs/matrix.md b/docs/matrix.md index f5c4167152b..f8f7505bffd 100644 --- a/docs/matrix.md +++ b/docs/matrix.md @@ -74,10 +74,10 @@ The `Matrix.Include` is used to add explicit combinations to fan out a `Pipeline include: - name: s390x-no-race params: - - name: GOARCH - value: "linux/s390x" - - name: flags - value: "-cover -v" + - name: GOARCH + value: "linux/s390x" + - name: flags + value: "-cover -v" ... ``` diff --git a/docs/pipeline-api.md b/docs/pipeline-api.md index 72737a30222..41fa555253c 100644 --- a/docs/pipeline-api.md +++ b/docs/pipeline-api.md @@ -1328,7 +1328,7 @@ string

Combinations ([]github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Combination alias)

-

Combinations is a list of combinations

+

Combinations is a Combination list

ConfigSource

@@ -1478,13 +1478,11 @@ TaskSpec -

Matrix +

IncludeParams

-

-(Appears on:PipelineTask) -

-

Matrix is used to fan out Tasks in a Pipeline

+

IncludeParams allows passing in a specific combinations of Parameters into the Matrix. +Note this struct is in preview mode and not yet supported

@@ -1496,45 +1494,38 @@ TaskSpec
-params
+name
- -Params - +string
-

Params is a list of parameters used to fan out the pipelineTask -Params takes only Parameters of type "array" -Each array element is supplied to the PipelineTask by substituting params of type "string" in the underlying Task. -The names of the params in the Matrix must match the names of the params in the underlying Task that they will be substituting.

+

Name the specified combination

-include
+params
- -[]MatrixInclude + +Params
-(Optional) -

Include is a list of MatrixInclude which allows passing in specific combinations of Parameters into the Matrix. -Note that Include is in preview mode and not yet supported.

+

Params takes only Parameters of type "string" +The names of the params must match the names of the params in the underlying Task

-

MatrixInclude +

Matrix

-(Appears on:Matrix) +(Appears on:PipelineTask)

-

MatrixInclude allows passing in a specific combinations of Parameters into the Matrix. -Note this struct is in preview mode and not yet supported

+

Matrix is used to fan out Tasks in a Pipeline

@@ -1546,27 +1537,33 @@ Note this struct is in preview mode and not yet supported

@@ -1816,7 +1813,7 @@ map[string]string

Params ([]github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param alias)

-(Appears on:Matrix, MatrixInclude, PipelineTask) +(Appears on:IncludeParams, Matrix, PipelineTask)

Params is a list of Param

@@ -8234,7 +8231,7 @@ int32

Combinations ([]github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Combination alias)

-

Combinations is a list of combination

+

Combinations is a Combination list

ConfigSource

@@ -8614,13 +8611,11 @@ TaskSpec
-name
+params
-string + +Params +
-

Name the specified combination

+

Params is a list of parameters used to fan out the pipelineTask +Params takes only Parameters of type "array" +Each array element is supplied to the PipelineTask by substituting params of type "string" in the underlying Task. +The names of the params in the Matrix must match the names of the params in the underlying Task that they will be substituting.

-params
+include
- -Params + +IncludeParamsList
-

Params takes only Parameters of type "string" -The names of the params must match the names of the params in the underlying Task

+(Optional) +

Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. +Note that Include is in preview mode and not yet supported.

-

Matrix +

IncludeParams

-

-(Appears on:PipelineTask) -

-

Matrix is used to fan out Tasks in a Pipeline

+

IncludeParams allows passing in a specific combinations of Parameters into the Matrix. +Note this struct is in preview mode and not yet supported

@@ -8632,45 +8627,38 @@ TaskSpec
-params
+name
- -Params - +string
-

Params is a list of parameters used to fan out the pipelineTask -Params takes only Parameters of type "array" -Each array element is supplied to the PipelineTask by substituting params of type "string" in the underlying Task. -The names of the params in the Matrix must match the names of the params in the underlying Task that they will be substituting.

+

Name the specified combination

-include
+params
- -[]MatrixInclude + +Params
-(Optional) -

Include is a list of MatrixInclude which allows passing in specific combinations of Parameters into the Matrix. -Note that Include is in preview mode and not yet supported.

+

Params takes only Parameters of type "string" +The names of the params must match the names of the params in the underlying Task

-

MatrixInclude +

Matrix

-(Appears on:Matrix) +(Appears on:PipelineTask)

-

MatrixInclude allows passing in a specific combinations of Parameters into the Matrix. -Note this struct is in preview mode and not yet supported

+

Matrix is used to fan out Tasks in a Pipeline

@@ -8682,27 +8670,33 @@ Note this struct is in preview mode and not yet supported

@@ -8922,7 +8916,7 @@ map[string]string

Params ([]github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param alias)

-(Appears on:Matrix, MatrixInclude, PipelineTask) +(Appears on:IncludeParams, Matrix, PipelineTask)

Params is a list of Param

diff --git a/docs/pipelines.md b/docs/pipelines.md index dd39c578659..0571e4a034c 100644 --- a/docs/pipelines.md +++ b/docs/pipelines.md @@ -386,6 +386,13 @@ spec: - chrome - safari - firefox + include: + - name: build-1 + params: + - name: browser + value: chrome + - name: url + value: some-url ``` For further information, read [`Matrix`](./matrix.md). @@ -1261,6 +1268,13 @@ spec: value: - "foo" - "bar" + include: + - name: build-1 + params: + - name: slack-channel + value: "foo" + - name: flags + value: "-v" ``` For further information, read [`Matrix`](./matrix.md). @@ -1720,6 +1734,11 @@ spec: value: - qux - thud + include: + - name: build-1 + params: + - name: common-package + value: path-to-common-pkg ``` For further information, read [`Matrix`](./matrix.md). diff --git a/pkg/apis/pipeline/v1/matrix_types.go b/pkg/apis/pipeline/v1/matrix_types.go index 1c99567dc83..854751303f8 100644 --- a/pkg/apis/pipeline/v1/matrix_types.go +++ b/pkg/apis/pipeline/v1/matrix_types.go @@ -34,16 +34,19 @@ type Matrix struct { // +listType=atomic Params Params `json:"params,omitempty"` - // Include is a list of MatrixInclude which allows passing in specific combinations of Parameters into the Matrix. + // Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. // Note that Include is in preview mode and not yet supported. // +optional // +listType=atomic - Include []MatrixInclude `json:"include,omitempty"` + Include IncludeParamsList `json:"include,omitempty"` } -// MatrixInclude allows passing in a specific combinations of Parameters into the Matrix. +// IncludeParamsList is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. +type IncludeParamsList []IncludeParams + +// IncludeParams allows passing in a specific combinations of Parameters into the Matrix. // Note this struct is in preview mode and not yet supported -type MatrixInclude struct { +type IncludeParams struct { // Name the specified combination Name string `json:"name,omitempty"` @@ -56,12 +59,21 @@ type MatrixInclude struct { // Combination is a map, mainly defined to hold a single combination from a Matrix with key as param.Name and value as param.Value type Combination map[string]string -// Combinations is a list of combinations +// Combinations is a Combination list type Combinations []Combination -// ToParams transforms Combinations from a slice of map[string]string to a slice of Params +// FanOut returns an list of params that represent combinations +func (m *Matrix) FanOut() []Params { + var combinations Combinations + for _, parameter := range m.Params { + combinations = combinations.fanOutMatrixParams(parameter) + } + return combinations.toParams() +} + +// toParams transforms Combinations from a slice of map[string]string to a slice of Params // such that, these combinations can be directly consumed in creating taskRun/run object -func (cs Combinations) ToParams() []Params { +func (cs Combinations) toParams() []Params { listOfParams := make([]Params, len(cs)) for i := range cs { var params Params @@ -78,15 +90,15 @@ func (cs Combinations) ToParams() []Params { return listOfParams } -// fanOut generates a new combination based on a given Parameter in the Matrix. -func (cs Combinations) fanOut(param Param) Combinations { +// fanOutMatrixParams generates new combinations based on Matrix Parameters. +func (cs Combinations) fanOutMatrixParams(param Param) Combinations { if len(cs) == 0 { return initializeCombinations(param) } return cs.distribute(param) } -// distribute generates a new combination of Parameters by adding a new Parameter to an existing list of Combinations. +// distribute generates a new Combination of Parameters by adding a new Parameter to an existing list of Combinations. func (cs Combinations) distribute(param Param) Combinations { var expandedCombinations Combinations for _, value := range param.Value.ArrayVal { @@ -101,7 +113,7 @@ func (cs Combinations) distribute(param Param) Combinations { return expandedCombinations } -// initializeCombinations generates a new combination based on the first Parameter in the Matrix. +// initializeCombinations generates a new Combination based on the first Parameter in the Matrix. func initializeCombinations(param Param) Combinations { var combinations Combinations for _, value := range param.Value.ArrayVal { @@ -110,7 +122,7 @@ func initializeCombinations(param Param) Combinations { return combinations } -// sortCombination sorts the given Combination based on the param names to produce a deterministic ordering +// sortCombination sorts the given Combination based on the Parameter names to produce a deterministic ordering func (c Combination) sortCombination() ([]string, Combination) { sortedCombination := make(Combination, len(c)) order := make([]string, 0, len(c)) @@ -126,30 +138,21 @@ func (c Combination) sortCombination() ([]string, Combination) { return order, sortedCombination } -// FanOut produces combinations of Parameters of type String from a slice of Parameters of type Array. -func (m *Matrix) FanOut() Combinations { - var combinations Combinations - for _, parameter := range m.Params { - combinations = combinations.fanOut(parameter) - } - return combinations -} - -// CountCombinations returns the count of combinations of Parameters generated from the Matrix in PipelineTask. +// CountCombinations returns the count of Combinations of Parameters generated from the Matrix in PipelineTask. func (m *Matrix) CountCombinations() int { - // Iterate over matrix.params and compute count of all generated combinations + // Iterate over Matrix Parameters and compute count of all generated Combinations count := m.countGeneratedCombinationsFromParams() - // Add any additional combinations generated from matrix include params + // Add any additional Combinations generated from Matrix Include Parameters count += m.countNewCombinationsFromInclude() return count } -// countGeneratedCombinationsFromParams returns the count of combinations of Parameters generated from the matrix -// parameters +// countGeneratedCombinationsFromParams returns the count of Combinations of Parameters generated from the Matrix +// Parameters func (m *Matrix) countGeneratedCombinationsFromParams() int { - if !m.hasParams() { + if !m.HasParams() { return 0 } count := 1 @@ -159,13 +162,13 @@ func (m *Matrix) countGeneratedCombinationsFromParams() int { return count } -// countNewCombinationsFromInclude returns the count of combinations of Parameters generated from the matrix -// include parameters +// countNewCombinationsFromInclude returns the count of Combinations of Parameters generated from the Matrix +// Include Parameters func (m *Matrix) countNewCombinationsFromInclude() int { - if !m.hasInclude() { + if !m.HasInclude() { return 0 } - if !m.hasParams() { + if !m.HasParams() { return len(m.Include) } count := 0 @@ -173,7 +176,7 @@ func (m *Matrix) countNewCombinationsFromInclude() int { for _, include := range m.Include { for _, param := range include.Params { if val, exist := matrixParamMap[param.Name]; exist { - // If the matrix include param values does not exist, a new combination will be generated + // If the Matrix Include param values does not exist, a new Combination will be generated if !slices.Contains(val, param.Value.StringVal) { count++ } else { @@ -185,25 +188,28 @@ func (m *Matrix) countNewCombinationsFromInclude() int { return count } -func (m *Matrix) hasInclude() bool { +// HasInclude returns true if the Matrix has Include Parameters +func (m *Matrix) HasInclude() bool { return m != nil && m.Include != nil && len(m.Include) > 0 } -func (m *Matrix) hasParams() bool { +// HasParams returns true if the Matrix has Parameters +func (m *Matrix) HasParams() bool { return m != nil && m.Params != nil && len(m.Params) > 0 } -func (m *Matrix) getParamNames() []string { - var names []string - if m.hasParams() { - names = m.Params.extractNames() +// GetAllParams returns a list of all Matrix Parameters +func (m *Matrix) GetAllParams() Params { + var params Params + if m.HasParams() { + params = append(params, m.Params...) } - if m.hasInclude() { + if m.HasInclude() { for _, include := range m.Include { - names = append(names, include.Params.extractNames()...) + params = append(params, include.Params...) } } - return names + return params } func (m *Matrix) validateCombinationsCount(ctx context.Context) (errs *apis.FieldError) { @@ -215,14 +221,13 @@ func (m *Matrix) validateCombinationsCount(ctx context.Context) (errs *apis.Fiel return errs } -// validateParams validates the type of parameter -// for Matrix.Params and Matrix.Include.Params +// validateParams validates the type of Parameter for Matrix.Params and Matrix.Include.Params // Matrix.Params must be of type array. Matrix.Include.Params must be of type string. // validateParams also validates Matrix.Params for a unique list of params // and a unique list of params in each Matrix.Include.Params specification func (m *Matrix) validateParams() (errs *apis.FieldError) { if m != nil { - if m.hasInclude() { + if m.HasInclude() { for i, include := range m.Include { errs = errs.Also(include.Params.validateDuplicateParameters().ViaField(fmt.Sprintf("matrix.include[%d].params", i))) for _, param := range include.Params { @@ -232,7 +237,7 @@ func (m *Matrix) validateParams() (errs *apis.FieldError) { } } } - if m.hasParams() { + if m.HasParams() { errs = errs.Also(m.Params.validateDuplicateParameters().ViaField("matrix.params")) for _, param := range m.Params { if param.Value.Type != ParamTypeArray { @@ -244,10 +249,10 @@ func (m *Matrix) validateParams() (errs *apis.FieldError) { return errs } -// validatePipelineParametersVariablesInMatrixParameters validates all pipeline paramater variables including Matrix.Params and Matrix.Include.Params +// validatePipelineParametersVariablesInMatrixParameters validates all pipeline parameter variables including Matrix.Params and Matrix.Include.Params // that may contain the reference(s) to other params to make sure those references are used appropriately. func (m *Matrix) validatePipelineParametersVariablesInMatrixParameters(prefix string, paramNames sets.String, arrayParamNames sets.String, objectParamNameKeys map[string][]string) (errs *apis.FieldError) { - if m.hasInclude() { + if m.HasInclude() { for _, include := range m.Include { for idx, param := range include.Params { stringElement := param.Value.StringVal @@ -256,7 +261,7 @@ func (m *Matrix) validatePipelineParametersVariablesInMatrixParameters(prefix st } } } - if m.hasParams() { + if m.HasParams() { for _, param := range m.Params { for idx, arrayElement := range param.Value.ArrayVal { // Matrix Params must be of type array @@ -268,7 +273,7 @@ func (m *Matrix) validatePipelineParametersVariablesInMatrixParameters(prefix st } func (m *Matrix) validateParameterInOneOfMatrixOrParams(params []Param) (errs *apis.FieldError) { - matrixParamNames := sets.NewString(m.getParamNames()...) + matrixParamNames := m.GetAllParams().ExtractNames() for _, param := range params { if matrixParamNames.Has(param.Name) { errs = errs.Also(apis.ErrMultipleOneOf("matrix["+param.Name+"]", "params["+param.Name+"]")) diff --git a/pkg/apis/pipeline/v1/matrix_types_test.go b/pkg/apis/pipeline/v1/matrix_types_test.go index 7c3a87ff66d..4394e61171b 100644 --- a/pkg/apis/pipeline/v1/matrix_types_test.go +++ b/pkg/apis/pipeline/v1/matrix_types_test.go @@ -20,19 +20,17 @@ import ( "github.com/tektoncd/pipeline/test/diff" ) -func TestMatrix_FanOut_ToParams(t *testing.T) { +func TestMatrix_FanOut(t *testing.T) { tests := []struct { - name string - matrix Matrix - want Combinations - expectedParams []Params + name string + matrix Matrix + want []Params }{{ name: "matrix with no params", matrix: Matrix{ Params: Params{}, }, - want: nil, - expectedParams: nil, + want: []Params{}, }, { name: "single array in matrix", matrix: Matrix{ @@ -41,14 +39,7 @@ func TestMatrix_FanOut_ToParams(t *testing.T) { Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, }}, }, - want: Combinations{{ - "platform": "linux", - }, { - "platform": "mac", - }, { - "platform": "windows", - }}, - expectedParams: []Params{{ + want: []Params{{ { Name: "platform", Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, @@ -67,126 +58,68 @@ func TestMatrix_FanOut_ToParams(t *testing.T) { }, { name: "multiple arrays in matrix", matrix: Matrix{ - Params: []Param{{ - Name: "platform", - Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, - }, { - Name: "browser", - Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"chrome", "safari", "firefox"}}, - }}}, - want: Combinations{{ - "browser": "chrome", - "platform": "linux", - }, { - "browser": "chrome", - "platform": "mac", - }, { - "browser": "chrome", - "platform": "windows", - }, { - "browser": "safari", - "platform": "linux", - }, { - "browser": "safari", - "platform": "mac", - }, { - "browser": "safari", - "platform": "windows", - }, { - "browser": "firefox", - "platform": "linux", - }, { - "browser": "firefox", - "platform": "mac", - }, { - "browser": "firefox", - "platform": "windows", - }}, - expectedParams: []Params{{ - { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "chrome"}, - }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, - }, - }, { - { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "chrome"}, + Params: Params{{ + Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "mac"}, + Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - }, { + Include: IncludeParamsList{{}}, + }, + want: []Params{{ { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "chrome"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "windows"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "safari"}, - }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, - }}, { - { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "safari"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "mac"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "safari"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "windows"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "firefox"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "firefox"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "mac"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "firefox"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "windows"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, }, }}, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - tt.matrix.FanOut() if d := cmp.Diff(tt.want, tt.matrix.FanOut()); d != "" { t.Errorf("Combinations of Parameters did not match the expected Params: %s", diff.PrintWantGot(d)) } - c := tt.matrix.FanOut().ToParams() - for i := range c { - if d := cmp.Diff(tt.expectedParams[i], c[i]); d != "" { - t.Errorf("The formatted Combinations of Parameters did not match the expected Params: %s", diff.PrintWantGot(d)) - } - } }) } } @@ -216,7 +149,7 @@ func TestMatrix_HasParams(t *testing.T) { }, { name: "matrixed with include", matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", Params: []Param{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, @@ -228,12 +161,12 @@ func TestMatrix_HasParams(t *testing.T) { }, { name: "matrixed with params and include", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", - Params: []Param{{ + Params: Params{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, @@ -242,8 +175,8 @@ func TestMatrix_HasParams(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - if d := cmp.Diff(tc.want, tc.matrix.hasParams()); d != "" { - t.Errorf("matrix.hasParams() bool diff %s", diff.PrintWantGot(d)) + if d := cmp.Diff(tc.want, tc.matrix.HasParams()); d != "" { + t.Errorf("matrix.HasParams() bool diff %s", diff.PrintWantGot(d)) } }) } @@ -268,15 +201,15 @@ func TestMatrix_HasInclude(t *testing.T) { { name: "matrixed with params", matrix: &Matrix{ - Params: []Param{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, want: false, }, { name: "matrixed with include", matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, }, { Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, @@ -286,12 +219,12 @@ func TestMatrix_HasInclude(t *testing.T) { }, { name: "matrixed with params and include", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", - Params: []Param{{ + Params: Params{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, @@ -300,8 +233,74 @@ func TestMatrix_HasInclude(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - if d := cmp.Diff(tc.want, tc.matrix.hasInclude()); d != "" { - t.Errorf("matrix.hasInclude() bool diff %s", diff.PrintWantGot(d)) + if d := cmp.Diff(tc.want, tc.matrix.HasInclude()); d != "" { + t.Errorf("matrix.HasInclude() bool diff %s", diff.PrintWantGot(d)) + } + }) + } +} + +func TestMatrix_GetAllParams(t *testing.T) { + testCases := []struct { + name string + matrix *Matrix + want Params + }{ + { + name: "nil matrix", + matrix: nil, + want: nil, + }, + { + name: "empty matrix", + matrix: &Matrix{}, + want: nil, + }, + { + name: "matrixed with params", + matrix: &Matrix{ + Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + }, + want: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + }, { + name: "matrixed with include", + matrix: &Matrix{ + Include: IncludeParamsList{{ + Name: "build-1", + Params: Params{{ + Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + }, { + Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + }}, + }, + want: Params{{ + Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + }, { + Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + }, + { + name: "matrixed with params and include", + matrix: &Matrix{ + Params: Params{{ + Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + }}, + Include: IncludeParamsList{{ + Name: "common-package", + Params: Params{{ + Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + }}, + }, + want: Params{{ + Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + }, { + Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + }}, + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + if d := cmp.Diff(tc.want, tc.matrix.GetAllParams()); d != "" { + t.Errorf("matrix.GetAllParams() bool diff %s", diff.PrintWantGot(d)) } }) } @@ -315,12 +314,12 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }{{ name: "combinations count is zero", matrix: &Matrix{ - Params: []Param{{}}}, + Params: Params{{}}}, want: 0, }, { name: "combinations count is one from one parameter", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, }}}, @@ -328,7 +327,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { name: "combinations count is one from two parameters", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar"}}, @@ -337,14 +336,14 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { name: "combinations count is two from one parameter", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, want: 2, }, { name: "combinations count is nine", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, @@ -353,7 +352,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { name: "combinations count is large", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, @@ -366,7 +365,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { name: "explicit combinations in the matrix", matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", Params: []Param{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, @@ -398,7 +397,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", Params: []Param{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, @@ -425,7 +424,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", Params: []Param{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, diff --git a/pkg/apis/pipeline/v1/openapi_generated.go b/pkg/apis/pipeline/v1/openapi_generated.go index ddbd49c2f7a..62a5fcd92ec 100644 --- a/pkg/apis/pipeline/v1/openapi_generated.go +++ b/pkg/apis/pipeline/v1/openapi_generated.go @@ -35,8 +35,8 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.ChildStatusReference": schema_pkg_apis_pipeline_v1_ChildStatusReference(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.ConfigSource": schema_pkg_apis_pipeline_v1_ConfigSource(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.EmbeddedTask": schema_pkg_apis_pipeline_v1_EmbeddedTask(ref), + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.IncludeParams": schema_pkg_apis_pipeline_v1_IncludeParams(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Matrix": schema_pkg_apis_pipeline_v1_Matrix(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.MatrixInclude": schema_pkg_apis_pipeline_v1_MatrixInclude(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param": schema_pkg_apis_pipeline_v1_Param(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.ParamSpec": schema_pkg_apis_pipeline_v1_ParamSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.ParamValue": schema_pkg_apis_pipeline_v1_ParamValue(ref), @@ -650,46 +650,34 @@ func schema_pkg_apis_pipeline_v1_EmbeddedTask(ref common.ReferenceCallback) comm } } -func schema_pkg_apis_pipeline_v1_Matrix(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_pipeline_v1_IncludeParams(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "Matrix is used to fan out Tasks in a Pipeline", + Description: "IncludeParams allows passing in a specific combinations of Parameters into the Matrix. Note this struct is in preview mode and not yet supported", Type: []string{"object"}, Properties: map[string]spec.Schema{ - "params": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, + "name": { SchemaProps: spec.SchemaProps{ - Description: "Params is a list of parameters used to fan out the pipelineTask Params takes only `Parameters` of type `\"array\"` Each array element is supplied to the `PipelineTask` by substituting `params` of type `\"string\"` in the underlying `Task`. The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param"), - }, - }, - }, + Description: "Name the specified combination", + Type: []string{"string"}, + Format: "", }, }, - "include": { + "params": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ "x-kubernetes-list-type": "atomic", }, }, SchemaProps: spec.SchemaProps{ - Description: "Include is a list of MatrixInclude which allows passing in specific combinations of Parameters into the Matrix. Note that Include is in preview mode and not yet supported.", + Description: "Params takes only `Parameters` of type `\"string\"` The names of the `params` must match the names of the `params` in the underlying `Task`", Type: []string{"array"}, Items: &spec.SchemaOrArray{ Schema: &spec.Schema{ SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.MatrixInclude"), + Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param"), }, }, }, @@ -699,38 +687,50 @@ func schema_pkg_apis_pipeline_v1_Matrix(ref common.ReferenceCallback) common.Ope }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.MatrixInclude", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param"}, } } -func schema_pkg_apis_pipeline_v1_MatrixInclude(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_pipeline_v1_Matrix(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "MatrixInclude allows passing in a specific combinations of Parameters into the Matrix. Note this struct is in preview mode and not yet supported", + Description: "Matrix is used to fan out Tasks in a Pipeline", Type: []string{"object"}, Properties: map[string]spec.Schema{ - "name": { + "params": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-list-type": "atomic", + }, + }, SchemaProps: spec.SchemaProps{ - Description: "Name the specified combination", - Type: []string{"string"}, - Format: "", + Description: "Params is a list of parameters used to fan out the pipelineTask Params takes only `Parameters` of type `\"array\"` Each array element is supplied to the `PipelineTask` by substituting `params` of type `\"string\"` in the underlying `Task`. The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param"), + }, + }, + }, }, }, - "params": { + "include": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ "x-kubernetes-list-type": "atomic", }, }, SchemaProps: spec.SchemaProps{ - Description: "Params takes only `Parameters` of type `\"string\"` The names of the `params` must match the names of the `params` in the underlying `Task`", + Description: "Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. Note that Include is in preview mode and not yet supported.", Type: []string{"array"}, Items: &spec.SchemaOrArray{ Schema: &spec.Schema{ SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param"), + Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.IncludeParams"), }, }, }, @@ -740,7 +740,7 @@ func schema_pkg_apis_pipeline_v1_MatrixInclude(ref common.ReferenceCallback) com }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.IncludeParams", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1.Param"}, } } diff --git a/pkg/apis/pipeline/v1/param_types.go b/pkg/apis/pipeline/v1/param_types.go index c7c9b4b41bc..994cd7e74ba 100644 --- a/pkg/apis/pipeline/v1/param_types.go +++ b/pkg/apis/pipeline/v1/param_types.go @@ -116,10 +116,11 @@ type Param struct { Value ParamValue `json:"value"` } -func (ps Params) extractNames() []string { - names := []string{} +// ExtractNames returns a set of unique names +func (ps Params) ExtractNames() sets.String { + names := sets.String{} for _, p := range ps { - names = append(names, p.Name) + names.Insert(p.Name) } return names } diff --git a/pkg/apis/pipeline/v1/param_types_test.go b/pkg/apis/pipeline/v1/param_types_test.go index b0928c47504..41c8d7b6442 100644 --- a/pkg/apis/pipeline/v1/param_types_test.go +++ b/pkg/apis/pipeline/v1/param_types_test.go @@ -26,6 +26,7 @@ import ( "github.com/google/go-cmp/cmp" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tektoncd/pipeline/test/diff" + "k8s.io/apimachinery/pkg/util/sets" ) func TestParamSpec_SetDefaults(t *testing.T) { @@ -453,3 +454,41 @@ func TestArrayReference(t *testing.T) { } } } + +func TestExtractNames(t *testing.T) { + tests := []struct { + name string + params v1.Params + want sets.String + }{{ + name: "no params", + params: v1.Params{{}}, + want: sets.NewString(""), + }, { + name: "extract param names from ParamTypeString", + params: v1.Params{{ + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-1"}, + }, { + Name: "DOCKERFILE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + want: sets.NewString("IMAGE", "DOCKERFILE"), + }, { + name: "extract param names from ParamTypeArray", + params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + }}, + want: sets.NewString("GOARCH"), + }, { + name: "extract param names from ParamTypeString and ParamTypeArray", + params: v1.Params{{ + Name: "GOARCH", Value: v1.ParamValue{Type: v1.ParamTypeArray, ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + }, { + Name: "IMAGE", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "image-1"}, + }}, + want: sets.NewString("GOARCH", "IMAGE"), + }} + for _, tt := range tests { + if d := cmp.Diff(tt.want, v1.Params.ExtractNames(tt.params)); d != "" { + t.Errorf(diff.PrintWantGot(d)) + } + } +} diff --git a/pkg/apis/pipeline/v1/pipeline_types.go b/pkg/apis/pipeline/v1/pipeline_types.go index 56f606b4c26..3fbebee7839 100644 --- a/pkg/apis/pipeline/v1/pipeline_types.go +++ b/pkg/apis/pipeline/v1/pipeline_types.go @@ -264,7 +264,7 @@ func (pt PipelineTask) validateTask(ctx context.Context) (errs *apis.FieldError) // IsMatrixed return whether pipeline task is matrixed func (pt *PipelineTask) IsMatrixed() bool { - return pt.Matrix != nil && (pt.Matrix.hasParams() || pt.Matrix.hasInclude()) + return pt.Matrix.HasParams() || pt.Matrix.HasInclude() } // extractAllParams extracts all the parameters in a PipelineTask: @@ -273,10 +273,10 @@ func (pt *PipelineTask) IsMatrixed() bool { // - pt.Matrix.Include.Params func (pt *PipelineTask) extractAllParams() Params { allParams := pt.Params - if pt.Matrix.hasParams() { + if pt.Matrix.HasParams() { allParams = append(allParams, pt.Matrix.Params...) } - if pt.Matrix.hasInclude() { + if pt.Matrix.HasInclude() { for _, include := range pt.Matrix.Include { allParams = append(allParams, include.Params...) } diff --git a/pkg/apis/pipeline/v1/pipeline_types_test.go b/pkg/apis/pipeline/v1/pipeline_types_test.go index 8398fedc306..283bd3732db 100644 --- a/pkg/apis/pipeline/v1/pipeline_types_test.go +++ b/pkg/apis/pipeline/v1/pipeline_types_test.go @@ -588,7 +588,7 @@ func TestPipelineTaskList_Deps(t *testing.T) { } } -func TestPipelineTask_validateMatrix(t *testing.T) { +func TestPipelineTask_ValidateMatrix(t *testing.T) { tests := []struct { name string pt *PipelineTask @@ -598,10 +598,10 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}, }, @@ -611,13 +611,13 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "duplicate-param", Params: Params{{ Name: "duplicate", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, }}}, }}, - Params: []Param{{ + Params: Params{{ Name: "duplicate", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}, }, @@ -627,7 +627,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }, { Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo-1", "bar-1"}}, @@ -642,10 +642,10 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, - Params: []Param{{ + Params: Params{{ Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}, }}, }, @@ -654,7 +654,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "invalid-include", Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, @@ -672,7 +672,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeString, StringVal: "bar"}, @@ -687,7 +687,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}, @@ -698,9 +698,9 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, }, { Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}, @@ -712,9 +712,9 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "barfoo", Value: ParamValue{Type: ParamTypeObject, ObjectVal: map[string]string{ "url": "$(params.myObject.non-exist-key)", "commit": "$(params.myString)", @@ -736,9 +736,9 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}}}, @@ -753,7 +753,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.foo-task.results.a-result)"}}, }}}, }, @@ -762,7 +762,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "platform", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, }, { Name: "browser", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"chrome", "firefox", "safari"}}, @@ -777,7 +777,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "platform", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac"}}, }, { Name: "browser", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"chrome", "firefox"}}, @@ -926,7 +926,7 @@ func TestPipelineTask_IsMatrixed(t *testing.T) { name: "matrixed with include", arg: arg{ Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", Params: []Param{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, @@ -943,7 +943,7 @@ func TestPipelineTask_IsMatrixed(t *testing.T) { Params: []Param{{ Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", Params: []Param{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, diff --git a/pkg/apis/pipeline/v1/pipeline_validation_test.go b/pkg/apis/pipeline/v1/pipeline_validation_test.go index a18e4f6025c..42282e65990 100644 --- a/pkg/apis/pipeline/v1/pipeline_validation_test.go +++ b/pkg/apis/pipeline/v1/pipeline_validation_test.go @@ -467,7 +467,7 @@ func TestPipelineSpec_Validate_Failure(t *testing.T) { }, { Name: "invalid-pipeline-task", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "prefix", Value: ParamValue{Type: ParamTypeString, StringVal: "bar"}, }}, When: []WhenExpression{{ @@ -1004,7 +1004,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.baz) and $(params.foo-is-baz)"}, }}, }}, @@ -1054,7 +1054,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.baz)", "and", "$(params.foo-is-baz)"}}, }}, }}, @@ -1068,7 +1068,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.baz[*])", "and", "$(params.foo-is-baz[*])"}}, }}, }}, @@ -1080,7 +1080,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(input.workspace.$(params.baz))"}, }}, }}, @@ -1095,7 +1095,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.baz)", "and", "$(params.foo-is-baz)"}}, }}}, }}, @@ -1110,7 +1110,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.baz[*])", "and", "$(params.foo-is-baz[*])"}}, }}}, }}, @@ -1123,7 +1123,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param-intended-to-be-array", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myArray[*])"}, }}, }}, @@ -1136,9 +1136,9 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.baz)"}}, }}}}, }}, @@ -1155,7 +1155,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-string-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myObject.key1)"}, }}, }}, @@ -1172,7 +1172,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-string-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myObject.key1) and $(params.myObject.key2)"}, }}, }}, @@ -1189,7 +1189,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "an-array-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.key1)", "another one $(params.myObject.key2)"}}, }}, }}, @@ -1209,7 +1209,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "an-object-param", Value: ParamValue{Type: ParamTypeObject, ObjectVal: map[string]string{ "url": "$(params.myObject.key1)", "commit": "$(params.myString)", @@ -1230,7 +1230,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.key1)", "and", "$(params.myObject.key2)"}}, }}}, }}, @@ -1247,7 +1247,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param-intended-to-be-object", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myObject[*])"}, }}, }}, @@ -1297,7 +1297,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.does-not-exist)"}, }}, }}, @@ -1379,7 +1379,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.foo) and $(params.does-not-exist)"}, }}, }}, @@ -1395,7 +1395,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.foo)"}, }, { Name: "b-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.does-not-exist)"}, @@ -1452,7 +1452,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.baz)"}, }}, }}, @@ -1468,7 +1468,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.baz[*])"}, }}, }}, @@ -1484,7 +1484,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"value: $(params.baz)", "last"}}, }}, }}, @@ -1500,7 +1500,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"value: $(params.baz[*])", "last"}}, }}, }}, @@ -1559,7 +1559,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.does-not-exist)"}}, }}}, }}, @@ -1576,7 +1576,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.foo)", "and", "$(params.does-not-exist)"}}, }}}, }}, @@ -1593,7 +1593,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.foo)"}}, }, { Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.does-not-exist)"}}}}}, @@ -1611,8 +1611,8 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ - Params: []Param{{ + Include: IncludeParamsList{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.foo)"}, }, { Name: "b-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.does-not-exist)"}, @@ -1684,7 +1684,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.non-exist-key)", "last"}}, }}, }}, @@ -1706,7 +1706,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myObject.non-exist-key)"}, }}, }}, @@ -1731,7 +1731,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "an-object-param", Value: ParamValue{Type: ParamTypeObject, ObjectVal: map[string]string{ "url": "$(params.myObject.non-exist-key)", "commit": "$(params.myString)", @@ -1757,7 +1757,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.key1)"}}, }, { Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.non-exist-key)"}}, @@ -1773,7 +1773,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "duplicate-param", Value: ParamValue{Type: ParamTypeString, StringVal: "val1"}, }, { Name: "duplicate-param", Value: ParamValue{Type: ParamTypeString, StringVal: "val2"}, @@ -2026,7 +2026,7 @@ func TestValidatePipelineWithFinalTasks_Success(t *testing.T) { Finally: []PipelineTask{{ Name: "final-task-1", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.non-final-task.results.output)"}, }}, }}, @@ -2044,7 +2044,7 @@ func TestValidatePipelineWithFinalTasks_Success(t *testing.T) { Finally: []PipelineTask{{ Name: "final-task-1", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineRun.name)"}, }}, }}, @@ -2214,7 +2214,7 @@ func TestValidatePipelineWithFinalTasks_Failure(t *testing.T) { Finally: []PipelineTask{{ Name: "final-task", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "final-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.foo) and $(params.does-not-exist)"}, }}, }}, @@ -2289,7 +2289,7 @@ func TestValidatePipelineWithFinalTasks_Failure(t *testing.T) { Finally: []PipelineTask{{ Name: "final-task-1", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineRun.missing)"}, }}, }}, @@ -2392,7 +2392,7 @@ func TestValidateFinalTasks_Failure(t *testing.T) { }, { Name: "final-task-2", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.final-task-1.results.output)"}, }}, }}, @@ -2423,7 +2423,7 @@ func TestValidateFinalTasks_Failure(t *testing.T) { finalTasks: []PipelineTask{{ Name: "final-task", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.no-dag-task-1.results.output)"}, }}, }}, @@ -2453,11 +2453,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipeline.name)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.name)"}}, }}}, }}, @@ -2466,11 +2466,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineRun.name)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipelineRun.name)"}}, }}}, }}, @@ -2479,11 +2479,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineRun.namespace)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipelineRun.namespace)"}}, }}}, }}, @@ -2492,11 +2492,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineRun.uid)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipelineRun.uid)"}}, }}}, }}, @@ -2505,11 +2505,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.name)", "and", "$(context.pipelineRun.name)"}}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.name)", "and", "$(context.pipelineRun.name)"}}, }}}, }}, @@ -2518,11 +2518,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineTask.retries)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineTask.retries)"}, }}}, }}, @@ -2531,11 +2531,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{ArrayVal: []string{"$(context.pipelineTask.retries)"}}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipelineTask.retries)"}}, }}}, }}, @@ -2544,13 +2544,13 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipeline.name)"}, }}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipeline.name)"}}}, }}}, }}, @@ -2559,13 +2559,13 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineTask.retries)"}, }}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineTask.retries)"}}}, }}}, }}, @@ -2589,11 +2589,11 @@ func TestContextInvalid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipeline.missing)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.missing-foo)"}}, }}}, }}, @@ -2609,11 +2609,11 @@ func TestContextInvalid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineRun.missing)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{ArrayVal: []string{"$(context.pipelineRun.missing-foo)"}}, }}}, }}, @@ -2629,11 +2629,11 @@ func TestContextInvalid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineTask.missing)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{ArrayVal: []string{"$(context.pipelineTask.missing-foo)"}}, }}}, }}, @@ -2649,11 +2649,11 @@ func TestContextInvalid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.missing)", "$(context.pipelineTask.missing)", "$(context.pipelineRun.missing)"}}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.missing-foo)", "$(context.pipelineTask.missing-foo)", "$(context.pipelineRun.missing-foo)"}}, }}}, }}, @@ -2669,9 +2669,9 @@ func TestContextInvalid(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipeline.missing)"}}}, }}}, }}, @@ -2685,9 +2685,9 @@ func TestContextInvalid(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineRun.missing)"}}}, }}}, }}, @@ -2701,9 +2701,9 @@ func TestContextInvalid(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineTask.missing)"}}}, }}}, }}, @@ -2739,7 +2739,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "foo-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.foo.status)"}, }, { Name: "tasks-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.status)"}, @@ -2759,7 +2759,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "foo-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.foo.results.status)"}, }}, When: WhenExpressions{WhenExpression{ @@ -2776,7 +2776,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "foo-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of foo is $(tasks.foo.status)."}, }}, }}, @@ -2788,7 +2788,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "foo-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of $(tasks.taskname) is $(tasks.foo.status)."}, }}, }}, @@ -2797,7 +2797,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "bar-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.bar.status)"}, }}, When: WhenExpressions{WhenExpression{ @@ -2815,7 +2815,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "tasks-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.status)"}, }}, }}, @@ -2828,7 +2828,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "bar-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of bar is $(tasks.bar.status)"}, }}, }}, @@ -2841,7 +2841,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "bar-status", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.bar.status)"}}, }}, }}, @@ -2854,7 +2854,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "tasks-status", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.status)"}}, }}, }}, @@ -2867,7 +2867,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "notask-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.notask.status)"}, }}, }}, @@ -2895,7 +2895,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "notask-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.notask.status)"}, }}, }, { @@ -2916,7 +2916,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "notask-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of notask is $(tasks.notask.status)."}, }}, }}, @@ -2929,7 +2929,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "notask-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of $(tasks.taskname) is $(tasks.notask.status)."}, }}, }}, @@ -2972,7 +2972,7 @@ func TestMatrixIncompatibleAPIVersions(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }}, @@ -2989,7 +2989,7 @@ func TestMatrixIncompatibleAPIVersions(t *testing.T) { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }}, @@ -3041,10 +3041,10 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}, }}, @@ -3055,10 +3055,10 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, - Params: []Param{{ + Params: Params{{ Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}, }}, }}, @@ -3068,7 +3068,7 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeString, StringVal: "bar"}, @@ -3077,7 +3077,7 @@ func Test_validateMatrix(t *testing.T) { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "baz", Value: ParamValue{Type: ParamTypeString, StringVal: "baz"}, }}}, }}, @@ -3091,7 +3091,7 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}, @@ -3103,9 +3103,9 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "test", - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeString, StringVal: "bar"}}, @@ -3118,9 +3118,9 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "test", - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar"}}}, @@ -3137,14 +3137,14 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.foo-task.results.a-result)"}}, }}}, }, { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.bar-task.results.b-result)"}}, }}}, }}, @@ -3182,13 +3182,13 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }, { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.a-task.results.a-result)"}}, }}, }}, @@ -3202,14 +3202,14 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }}, finally: PipelineTaskList{{ Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.a-task.results.a-result)"}}, }}, }}, @@ -3223,20 +3223,20 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }, { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.a-task.results.a-result)"}}, }}, }}, finally: PipelineTaskList{{ Name: "c-task", TaskRef: &TaskRef{Name: "c-task"}, - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.a-task.results.a-result)"}}, }}, }}, @@ -3250,7 +3250,7 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }, { @@ -3272,7 +3272,7 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }}, @@ -3295,7 +3295,7 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }, { @@ -3362,7 +3362,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, { name: "single parameter with when expression", original: PipelineSpec{ @@ -3378,7 +3378,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, { name: "pipeline parameter nested inside task parameter", original: PipelineSpec{ @@ -3430,7 +3430,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, { name: "parameter evaluation with both tasks and final tasks", original: PipelineSpec{ @@ -3456,7 +3456,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, { name: "parameter references with bracket notation and special characters", original: PipelineSpec{ @@ -3501,7 +3501,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, } { tt := tt // capture range variable @@ -3540,7 +3540,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[2])]"), }, { name: "single parameter reference with when expression out of bound", @@ -3557,7 +3557,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[2])]"), }, { name: "pipeline parameter reference nested inside task parameter out of bound", @@ -3632,7 +3632,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[2])]"), }, { name: "parameter evaluation with both tasks and final tasks reference out of bound", @@ -3664,7 +3664,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.first-param[3]) $(params.first-param[4]) $(params.second-param[2]) $(params.second-param[3]) $(params.second-param[4])]"), }, { name: "parameter in matrix reference out of bound", @@ -3682,7 +3682,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2])]"), }, { name: "parameter references with bracket notation and special characters reference out of bound", @@ -3729,7 +3729,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[3])]"), }, } { diff --git a/pkg/apis/pipeline/v1/resultref_test.go b/pkg/apis/pipeline/v1/resultref_test.go index 50a815a2ed9..a019fc3320f 100644 --- a/pkg/apis/pipeline/v1/resultref_test.go +++ b/pkg/apis/pipeline/v1/resultref_test.go @@ -639,7 +639,7 @@ func TestPipelineTaskResultRefs(t *testing.T) { }, }}, Matrix: &v1.Matrix{ - Include: []v1.MatrixInclude{{ + Include: v1.IncludeParamsList{{ Name: "build-1", Params: []v1.Param{{ Name: "a-param", Value: *v1.NewStructuredValues("$(tasks.pt9.results.r9)"), diff --git a/pkg/apis/pipeline/v1/swagger.json b/pkg/apis/pipeline/v1/swagger.json index bdd3c65f616..a08d40d8846 100644 --- a/pkg/apis/pipeline/v1/swagger.json +++ b/pkg/apis/pipeline/v1/swagger.json @@ -285,21 +285,16 @@ } } }, - "v1.Matrix": { - "description": "Matrix is used to fan out Tasks in a Pipeline", + "v1.IncludeParams": { + "description": "IncludeParams allows passing in a specific combinations of Parameters into the Matrix. Note this struct is in preview mode and not yet supported", "type": "object", "properties": { - "include": { - "description": "Include is a list of MatrixInclude which allows passing in specific combinations of Parameters into the Matrix. Note that Include is in preview mode and not yet supported.", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1.MatrixInclude" - }, - "x-kubernetes-list-type": "atomic" + "name": { + "description": "Name the specified combination", + "type": "string" }, "params": { - "description": "Params is a list of parameters used to fan out the pipelineTask Params takes only `Parameters` of type `\"array\"` Each array element is supplied to the `PipelineTask` by substituting `params` of type `\"string\"` in the underlying `Task`. The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.", + "description": "Params takes only `Parameters` of type `\"string\"` The names of the `params` must match the names of the `params` in the underlying `Task`", "type": "array", "items": { "default": {}, @@ -309,16 +304,21 @@ } } }, - "v1.MatrixInclude": { - "description": "MatrixInclude allows passing in a specific combinations of Parameters into the Matrix. Note this struct is in preview mode and not yet supported", + "v1.Matrix": { + "description": "Matrix is used to fan out Tasks in a Pipeline", "type": "object", "properties": { - "name": { - "description": "Name the specified combination", - "type": "string" + "include": { + "description": "Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. Note that Include is in preview mode and not yet supported.", + "type": "array", + "items": { + "default": {}, + "$ref": "#/definitions/v1.IncludeParams" + }, + "x-kubernetes-list-type": "atomic" }, "params": { - "description": "Params takes only `Parameters` of type `\"string\"` The names of the `params` must match the names of the `params` in the underlying `Task`", + "description": "Params is a list of parameters used to fan out the pipelineTask Params takes only `Parameters` of type `\"array\"` Each array element is supplied to the `PipelineTask` by substituting `params` of type `\"string\"` in the underlying `Task`. The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.", "type": "array", "items": { "default": {}, diff --git a/pkg/apis/pipeline/v1/zz_generated.deepcopy.go b/pkg/apis/pipeline/v1/zz_generated.deepcopy.go index f08cf537027..7b0b58c4501 100644 --- a/pkg/apis/pipeline/v1/zz_generated.deepcopy.go +++ b/pkg/apis/pipeline/v1/zz_generated.deepcopy.go @@ -148,7 +148,7 @@ func (in *EmbeddedTask) DeepCopy() *EmbeddedTask { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Matrix) DeepCopyInto(out *Matrix) { +func (in *IncludeParams) DeepCopyInto(out *IncludeParams) { *out = *in if in.Params != nil { in, out := &in.Params, &out.Params @@ -157,28 +157,43 @@ func (in *Matrix) DeepCopyInto(out *Matrix) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.Include != nil { - in, out := &in.Include, &out.Include - *out = make([]MatrixInclude, len(*in)) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IncludeParams. +func (in *IncludeParams) DeepCopy() *IncludeParams { + if in == nil { + return nil + } + out := new(IncludeParams) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in IncludeParamsList) DeepCopyInto(out *IncludeParamsList) { + { + in := &in + *out = make(IncludeParamsList, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } + return } - return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Matrix. -func (in *Matrix) DeepCopy() *Matrix { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IncludeParamsList. +func (in IncludeParamsList) DeepCopy() IncludeParamsList { if in == nil { return nil } - out := new(Matrix) + out := new(IncludeParamsList) in.DeepCopyInto(out) - return out + return *out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MatrixInclude) DeepCopyInto(out *MatrixInclude) { +func (in *Matrix) DeepCopyInto(out *Matrix) { *out = *in if in.Params != nil { in, out := &in.Params, &out.Params @@ -187,15 +202,22 @@ func (in *MatrixInclude) DeepCopyInto(out *MatrixInclude) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Include != nil { + in, out := &in.Include, &out.Include + *out = make(IncludeParamsList, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MatrixInclude. -func (in *MatrixInclude) DeepCopy() *MatrixInclude { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Matrix. +func (in *Matrix) DeepCopy() *Matrix { if in == nil { return nil } - out := new(MatrixInclude) + out := new(Matrix) in.DeepCopyInto(out) return out } diff --git a/pkg/apis/pipeline/v1beta1/matrix_types.go b/pkg/apis/pipeline/v1beta1/matrix_types.go index 89797c7075b..45b80ae187f 100644 --- a/pkg/apis/pipeline/v1beta1/matrix_types.go +++ b/pkg/apis/pipeline/v1beta1/matrix_types.go @@ -34,16 +34,19 @@ type Matrix struct { // +listType=atomic Params Params `json:"params,omitempty"` - // Include is a list of MatrixInclude which allows passing in specific combinations of Parameters into the Matrix. + // Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. // Note that Include is in preview mode and not yet supported. // +optional // +listType=atomic - Include []MatrixInclude `json:"include,omitempty"` + Include IncludeParamsList `json:"include,omitempty"` } -// MatrixInclude allows passing in a specific combinations of Parameters into the Matrix. +// IncludeParamsList is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. +type IncludeParamsList []IncludeParams + +// IncludeParams allows passing in a specific combinations of Parameters into the Matrix. // Note this struct is in preview mode and not yet supported -type MatrixInclude struct { +type IncludeParams struct { // Name the specified combination Name string `json:"name,omitempty"` @@ -56,21 +59,30 @@ type MatrixInclude struct { // Combination is a map, mainly defined to hold a single combination from a Matrix with key as param.Name and value as param.Value type Combination map[string]string -// Combinations is a list of combination +// Combinations is a Combination list type Combinations []Combination -// ToParams transforms Combinations from a slice of map[string]string to a slice of Params -// such that, the combinations can be directly consumed in creating taskRun/run object -func (cs Combinations) ToParams() []Params { +// FanOut returns an list of params that represent combinations +func (m *Matrix) FanOut() []Params { + var combinations Combinations + for _, parameter := range m.Params { + combinations = combinations.fanOutMatrixParams(parameter) + } + return combinations.toParams() +} + +// toParams transforms Combinations from a slice of map[string]string to a slice of Params +// such that, these combinations can be directly consumed in creating taskRun/run object +func (cs Combinations) toParams() []Params { listOfParams := make([]Params, len(cs)) for i := range cs { var params Params combination := cs[i] - order, sortedCombination := combination.sortCombination() + order, _ := combination.sortCombination() for _, key := range order { params = append(params, Param{ Name: key, - Value: ParamValue{Type: ParamTypeString, StringVal: sortedCombination[key]}, + Value: ParamValue{Type: ParamTypeString, StringVal: combination[key]}, }) } listOfParams[i] = params @@ -78,15 +90,15 @@ func (cs Combinations) ToParams() []Params { return listOfParams } -// fanOut generates a new combination based on a given Parameter in the Matrix. -func (cs Combinations) fanOut(param Param) Combinations { +// fanOutMatrixParams generates new combinations based on Matrix Parameters. +func (cs Combinations) fanOutMatrixParams(param Param) Combinations { if len(cs) == 0 { return initializeCombinations(param) } return cs.distribute(param) } -// distribute generates a new combination of Parameters by adding a new Parameter to an existing list of Combinations. +// distribute generates a new Combination of Parameters by adding a new Parameter to an existing list of Combinations. func (cs Combinations) distribute(param Param) Combinations { var expandedCombinations Combinations for _, value := range param.Value.ArrayVal { @@ -101,7 +113,7 @@ func (cs Combinations) distribute(param Param) Combinations { return expandedCombinations } -// initializeCombinations generates a new combination based on the first Parameter in the Matrix. +// initializeCombinations generates a new Combination based on the first Parameter in the Matrix. func initializeCombinations(param Param) Combinations { var combinations Combinations for _, value := range param.Value.ArrayVal { @@ -110,7 +122,7 @@ func initializeCombinations(param Param) Combinations { return combinations } -// sortCombination sorts the given Combination based on the param names to produce a deterministic ordering +// sortCombination sorts the given Combination based on the Parameter names to produce a deterministic ordering func (c Combination) sortCombination() ([]string, Combination) { sortedCombination := make(Combination, len(c)) order := make([]string, 0, len(c)) @@ -126,30 +138,21 @@ func (c Combination) sortCombination() ([]string, Combination) { return order, sortedCombination } -// FanOut produces combinations of Parameters of type String from a slice of Parameters of type Array. -func (m *Matrix) FanOut() Combinations { - var combinations Combinations - for _, parameter := range m.Params { - combinations = combinations.fanOut(parameter) - } - return combinations -} - -// CountCombinations returns the count of combinations of Parameters generated from the Matrix in PipelineTask. +// CountCombinations returns the count of Combinations of Parameters generated from the Matrix in PipelineTask. func (m *Matrix) CountCombinations() int { - // Iterate over matrix.params and compute count of all generated combinations + // Iterate over Matrix Parameters and compute count of all generated Combinations count := m.countGeneratedCombinationsFromParams() - // Add any additional combinations generated from matrix include params + // Add any additional Combinations generated from Matrix Include Parameters count += m.countNewCombinationsFromInclude() return count } -// countGeneratedCombinationsFromParams returns the count of combinations of Parameters generated from the matrix -// parameters +// countGeneratedCombinationsFromParams returns the count of Combinations of Parameters generated from the Matrix +// Parameters func (m *Matrix) countGeneratedCombinationsFromParams() int { - if !m.hasParams() { + if !m.HasParams() { return 0 } count := 1 @@ -159,13 +162,13 @@ func (m *Matrix) countGeneratedCombinationsFromParams() int { return count } -// countNewCombinationsFromInclude returns the count of combinations of Parameters generated from the matrix -// include parameters +// countNewCombinationsFromInclude returns the count of Combinations of Parameters generated from the Matrix +// Include Parameters func (m *Matrix) countNewCombinationsFromInclude() int { - if !m.hasInclude() { + if !m.HasInclude() { return 0 } - if !m.hasParams() { + if !m.HasParams() { return len(m.Include) } count := 0 @@ -173,7 +176,7 @@ func (m *Matrix) countNewCombinationsFromInclude() int { for _, include := range m.Include { for _, param := range include.Params { if val, exist := matrixParamMap[param.Name]; exist { - // If the matrix include param values does not exist, a new combination will be generated + // If the Matrix Include param values does not exist, a new Combination will be generated if !slices.Contains(val, param.Value.StringVal) { count++ } else { @@ -185,25 +188,28 @@ func (m *Matrix) countNewCombinationsFromInclude() int { return count } -func (m *Matrix) hasInclude() bool { +// HasInclude returns true if the Matrix has Include Parameters +func (m *Matrix) HasInclude() bool { return m != nil && m.Include != nil && len(m.Include) > 0 } -func (m *Matrix) hasParams() bool { +// HasParams returns true if the Matrix has Parameters +func (m *Matrix) HasParams() bool { return m != nil && m.Params != nil && len(m.Params) > 0 } -func (m *Matrix) getParamNames() []string { - var names []string - if m.hasParams() { - names = m.Params.extractNames() +// GetAllParams returns a list of all Matrix Parameters +func (m *Matrix) GetAllParams() Params { + var params Params + if m.HasParams() { + params = append(params, m.Params...) } - if m.hasInclude() { + if m.HasInclude() { for _, include := range m.Include { - names = append(names, include.Params.extractNames()...) + params = append(params, include.Params...) } } - return names + return params } func (m *Matrix) validateCombinationsCount(ctx context.Context) (errs *apis.FieldError) { @@ -215,14 +221,13 @@ func (m *Matrix) validateCombinationsCount(ctx context.Context) (errs *apis.Fiel return errs } -// validateParams validates the type of parameter -// for Matrix.Params and Matrix.Include.Params +// validateParams validates the type of Parameter for Matrix.Params and Matrix.Include.Params // Matrix.Params must be of type array. Matrix.Include.Params must be of type string. // validateParams also validates Matrix.Params for a unique list of params // and a unique list of params in each Matrix.Include.Params specification func (m *Matrix) validateParams() (errs *apis.FieldError) { if m != nil { - if m.hasInclude() { + if m.HasInclude() { for i, include := range m.Include { errs = errs.Also(include.Params.validateDuplicateParameters().ViaField(fmt.Sprintf("matrix.include[%d].params", i))) for _, param := range include.Params { @@ -232,7 +237,7 @@ func (m *Matrix) validateParams() (errs *apis.FieldError) { } } } - if m.hasParams() { + if m.HasParams() { errs = errs.Also(m.Params.validateDuplicateParameters().ViaField("matrix.params")) for _, param := range m.Params { if param.Value.Type != ParamTypeArray { @@ -244,10 +249,10 @@ func (m *Matrix) validateParams() (errs *apis.FieldError) { return errs } -// validatePipelineParametersVariablesInMatrixParameters validates all pipeline paramater variables including Matrix.Params and Matrix.Include.Params +// validatePipelineParametersVariablesInMatrixParameters validates all pipeline parameter variables including Matrix.Params and Matrix.Include.Params // that may contain the reference(s) to other params to make sure those references are used appropriately. func (m *Matrix) validatePipelineParametersVariablesInMatrixParameters(prefix string, paramNames sets.String, arrayParamNames sets.String, objectParamNameKeys map[string][]string) (errs *apis.FieldError) { - if m.hasInclude() { + if m.HasInclude() { for _, include := range m.Include { for idx, param := range include.Params { stringElement := param.Value.StringVal @@ -256,7 +261,7 @@ func (m *Matrix) validatePipelineParametersVariablesInMatrixParameters(prefix st } } } - if m.hasParams() { + if m.HasParams() { for _, param := range m.Params { for idx, arrayElement := range param.Value.ArrayVal { // Matrix Params must be of type array @@ -268,7 +273,7 @@ func (m *Matrix) validatePipelineParametersVariablesInMatrixParameters(prefix st } func (m *Matrix) validateParameterInOneOfMatrixOrParams(params []Param) (errs *apis.FieldError) { - matrixParamNames := sets.NewString(m.getParamNames()...) + matrixParamNames := m.GetAllParams().ExtractNames() for _, param := range params { if matrixParamNames.Has(param.Name) { errs = errs.Also(apis.ErrMultipleOneOf("matrix["+param.Name+"]", "params["+param.Name+"]")) diff --git a/pkg/apis/pipeline/v1beta1/matrix_types_test.go b/pkg/apis/pipeline/v1beta1/matrix_types_test.go index be058a74a34..6471db631be 100644 --- a/pkg/apis/pipeline/v1beta1/matrix_types_test.go +++ b/pkg/apis/pipeline/v1beta1/matrix_types_test.go @@ -20,19 +20,17 @@ import ( "github.com/tektoncd/pipeline/test/diff" ) -func TestMatrix_FanOut_ToParams(t *testing.T) { +func TestMatrix_FanOut(t *testing.T) { tests := []struct { - name string - matrix Matrix - want Combinations - expectedParams []Params + name string + matrix Matrix + want []Params }{{ name: "matrix with no params", matrix: Matrix{ Params: Params{}, }, - want: nil, - expectedParams: nil, + want: []Params{}, }, { name: "single array in matrix", matrix: Matrix{ @@ -41,14 +39,7 @@ func TestMatrix_FanOut_ToParams(t *testing.T) { Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, }}, }, - want: Combinations{{ - "platform": "linux", - }, { - "platform": "mac", - }, { - "platform": "windows", - }}, - expectedParams: []Params{{ + want: []Params{{ { Name: "platform", Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, @@ -67,111 +58,60 @@ func TestMatrix_FanOut_ToParams(t *testing.T) { }, { name: "multiple arrays in matrix", matrix: Matrix{ - Params: []Param{{ - Name: "platform", - Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, - }, { - Name: "browser", - Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"chrome", "safari", "firefox"}}, - }}}, - want: Combinations{{ - "browser": "chrome", - "platform": "linux", - }, { - "browser": "chrome", - "platform": "mac", - }, { - "browser": "chrome", - "platform": "windows", - }, { - "browser": "safari", - "platform": "linux", - }, { - "browser": "safari", - "platform": "mac", - }, { - "browser": "safari", - "platform": "windows", - }, { - "browser": "firefox", - "platform": "linux", - }, { - "browser": "firefox", - "platform": "mac", - }, { - "browser": "firefox", - "platform": "windows", - }}, - expectedParams: []Params{{ - { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "chrome"}, - }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, - }, - }, { - { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "chrome"}, + Params: Params{{ + Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "mac"}, + Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - }, { + Include: IncludeParamsList{{}}, + }, + want: []Params{{ { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "chrome"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "windows"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "safari"}, - }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, - }}, { - { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "safari"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "mac"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "safari"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "windows"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.17"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "firefox"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/amd64"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "linux"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "firefox"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/ppc64le"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "mac"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, }, }, { { - Name: "browser", - Value: ParamValue{Type: ParamTypeString, StringVal: "firefox"}, + Name: "GOARCH", + Value: ParamValue{Type: ParamTypeString, StringVal: "linux/s390x"}, }, { - Name: "platform", - Value: ParamValue{Type: ParamTypeString, StringVal: "windows"}, + Name: "version", + Value: ParamValue{Type: ParamTypeString, StringVal: "go1.18.1"}, }, }}, }} @@ -180,12 +120,6 @@ func TestMatrix_FanOut_ToParams(t *testing.T) { if d := cmp.Diff(tt.want, tt.matrix.FanOut()); d != "" { t.Errorf("Combinations of Parameters did not match the expected Params: %s", diff.PrintWantGot(d)) } - c := tt.matrix.FanOut().ToParams() - for i := range c { - if d := cmp.Diff(tt.expectedParams[i], c[i]); d != "" { - t.Errorf("The formatted Combinations of Parameters did not match the expected Params: %s", diff.PrintWantGot(d)) - } - } }) } } @@ -215,7 +149,7 @@ func TestMatrix_HasParams(t *testing.T) { }, { name: "matrixed with include", matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", Params: []Param{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, @@ -227,12 +161,12 @@ func TestMatrix_HasParams(t *testing.T) { }, { name: "matrixed with params and include", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", - Params: []Param{{ + Params: Params{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, @@ -241,8 +175,8 @@ func TestMatrix_HasParams(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - if d := cmp.Diff(tc.want, tc.matrix.hasParams()); d != "" { - t.Errorf("matrix.hasParams() bool diff %s", diff.PrintWantGot(d)) + if d := cmp.Diff(tc.want, tc.matrix.HasParams()); d != "" { + t.Errorf("matrix.HasParams() bool diff %s", diff.PrintWantGot(d)) } }) } @@ -267,15 +201,15 @@ func TestMatrix_HasInclude(t *testing.T) { { name: "matrixed with params", matrix: &Matrix{ - Params: []Param{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, want: false, }, { name: "matrixed with include", matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, }, { Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, @@ -285,12 +219,12 @@ func TestMatrix_HasInclude(t *testing.T) { }, { name: "matrixed with params and include", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", - Params: []Param{{ + Params: Params{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, @@ -299,8 +233,74 @@ func TestMatrix_HasInclude(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - if d := cmp.Diff(tc.want, tc.matrix.hasInclude()); d != "" { - t.Errorf("matrix.hasInclude() bool diff %s", diff.PrintWantGot(d)) + if d := cmp.Diff(tc.want, tc.matrix.HasInclude()); d != "" { + t.Errorf("matrix.HasInclude() bool diff %s", diff.PrintWantGot(d)) + } + }) + } +} + +func TestMatrix_GetAllParams(t *testing.T) { + testCases := []struct { + name string + matrix *Matrix + want Params + }{ + { + name: "nil matrix", + matrix: nil, + want: nil, + }, + { + name: "empty matrix", + matrix: &Matrix{}, + want: nil, + }, + { + name: "matrixed with params", + matrix: &Matrix{ + Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + }, + want: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + }, { + name: "matrixed with include", + matrix: &Matrix{ + Include: IncludeParamsList{{ + Name: "build-1", + Params: Params{{ + Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + }, { + Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + }}, + }, + want: Params{{ + Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, + }, { + Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + }, + { + name: "matrixed with params and include", + matrix: &Matrix{ + Params: Params{{ + Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + }}, + Include: IncludeParamsList{{ + Name: "common-package", + Params: Params{{ + Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, + }}, + }, + want: Params{{ + Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + }, { + Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}, + }}, + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + if d := cmp.Diff(tc.want, tc.matrix.GetAllParams()); d != "" { + t.Errorf("matrix.GetAllParams() bool diff %s", diff.PrintWantGot(d)) } }) } @@ -314,12 +314,12 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }{{ name: "combinations count is zero", matrix: &Matrix{ - Params: []Param{{}}}, + Params: Params{{}}}, want: 0, }, { name: "combinations count is one from one parameter", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, }}}, @@ -327,7 +327,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { name: "combinations count is one from two parameters", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar"}}, @@ -336,14 +336,14 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { name: "combinations count is two from one parameter", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, want: 2, }, { name: "combinations count is nine", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, @@ -352,7 +352,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { name: "combinations count is large", matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"f", "o", "o"}}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"b", "a", "r"}}, @@ -365,7 +365,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { name: "explicit combinations in the matrix", matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", Params: []Param{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, @@ -397,7 +397,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", Params: []Param{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, @@ -424,7 +424,7 @@ func TestPipelineTask_CountCombinations(t *testing.T) { }, { Name: "version", Value: ParamValue{ArrayVal: []string{"go1.17", "go1.18.1"}}}, }, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", Params: []Param{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, diff --git a/pkg/apis/pipeline/v1beta1/openapi_generated.go b/pkg/apis/pipeline/v1beta1/openapi_generated.go index c668bd6c1f1..92bbcf4afd3 100644 --- a/pkg/apis/pipeline/v1beta1/openapi_generated.go +++ b/pkg/apis/pipeline/v1beta1/openapi_generated.go @@ -43,8 +43,8 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.CustomRunSpec": schema_pkg_apis_pipeline_v1beta1_CustomRunSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.EmbeddedCustomRunSpec": schema_pkg_apis_pipeline_v1beta1_EmbeddedCustomRunSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.EmbeddedTask": schema_pkg_apis_pipeline_v1beta1_EmbeddedTask(ref), + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.IncludeParams": schema_pkg_apis_pipeline_v1beta1_IncludeParams(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Matrix": schema_pkg_apis_pipeline_v1beta1_Matrix(ref), - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.MatrixInclude": schema_pkg_apis_pipeline_v1beta1_MatrixInclude(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param": schema_pkg_apis_pipeline_v1beta1_Param(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamSpec": schema_pkg_apis_pipeline_v1beta1_ParamSpec(ref), "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.ParamValue": schema_pkg_apis_pipeline_v1beta1_ParamValue(ref), @@ -1059,46 +1059,34 @@ func schema_pkg_apis_pipeline_v1beta1_EmbeddedTask(ref common.ReferenceCallback) } } -func schema_pkg_apis_pipeline_v1beta1_Matrix(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_pipeline_v1beta1_IncludeParams(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "Matrix is used to fan out Tasks in a Pipeline", + Description: "IncludeParams allows passing in a specific combinations of Parameters into the Matrix. Note this struct is in preview mode and not yet supported", Type: []string{"object"}, Properties: map[string]spec.Schema{ - "params": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, + "name": { SchemaProps: spec.SchemaProps{ - Description: "Params is a list of parameters used to fan out the pipelineTask Params takes only `Parameters` of type `\"array\"` Each array element is supplied to the `PipelineTask` by substituting `params` of type `\"string\"` in the underlying `Task`. The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param"), - }, - }, - }, + Description: "Name the specified combination", + Type: []string{"string"}, + Format: "", }, }, - "include": { + "params": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ "x-kubernetes-list-type": "atomic", }, }, SchemaProps: spec.SchemaProps{ - Description: "Include is a list of MatrixInclude which allows passing in specific combinations of Parameters into the Matrix. Note that Include is in preview mode and not yet supported.", + Description: "Params takes only `Parameters` of type `\"string\"` The names of the `params` must match the names of the `params` in the underlying `Task`", Type: []string{"array"}, Items: &spec.SchemaOrArray{ Schema: &spec.Schema{ SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.MatrixInclude"), + Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param"), }, }, }, @@ -1108,38 +1096,50 @@ func schema_pkg_apis_pipeline_v1beta1_Matrix(ref common.ReferenceCallback) commo }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.MatrixInclude", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param"}, } } -func schema_pkg_apis_pipeline_v1beta1_MatrixInclude(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_pipeline_v1beta1_Matrix(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "MatrixInclude allows passing in a specific combinations of Parameters into the Matrix. Note this struct is in preview mode and not yet supported", + Description: "Matrix is used to fan out Tasks in a Pipeline", Type: []string{"object"}, Properties: map[string]spec.Schema{ - "name": { + "params": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-list-type": "atomic", + }, + }, SchemaProps: spec.SchemaProps{ - Description: "Name the specified combination", - Type: []string{"string"}, - Format: "", + Description: "Params is a list of parameters used to fan out the pipelineTask Params takes only `Parameters` of type `\"array\"` Each array element is supplied to the `PipelineTask` by substituting `params` of type `\"string\"` in the underlying `Task`. The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param"), + }, + }, + }, }, }, - "params": { + "include": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ "x-kubernetes-list-type": "atomic", }, }, SchemaProps: spec.SchemaProps{ - Description: "Params takes only `Parameters` of type `\"string\"` The names of the `params` must match the names of the `params` in the underlying `Task`", + Description: "Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. Note that Include is in preview mode and not yet supported.", Type: []string{"array"}, Items: &spec.SchemaOrArray{ Schema: &spec.Schema{ SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param"), + Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.IncludeParams"), }, }, }, @@ -1149,7 +1149,7 @@ func schema_pkg_apis_pipeline_v1beta1_MatrixInclude(ref common.ReferenceCallback }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.IncludeParams", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param"}, } } diff --git a/pkg/apis/pipeline/v1beta1/param_types.go b/pkg/apis/pipeline/v1beta1/param_types.go index e15c3619950..791a4e3c75b 100644 --- a/pkg/apis/pipeline/v1beta1/param_types.go +++ b/pkg/apis/pipeline/v1beta1/param_types.go @@ -112,10 +112,11 @@ type Param struct { // Params is a list of Param type Params []Param -func (ps Params) extractNames() []string { - names := []string{} +// ExtractNames returns a set of unique names +func (ps Params) ExtractNames() sets.String { + names := sets.String{} for _, p := range ps { - names = append(names, p.Name) + names.Insert(p.Name) } return names } diff --git a/pkg/apis/pipeline/v1beta1/param_types_test.go b/pkg/apis/pipeline/v1beta1/param_types_test.go index cd1cccff074..f0669d34efc 100644 --- a/pkg/apis/pipeline/v1beta1/param_types_test.go +++ b/pkg/apis/pipeline/v1beta1/param_types_test.go @@ -26,6 +26,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/test/diff" + "k8s.io/apimachinery/pkg/util/sets" ) func TestParamSpec_SetDefaults(t *testing.T) { @@ -484,3 +485,41 @@ func TestArrayOrString(t *testing.T) { } } } + +func TestExtractNames(t *testing.T) { + tests := []struct { + name string + params v1beta1.Params + want sets.String + }{{ + name: "no params", + params: v1beta1.Params{{}}, + want: sets.NewString(""), + }, { + name: "extract param names from ParamTypeString", + params: v1beta1.Params{{ + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-1"}, + }, { + Name: "DOCKERFILE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, + want: sets.NewString("IMAGE", "DOCKERFILE"), + }, { + name: "extract param names from ParamTypeArray", + params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + }}, + want: sets.NewString("GOARCH"), + }, { + name: "extract param names from ParamTypeString and ParamTypeArray", + params: v1beta1.Params{{ + Name: "GOARCH", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, + }, { + Name: "IMAGE", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "image-1"}, + }}, + want: sets.NewString("GOARCH", "IMAGE"), + }} + for _, tt := range tests { + if d := cmp.Diff(tt.want, v1beta1.Params.ExtractNames(tt.params)); d != "" { + t.Errorf(diff.PrintWantGot(d)) + } + } +} diff --git a/pkg/apis/pipeline/v1beta1/pipeline_conversion.go b/pkg/apis/pipeline/v1beta1/pipeline_conversion.go index aa4eb5250ae..5299aa9ccf9 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_conversion.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_conversion.go @@ -260,7 +260,7 @@ func (m *Matrix) convertTo(ctx context.Context, sink *v1.Matrix) { sink.Params = append(sink.Params, new) } for i, include := range m.Include { - sink.Include = append(sink.Include, v1.MatrixInclude{Name: include.Name}) + sink.Include = append(sink.Include, v1.IncludeParams{Name: include.Name}) for _, param := range include.Params { newIncludeParam := v1.Param{} param.convertTo(ctx, &newIncludeParam) @@ -277,7 +277,7 @@ func (m *Matrix) convertFrom(ctx context.Context, source v1.Matrix) { } for i, include := range source.Include { - m.Include = append(m.Include, MatrixInclude{Name: include.Name}) + m.Include = append(m.Include, IncludeParams{Name: include.Name}) for _, p := range include.Params { new := Param{} new.convertFrom(ctx, p) diff --git a/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go b/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go index 6ac83aa259c..0fb96de35d3 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go @@ -115,7 +115,7 @@ func TestPipelineConversion(t *testing.T) { ArrayVal: []string{"$(params.baz)", "and", "$(params.foo-is-baz)"}, }, }}, - Include: []v1beta1.MatrixInclude{{ + Include: v1beta1.IncludeParamsList{{ Name: "baz", Params: v1beta1.Params{{ Name: "a-param", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "$(params.baz)"}, diff --git a/pkg/apis/pipeline/v1beta1/pipeline_types.go b/pkg/apis/pipeline/v1beta1/pipeline_types.go index e35d7781fcb..2ea11155148 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_types.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_types.go @@ -280,7 +280,7 @@ func (pt PipelineTask) validateTask(ctx context.Context) (errs *apis.FieldError) // IsMatrixed return whether pipeline task is matrixed func (pt *PipelineTask) IsMatrixed() bool { - return pt.Matrix != nil && (pt.Matrix.hasParams() || pt.Matrix.hasInclude()) + return pt.Matrix.HasParams() || pt.Matrix.HasInclude() } // extractAllParams extracts all the parameters in a PipelineTask: @@ -289,10 +289,10 @@ func (pt *PipelineTask) IsMatrixed() bool { // - pt.Matrix.Include.Params func (pt *PipelineTask) extractAllParams() Params { allParams := pt.Params - if pt.Matrix.hasParams() { + if pt.Matrix.HasParams() { allParams = append(allParams, pt.Matrix.Params...) } - if pt.Matrix.hasInclude() { + if pt.Matrix.HasInclude() { for _, include := range pt.Matrix.Include { allParams = append(allParams, include.Params...) } diff --git a/pkg/apis/pipeline/v1beta1/pipeline_types_test.go b/pkg/apis/pipeline/v1beta1/pipeline_types_test.go index 10e63ba5ef5..a0e1d8d9102 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_types_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_types_test.go @@ -419,7 +419,7 @@ func TestPipelineTaskList_Deps(t *testing.T) { Name: "task-1", }, { Name: "task-2", - Params: []Param{{ + Params: Params{{ Value: ParamValue{ Type: "string", StringVal: "$(tasks.task-1.results.result)", @@ -436,7 +436,7 @@ func TestPipelineTaskList_Deps(t *testing.T) { }, { Name: "task-2", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Value: ParamValue{ Type: ParamTypeArray, ArrayVal: []string{ @@ -572,10 +572,10 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}, }, @@ -585,13 +585,13 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "duplicate-param", Params: Params{{ Name: "duplicate", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, }}}, }}, - Params: []Param{{ + Params: Params{{ Name: "duplicate", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}, }, @@ -601,7 +601,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }, { Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo-1", "bar-1"}}, @@ -616,10 +616,10 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, - Params: []Param{{ + Params: Params{{ Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}, }}, }, @@ -628,7 +628,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeString, StringVal: "bar"}, @@ -643,7 +643,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}, @@ -654,7 +654,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "invalid-include", Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, @@ -672,9 +672,9 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, }, { Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}, @@ -686,9 +686,9 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "barfoo", Value: ParamValue{Type: ParamTypeObject, ObjectVal: map[string]string{ "url": "$(params.myObject.non-exist-key)", "commit": "$(params.myString)", @@ -710,9 +710,9 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}}}, @@ -727,7 +727,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.foo-task.results.a-result)"}}, }}}, }, @@ -736,7 +736,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "platform", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}}, }, { Name: "browser", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"chrome", "firefox", "safari"}}, @@ -751,7 +751,7 @@ func TestPipelineTask_validateMatrix(t *testing.T) { pt: &PipelineTask{ Name: "task", Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "platform", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"linux", "mac"}}, }, { Name: "browser", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"chrome", "firefox"}}, @@ -892,7 +892,7 @@ func TestPipelineTask_IsMatrixed(t *testing.T) { name: "matrixed with params", arg: arg{ Matrix: &Matrix{ - Params: []Param{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, + Params: Params{{Name: "platform", Value: ParamValue{ArrayVal: []string{"linux", "windows"}}}}, }, }, expected: true, @@ -900,9 +900,9 @@ func TestPipelineTask_IsMatrixed(t *testing.T) { name: "matrixed with include", arg: arg{ Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "IMAGE", Value: ParamValue{Type: ParamTypeString, StringVal: "image-1"}, }, { Name: "DOCKERFILE", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/Dockerfile1"}}}, @@ -914,12 +914,12 @@ func TestPipelineTask_IsMatrixed(t *testing.T) { name: "matrixed with params and include", arg: arg{ Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "GOARCH", Value: ParamValue{ArrayVal: []string{"linux/amd64", "linux/ppc64le", "linux/s390x"}}, }}, - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "common-package", - Params: []Param{{ + Params: Params{{ Name: "package", Value: ParamValue{Type: ParamTypeString, StringVal: "path/to/common/package/"}}}, }}, }, diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go index bb4e2e5ab5c..a4e5f499f0c 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go @@ -469,7 +469,7 @@ func TestPipelineSpec_Validate_Failure(t *testing.T) { }, { Name: "invalid-pipeline-task", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "prefix", Value: ParamValue{Type: ParamTypeString, StringVal: "bar"}, }}, WhenExpressions: []WhenExpression{{ @@ -1006,7 +1006,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.baz) and $(params.foo-is-baz)"}, }}, }}, @@ -1056,7 +1056,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.baz)", "and", "$(params.foo-is-baz)"}}, }}, }}, @@ -1070,7 +1070,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.baz[*])", "and", "$(params.foo-is-baz[*])"}}, }}, }}, @@ -1082,7 +1082,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(input.workspace.$(params.baz))"}, }}, }}, @@ -1097,7 +1097,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.baz)", "and", "$(params.foo-is-baz)"}}, }}}, }}, @@ -1112,7 +1112,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.baz[*])", "and", "$(params.foo-is-baz[*])"}}, }}}, }}, @@ -1125,7 +1125,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param-intended-to-be-array", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myArray[*])"}, }}, }}, @@ -1138,9 +1138,9 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.baz)"}}, }}}}, }}, @@ -1157,7 +1157,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-string-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myObject.key1)"}, }}, }}, @@ -1174,7 +1174,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-string-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myObject.key1) and $(params.myObject.key2)"}, }}, }}, @@ -1191,7 +1191,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "an-array-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.key1)", "another one $(params.myObject.key2)"}}, }}, }}, @@ -1211,7 +1211,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "an-object-param", Value: ParamValue{Type: ParamTypeObject, ObjectVal: map[string]string{ "url": "$(params.myObject.key1)", "commit": "$(params.myString)", @@ -1232,7 +1232,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.key1)", "and", "$(params.myObject.key2)"}}, }}}, }}, @@ -1249,7 +1249,7 @@ func TestValidatePipelineParameterVariables_Success(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param-intended-to-be-object", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myObject[*])"}, }}, }}, @@ -1299,7 +1299,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.does-not-exist)"}, }}, }}, @@ -1381,7 +1381,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.foo) and $(params.does-not-exist)"}, }}, }}, @@ -1397,7 +1397,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.foo)"}, }, { Name: "b-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.does-not-exist)"}, @@ -1454,7 +1454,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.baz)"}, }}, }}, @@ -1470,7 +1470,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.baz[*])"}, }}, }}, @@ -1486,7 +1486,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"value: $(params.baz)", "last"}}, }}, }}, @@ -1502,7 +1502,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"value: $(params.baz[*])", "last"}}, }}, }}, @@ -1561,7 +1561,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.does-not-exist)"}}, }}}, }}, @@ -1578,7 +1578,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.foo)", "and", "$(params.does-not-exist)"}}, }}}, }}, @@ -1595,7 +1595,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.foo)"}}, }, { Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.does-not-exist)"}}}}}, @@ -1613,8 +1613,8 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ - Params: []Param{{ + Include: IncludeParamsList{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.foo)"}, }, { Name: "b-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.does-not-exist)"}, @@ -1686,7 +1686,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.non-exist-key)", "last"}}, }}, }}, @@ -1708,7 +1708,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.myObject.non-exist-key)"}, }}, }}, @@ -1733,7 +1733,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "an-object-param", Value: ParamValue{Type: ParamTypeObject, ObjectVal: map[string]string{ "url": "$(params.myObject.non-exist-key)", "commit": "$(params.myString)", @@ -1759,7 +1759,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.key1)"}}, }, { Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(params.myObject.non-exist-key)"}}, @@ -1775,7 +1775,7 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) { tasks: []PipelineTask{{ Name: "foo-task", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "duplicate-param", Value: ParamValue{Type: ParamTypeString, StringVal: "val1"}, }, { Name: "duplicate-param", Value: ParamValue{Type: ParamTypeString, StringVal: "val2"}, @@ -2028,7 +2028,7 @@ func TestValidatePipelineWithFinalTasks_Success(t *testing.T) { Finally: []PipelineTask{{ Name: "final-task-1", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.non-final-task.results.output)"}, }}, }}, @@ -2046,7 +2046,7 @@ func TestValidatePipelineWithFinalTasks_Success(t *testing.T) { Finally: []PipelineTask{{ Name: "final-task-1", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineRun.name)"}, }}, }}, @@ -2216,7 +2216,7 @@ func TestValidatePipelineWithFinalTasks_Failure(t *testing.T) { Finally: []PipelineTask{{ Name: "final-task", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "final-param", Value: ParamValue{Type: ParamTypeString, StringVal: "$(params.foo) and $(params.does-not-exist)"}, }}, }}, @@ -2291,7 +2291,7 @@ func TestValidatePipelineWithFinalTasks_Failure(t *testing.T) { Finally: []PipelineTask{{ Name: "final-task-1", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineRun.missing)"}, }}, }}, @@ -2394,7 +2394,7 @@ func TestValidateFinalTasks_Failure(t *testing.T) { }, { Name: "final-task-2", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.final-task-1.results.output)"}, }}, }}, @@ -2425,7 +2425,7 @@ func TestValidateFinalTasks_Failure(t *testing.T) { finalTasks: []PipelineTask{{ Name: "final-task", TaskRef: &TaskRef{Name: "final-task"}, - Params: []Param{{ + Params: Params{{ Name: "param1", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.no-dag-task-1.results.output)"}, }}, }}, @@ -2456,11 +2456,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipeline.name)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.name)"}}, }}}, }}, @@ -2469,11 +2469,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineRun.name)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipelineRun.name)"}}, }}}, }}, @@ -2482,11 +2482,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineRun.namespace)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipelineRun.namespace)"}}, }}}, }}, @@ -2495,11 +2495,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineRun.uid)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipelineRun.uid)"}}, }}}, }}, @@ -2508,11 +2508,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.name)", "and", "$(context.pipelineRun.name)"}}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.name)", "and", "$(context.pipelineRun.name)"}}, }}}, }}, @@ -2521,11 +2521,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineTask.retries)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineTask.retries)"}, }}}, }}, @@ -2534,11 +2534,11 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{ArrayVal: []string{"$(context.pipelineTask.retries)"}}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{ArrayVal: []string{"$(context.pipelineTask.retries)"}}, }}}, }}, @@ -2547,13 +2547,13 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipeline.name)"}, }}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipeline.name)"}}}, }}}, }}, @@ -2562,13 +2562,13 @@ func TestContextValid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineTask.retries)"}, }}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-mat", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineTask.retries)"}}}, }}}, }}, @@ -2592,11 +2592,11 @@ func TestContextInvalid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipeline.missing)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.missing-foo)"}}, }}}, }}, @@ -2612,11 +2612,11 @@ func TestContextInvalid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineRun.missing)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{ArrayVal: []string{"$(context.pipelineRun.missing-foo)"}}, }}}, }}, @@ -2632,11 +2632,11 @@ func TestContextInvalid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{StringVal: "$(context.pipelineTask.missing)"}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{ArrayVal: []string{"$(context.pipelineTask.missing-foo)"}}, }}}, }}, @@ -2652,11 +2652,11 @@ func TestContextInvalid(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.missing)", "$(context.pipelineTask.missing)", "$(context.pipelineRun.missing)"}}, }}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{ArrayVal: []string{"$(context.pipeline.missing-foo)", "$(context.pipelineTask.missing-foo)", "$(context.pipelineRun.missing-foo)"}}, }}}, }}, @@ -2672,9 +2672,9 @@ func TestContextInvalid(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipeline.missing)"}}}, }}}, }}, @@ -2688,9 +2688,9 @@ func TestContextInvalid(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineRun.missing)"}}}, }}}, }}, @@ -2704,9 +2704,9 @@ func TestContextInvalid(t *testing.T) { Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "build-1", - Params: []Param{{ + Params: Params{{ Name: "a-param-foo", Value: ParamValue{Type: ParamTypeString, StringVal: "$(context.pipelineTask.missing)"}}}, }}}, }}, @@ -2742,7 +2742,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "foo-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.foo.status)"}, }, { Name: "tasks-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.status)"}, @@ -2762,7 +2762,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "foo-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.foo.results.status)"}, }}, WhenExpressions: WhenExpressions{WhenExpression{ @@ -2779,7 +2779,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "foo-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of foo is $(tasks.foo.status)."}, }}, }}, @@ -2791,7 +2791,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "foo-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of $(tasks.taskname) is $(tasks.foo.status)."}, }}, }}, @@ -2800,7 +2800,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "bar-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.bar.status)"}, }}, WhenExpressions: WhenExpressions{WhenExpression{ @@ -2818,7 +2818,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "tasks-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.status)"}, }}, }}, @@ -2831,7 +2831,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "bar-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of bar is $(tasks.bar.status)"}, }}, }}, @@ -2844,7 +2844,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "bar-status", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.bar.status)"}}, }}, }}, @@ -2857,7 +2857,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { tasks: []PipelineTask{{ Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, - Params: []Param{{ + Params: Params{{ Name: "tasks-status", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.status)"}}, }}, }}, @@ -2870,7 +2870,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "notask-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.notask.status)"}, }}, }}, @@ -2898,7 +2898,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "notask-status", Value: ParamValue{Type: ParamTypeString, StringVal: "$(tasks.notask.status)"}, }}, }, { @@ -2919,7 +2919,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "notask-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of notask is $(tasks.notask.status)."}, }}, }}, @@ -2932,7 +2932,7 @@ func TestPipelineTasksExecutionStatus(t *testing.T) { finalTasks: []PipelineTask{{ Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, - Params: []Param{{ + Params: Params{{ Name: "notask-status", Value: ParamValue{Type: ParamTypeString, StringVal: "Execution status of $(tasks.taskname) is $(tasks.notask.status)."}, }}, }}, @@ -2975,7 +2975,7 @@ func TestMatrixIncompatibleAPIVersions(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }}, @@ -2992,7 +2992,7 @@ func TestMatrixIncompatibleAPIVersions(t *testing.T) { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }}, @@ -3044,10 +3044,10 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}, }}, @@ -3058,10 +3058,10 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, - Params: []Param{{ + Params: Params{{ Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}, }}, }}, @@ -3071,7 +3071,7 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foo", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, }, { Name: "bar", Value: ParamValue{Type: ParamTypeString, StringVal: "bar"}, @@ -3080,7 +3080,7 @@ func Test_validateMatrix(t *testing.T) { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "baz", Value: ParamValue{Type: ParamTypeString, StringVal: "baz"}, }}}, }}, @@ -3094,7 +3094,7 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar", "foo"}}, @@ -3106,9 +3106,9 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "test", - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeString, StringVal: "foo"}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeString, StringVal: "bar"}}, @@ -3121,9 +3121,9 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Include: []MatrixInclude{{ + Include: IncludeParamsList{{ Name: "test", - Params: []Param{{ + Params: Params{{ Name: "foobar", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo"}}, }, { Name: "barfoo", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"bar"}}}, @@ -3140,14 +3140,14 @@ func Test_validateMatrix(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.foo-task.results.a-result)"}}, }}}, }, { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.bar-task.results.b-result)"}}, }}}, }}, @@ -3185,13 +3185,13 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }, { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.a-task.results.a-result)"}}, }}, }}, @@ -3205,14 +3205,14 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }}, finally: PipelineTaskList{{ Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.a-task.results.a-result)"}}, }}, }}, @@ -3226,20 +3226,20 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }, { Name: "b-task", TaskRef: &TaskRef{Name: "b-task"}, - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.a-task.results.a-result)"}}, }}, }}, finally: PipelineTaskList{{ Name: "c-task", TaskRef: &TaskRef{Name: "c-task"}, - Params: []Param{{ + Params: Params{{ Name: "b-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"$(tasks.a-task.results.a-result)"}}, }}, }}, @@ -3253,7 +3253,7 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }, { @@ -3275,7 +3275,7 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }}, @@ -3298,7 +3298,7 @@ func Test_validateResultsFromMatrixedPipelineTasksNotConsumed(t *testing.T) { Name: "a-task", TaskRef: &TaskRef{Name: "a-task"}, Matrix: &Matrix{ - Params: []Param{{ + Params: Params{{ Name: "a-param", Value: ParamValue{Type: ParamTypeArray, ArrayVal: []string{"foo", "bar"}}, }}}, }, { @@ -3381,7 +3381,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, { name: "single parameter with when expression", original: PipelineSpec{ @@ -3397,7 +3397,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, { name: "pipeline parameter nested inside task parameter", original: PipelineSpec{ @@ -3449,7 +3449,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, { name: "parameter evaluation with both tasks and final tasks", original: PipelineSpec{ @@ -3475,7 +3475,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, { name: "parameter references with bracket notation and special characters", original: PipelineSpec{ @@ -3520,7 +3520,7 @@ func TestValidateParamArrayIndex_valid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, }, } { tt := tt // capture range variable @@ -3559,7 +3559,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[2])]"), }, { name: "single parameter reference with when expression out of bound", @@ -3576,7 +3576,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[2])]"), }, { name: "pipeline parameter reference nested inside task parameter out of bound", @@ -3651,7 +3651,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[2])]"), }, { name: "parameter evaluation with both tasks and final tasks reference out of bound", @@ -3683,7 +3683,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }}, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.first-param[3]) $(params.first-param[4]) $(params.second-param[2]) $(params.second-param[3]) $(params.second-param[4])]"), }, { name: "parameter in matrix reference out of bound", @@ -3701,7 +3701,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2])]"), }, { name: "parameter references with bracket notation and special characters reference out of bound", @@ -3748,7 +3748,7 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) { }, }}, }, - params: []Param{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, + params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}}, expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[3])]"), }, } { diff --git a/pkg/apis/pipeline/v1beta1/resultref_test.go b/pkg/apis/pipeline/v1beta1/resultref_test.go index cd00d4f9b4c..19ae15cbbc3 100644 --- a/pkg/apis/pipeline/v1beta1/resultref_test.go +++ b/pkg/apis/pipeline/v1beta1/resultref_test.go @@ -639,7 +639,7 @@ func TestPipelineTaskResultRefs(t *testing.T) { }, }}, Matrix: &v1beta1.Matrix{ - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: []v1beta1.Param{{ Name: "a-param", Value: *v1beta1.NewStructuredValues("$(tasks.pt9.results.r9)"), diff --git a/pkg/apis/pipeline/v1beta1/swagger.json b/pkg/apis/pipeline/v1beta1/swagger.json index ec56b898278..e8171739b5e 100644 --- a/pkg/apis/pipeline/v1beta1/swagger.json +++ b/pkg/apis/pipeline/v1beta1/swagger.json @@ -505,21 +505,16 @@ } } }, - "v1beta1.Matrix": { - "description": "Matrix is used to fan out Tasks in a Pipeline", + "v1beta1.IncludeParams": { + "description": "IncludeParams allows passing in a specific combinations of Parameters into the Matrix. Note this struct is in preview mode and not yet supported", "type": "object", "properties": { - "include": { - "description": "Include is a list of MatrixInclude which allows passing in specific combinations of Parameters into the Matrix. Note that Include is in preview mode and not yet supported.", - "type": "array", - "items": { - "default": {}, - "$ref": "#/definitions/v1beta1.MatrixInclude" - }, - "x-kubernetes-list-type": "atomic" + "name": { + "description": "Name the specified combination", + "type": "string" }, "params": { - "description": "Params is a list of parameters used to fan out the pipelineTask Params takes only `Parameters` of type `\"array\"` Each array element is supplied to the `PipelineTask` by substituting `params` of type `\"string\"` in the underlying `Task`. The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.", + "description": "Params takes only `Parameters` of type `\"string\"` The names of the `params` must match the names of the `params` in the underlying `Task`", "type": "array", "items": { "default": {}, @@ -529,16 +524,21 @@ } } }, - "v1beta1.MatrixInclude": { - "description": "MatrixInclude allows passing in a specific combinations of Parameters into the Matrix. Note this struct is in preview mode and not yet supported", + "v1beta1.Matrix": { + "description": "Matrix is used to fan out Tasks in a Pipeline", "type": "object", "properties": { - "name": { - "description": "Name the specified combination", - "type": "string" + "include": { + "description": "Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. Note that Include is in preview mode and not yet supported.", + "type": "array", + "items": { + "default": {}, + "$ref": "#/definitions/v1beta1.IncludeParams" + }, + "x-kubernetes-list-type": "atomic" }, "params": { - "description": "Params takes only `Parameters` of type `\"string\"` The names of the `params` must match the names of the `params` in the underlying `Task`", + "description": "Params is a list of parameters used to fan out the pipelineTask Params takes only `Parameters` of type `\"array\"` Each array element is supplied to the `PipelineTask` by substituting `params` of type `\"string\"` in the underlying `Task`. The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.", "type": "array", "items": { "default": {}, diff --git a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go index 8551c67495e..c3697a2a6d8 100644 --- a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go @@ -370,7 +370,7 @@ func (in *EmbeddedTask) DeepCopy() *EmbeddedTask { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Matrix) DeepCopyInto(out *Matrix) { +func (in *IncludeParams) DeepCopyInto(out *IncludeParams) { *out = *in if in.Params != nil { in, out := &in.Params, &out.Params @@ -379,28 +379,43 @@ func (in *Matrix) DeepCopyInto(out *Matrix) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.Include != nil { - in, out := &in.Include, &out.Include - *out = make([]MatrixInclude, len(*in)) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IncludeParams. +func (in *IncludeParams) DeepCopy() *IncludeParams { + if in == nil { + return nil + } + out := new(IncludeParams) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in IncludeParamsList) DeepCopyInto(out *IncludeParamsList) { + { + in := &in + *out = make(IncludeParamsList, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } + return } - return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Matrix. -func (in *Matrix) DeepCopy() *Matrix { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IncludeParamsList. +func (in IncludeParamsList) DeepCopy() IncludeParamsList { if in == nil { return nil } - out := new(Matrix) + out := new(IncludeParamsList) in.DeepCopyInto(out) - return out + return *out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MatrixInclude) DeepCopyInto(out *MatrixInclude) { +func (in *Matrix) DeepCopyInto(out *Matrix) { *out = *in if in.Params != nil { in, out := &in.Params, &out.Params @@ -409,15 +424,22 @@ func (in *MatrixInclude) DeepCopyInto(out *MatrixInclude) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Include != nil { + in, out := &in.Include, &out.Include + *out = make(IncludeParamsList, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MatrixInclude. -func (in *MatrixInclude) DeepCopy() *MatrixInclude { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Matrix. +func (in *Matrix) DeepCopy() *Matrix { if in == nil { return nil } - out := new(MatrixInclude) + out := new(Matrix) in.DeepCopyInto(out) return out } diff --git a/pkg/reconciler/pipelinerun/pipelinerun.go b/pkg/reconciler/pipelinerun/pipelinerun.go index 83f507b738b..0220ed95e5d 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun.go +++ b/pkg/reconciler/pipelinerun/pipelinerun.go @@ -756,7 +756,7 @@ func (c *Reconciler) runNextSchedulableTask(ctx context.Context, pr *v1beta1.Pip } switch { - case rpt.IsCustomTask() && rpt.IsMatrixed(): + case rpt.IsCustomTask() && rpt.PipelineTask.IsMatrixed(): rpt.RunObjects, err = c.createRunObjects(ctx, rpt, pr) if err != nil { recorder.Eventf(pr, corev1.EventTypeWarning, "RunsCreationFailed", "Failed to create Runs %q: %v", rpt.RunObjectNames, err) @@ -768,7 +768,7 @@ func (c *Reconciler) runNextSchedulableTask(ctx context.Context, pr *v1beta1.Pip recorder.Eventf(pr, corev1.EventTypeWarning, "RunCreationFailed", "Failed to create Run %q: %v", rpt.RunObjectName, err) return fmt.Errorf("error creating Run called %s for PipelineTask %s from PipelineRun %s: %w", rpt.RunObjectName, rpt.PipelineTask.Name, pr.Name, err) } - case rpt.IsMatrixed(): + case rpt.PipelineTask.IsMatrixed(): rpt.TaskRuns, err = c.createTaskRuns(ctx, rpt, pr) if err != nil { recorder.Eventf(pr, corev1.EventTypeWarning, "TaskRunsCreationFailed", "Failed to create TaskRuns %q: %v", rpt.TaskRunNames, err) @@ -799,7 +799,7 @@ func (c *Reconciler) createTaskRuns(ctx context.Context, rpt *resources.Resolved ctx, span := c.tracerProvider.Tracer(TracerName).Start(ctx, "createTaskRuns") defer span.End() var taskRuns []*v1beta1.TaskRun - matrixCombinations := rpt.PipelineTask.Matrix.FanOut().ToParams() + matrixCombinations := rpt.PipelineTask.Matrix.FanOut() for i, taskRunName := range rpt.TaskRunNames { params := matrixCombinations[i] taskRun, err := c.createTaskRun(ctx, taskRunName, params, rpt, pr) @@ -873,7 +873,7 @@ func (c *Reconciler) createRunObjects(ctx context.Context, rpt *resources.Resolv var runObjects []v1beta1.RunObject ctx, span := c.tracerProvider.Tracer(TracerName).Start(ctx, "createRunObjects") defer span.End() - matrixCombinations := rpt.PipelineTask.Matrix.FanOut().ToParams() + matrixCombinations := rpt.PipelineTask.Matrix.FanOut() for i, runObjectName := range rpt.RunObjectNames { params := matrixCombinations[i] runObject, err := c.createRunObject(ctx, runObjectName, params, rpt, pr) diff --git a/pkg/reconciler/pipelinerun/resources/apply_test.go b/pkg/reconciler/pipelinerun/resources/apply_test.go index 8aa34e2979f..72ac05c1902 100644 --- a/pkg/reconciler/pipelinerun/resources/apply_test.go +++ b/pkg/reconciler/pipelinerun/resources/apply_test.go @@ -2107,7 +2107,7 @@ func TestApplyReplacementsMatrix(t *testing.T) { }}, Tasks: []v1beta1.PipelineTask{{ Matrix: &v1beta1.Matrix{ - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: v1beta1.Params{{ // string replacements from string param @@ -2142,7 +2142,7 @@ func TestApplyReplacementsMatrix(t *testing.T) { }}, Tasks: []v1beta1.PipelineTask{{ Matrix: &v1beta1.Matrix{ - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: []v1beta1.Param{{ // string replacements from string param @@ -2221,7 +2221,7 @@ func TestApplyReplacementsMatrix(t *testing.T) { }}, Finally: []v1beta1.PipelineTask{{ Matrix: &v1beta1.Matrix{ - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: v1beta1.Params{{ // string replacements from string param @@ -2256,7 +2256,7 @@ func TestApplyReplacementsMatrix(t *testing.T) { }}, Finally: []v1beta1.PipelineTask{{ Matrix: &v1beta1.Matrix{ - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: []v1beta1.Param{{ // string replacements from string param @@ -2988,7 +2988,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, Matrix: &v1beta1.Matrix{ - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: v1beta1.Params{{ // string replacements from string results, array results and object results @@ -3003,7 +3003,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { Name: "bTask", TaskRef: &v1beta1.TaskRef{Name: "bTask"}, Matrix: &v1beta1.Matrix{ - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: []v1beta1.Param{{ // string replacements from string results, array results and object results @@ -3261,7 +3261,7 @@ func TestApplyPipelineTaskContexts(t *testing.T) { Name: "retries", Value: *v1beta1.NewStructuredValues("$(context.pipelineTask.retries)"), }}, - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: []v1beta1.Param{{ Name: "retries", @@ -3281,7 +3281,7 @@ func TestApplyPipelineTaskContexts(t *testing.T) { Name: "retries", Value: *v1beta1.NewStructuredValues("5"), }}, - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: []v1beta1.Param{{ Name: "retries", @@ -3302,7 +3302,7 @@ func TestApplyPipelineTaskContexts(t *testing.T) { Name: "retries", Value: *v1beta1.NewStructuredValues("$(context.pipelineTask.retries)"), }}, - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: []v1beta1.Param{{ Name: "retries", @@ -3321,7 +3321,7 @@ func TestApplyPipelineTaskContexts(t *testing.T) { Name: "retries", Value: *v1beta1.NewStructuredValues("0"), }}, - Include: []v1beta1.MatrixInclude{{ + Include: []v1beta1.IncludeParams{{ Name: "build-1", Params: []v1beta1.Param{{ Name: "retries", diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go index bd643428b63..7524c980600 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go @@ -79,7 +79,7 @@ func (t ResolvedPipelineTask) isDone(facts *PipelineRunFacts) bool { // IsRunning returns true only if the task is neither succeeded, cancelled nor failed func (t ResolvedPipelineTask) IsRunning() bool { switch { - case t.IsCustomTask() && t.IsMatrixed(): + case t.IsCustomTask() && t.PipelineTask.IsMatrixed(): if len(t.RunObjects) == 0 { return false } @@ -87,7 +87,7 @@ func (t ResolvedPipelineTask) IsRunning() bool { if t.RunObject == nil { return false } - case t.IsMatrixed(): + case t.PipelineTask.IsMatrixed(): if len(t.TaskRuns) == 0 { return false } @@ -104,16 +104,11 @@ func (t ResolvedPipelineTask) IsCustomTask() bool { return t.CustomTask } -// IsMatrixed return true if the PipelineTask has a Matrix. -func (t ResolvedPipelineTask) IsMatrixed() bool { - return t.PipelineTask.Matrix != nil && len(t.PipelineTask.Matrix.Params) > 0 -} - // isSuccessful returns true only if the run has completed successfully // If the PipelineTask has a Matrix, isSuccessful returns true if all runs have completed successfully func (t ResolvedPipelineTask) isSuccessful() bool { switch { - case t.IsCustomTask() && t.IsMatrixed(): + case t.IsCustomTask() && t.PipelineTask.IsMatrixed(): if len(t.RunObjects) == 0 { return false } @@ -125,7 +120,7 @@ func (t ResolvedPipelineTask) isSuccessful() bool { return true case t.IsCustomTask(): return t.RunObject != nil && t.RunObject.IsSuccessful() - case t.IsMatrixed(): + case t.PipelineTask.IsMatrixed(): if len(t.TaskRuns) == 0 { return false } @@ -156,7 +151,7 @@ func (t ResolvedPipelineTask) isFailure() bool { var c *apis.Condition var isDone bool switch { - case t.IsCustomTask() && t.IsMatrixed(): + case t.IsCustomTask() && t.PipelineTask.IsMatrixed(): if len(t.RunObjects) == 0 { return false } @@ -175,7 +170,7 @@ func (t ResolvedPipelineTask) isFailure() bool { c = t.RunObject.GetStatusCondition().GetCondition(apis.ConditionSucceeded) isDone = t.RunObject.IsDone() return isDone && c.IsFalse() && !t.isRunRetriable() - case t.IsMatrixed(): + case t.PipelineTask.IsMatrixed(): if len(t.TaskRuns) == 0 { return false } @@ -203,7 +198,7 @@ func (t ResolvedPipelineTask) isFailure() bool { // This should be removed once v1alpha1.Run is fully deprecated. func (t ResolvedPipelineTask) isRunRetriable() bool { switch { - case t.IsMatrixed(): + case t.PipelineTask.IsMatrixed(): if len(t.RunObjects) == 0 { return true } @@ -228,7 +223,7 @@ func (t ResolvedPipelineTask) isRunRetriable() bool { // If the PipelineTask has a Matrix, isCancelled returns true if any run is cancelled due to PipelineRun-controlled timeout and all other runs are done. func (t ResolvedPipelineTask) isCancelledForTimeOut() bool { switch { - case t.IsCustomTask() && t.IsMatrixed(): + case t.IsCustomTask() && t.PipelineTask.IsMatrixed(): if len(t.RunObjects) == 0 { return false } @@ -251,7 +246,7 @@ func (t ResolvedPipelineTask) isCancelledForTimeOut() bool { return c != nil && c.IsFalse() && c.Reason == v1beta1.CustomRunReasonCancelled.String() && isRunOrCustomRunCancelledByPipelineRunTimeout(t.RunObject) - case t.IsMatrixed(): + case t.PipelineTask.IsMatrixed(): if len(t.TaskRuns) == 0 { return false } @@ -281,7 +276,7 @@ func (t ResolvedPipelineTask) isCancelledForTimeOut() bool { // If the PipelineTask has a Matrix, isCancelled returns true if any run is cancelled and all other runs are done. func (t ResolvedPipelineTask) isCancelled() bool { switch { - case t.IsCustomTask() && t.IsMatrixed(): + case t.IsCustomTask() && t.PipelineTask.IsMatrixed(): if len(t.RunObjects) == 0 { return false } @@ -300,7 +295,7 @@ func (t ResolvedPipelineTask) isCancelled() bool { } c := t.RunObject.GetStatusCondition().GetCondition(apis.ConditionSucceeded) return c != nil && c.IsFalse() && c.Reason == v1beta1.CustomRunReasonCancelled.String() - case t.IsMatrixed(): + case t.PipelineTask.IsMatrixed(): if len(t.TaskRuns) == 0 { return false } @@ -605,7 +600,7 @@ func ResolvePipelineTask( } rpt.CustomTask = isCustomTask(ctx, rpt) switch { - case rpt.IsCustomTask() && rpt.IsMatrixed(): + case rpt.IsCustomTask() && rpt.PipelineTask.IsMatrixed(): rpt.RunObjectNames = getNamesOfRuns(pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name, pipelineTask.Matrix.CountCombinations()) for _, runName := range rpt.RunObjectNames { run, err := getRun(runName) @@ -625,7 +620,7 @@ func ResolvePipelineTask( if run != nil { rpt.RunObject = run } - case rpt.IsMatrixed(): + case rpt.PipelineTask.IsMatrixed(): rpt.TaskRunNames = GetNamesOfTaskRuns(pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name, pipelineTask.Matrix.CountCombinations()) for _, taskRunName := range rpt.TaskRunNames { if err := rpt.resolvePipelineRunTaskWithTaskRun(ctx, taskRunName, getTask, getTaskRun, pipelineTask); err != nil { @@ -655,7 +650,7 @@ func (t *ResolvedPipelineTask) resolvePipelineRunTaskWithTaskRun( } } if taskRun != nil { - if t.IsMatrixed() { + if t.PipelineTask.IsMatrixed() { t.TaskRuns = append(t.TaskRuns, taskRun) } else { t.TaskRun = taskRun diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go index 311fdd4c5c4..e69a9e5d44d 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go @@ -3068,7 +3068,7 @@ func TestIsMatrixed(t *testing.T) { if err != nil { t.Fatalf("Did not expect error when resolving PipelineRun: %v", err) } - got := rpt.IsMatrixed() + got := rpt.PipelineTask.IsMatrixed() if d := cmp.Diff(tc.want, got); d != "" { t.Errorf("IsMatrixed: %s", diff.PrintWantGot(d)) } diff --git a/pkg/reconciler/taskrun/validate_taskrun.go b/pkg/reconciler/taskrun/validate_taskrun.go index a44418ca41a..bbfdda29d7e 100644 --- a/pkg/reconciler/taskrun/validate_taskrun.go +++ b/pkg/reconciler/taskrun/validate_taskrun.go @@ -30,53 +30,38 @@ import ( "k8s.io/apimachinery/pkg/util/sets" ) -func validateParams(ctx context.Context, paramSpecs []v1beta1.ParamSpec, params []v1beta1.Param, matrix *v1beta1.Matrix) error { +func validateParams(ctx context.Context, paramSpecs []v1beta1.ParamSpec, params v1beta1.Params, matrix *v1beta1.Matrix) error { neededParamsNames, neededParamsTypes := neededParamsNamesAndTypes(paramSpecs) - var matrixParams []v1beta1.Param - if matrix != nil { - matrixParams = matrix.Params - } - providedParamsNames := providedParamsNames(append(params, matrixParams...)) + providedParams := params + matrixAllParams := matrix.GetAllParams() + providedParams = append(providedParams, matrixAllParams...) + providedParamsNames := providedParams.ExtractNames() if missingParamsNames := missingParamsNames(neededParamsNames, providedParamsNames, paramSpecs); len(missingParamsNames) != 0 { return fmt.Errorf("missing values for these params which have no default values: %s", missingParamsNames) } - if wrongTypeParamNames := wrongTypeParamsNames(params, matrixParams, neededParamsTypes); len(wrongTypeParamNames) != 0 { + if wrongTypeParamNames := wrongTypeParamsNames(params, matrixAllParams, neededParamsTypes); len(wrongTypeParamNames) != 0 { return fmt.Errorf("param types don't match the user-specified type: %s", wrongTypeParamNames) } if missingKeysObjectParamNames := MissingKeysObjectParamNames(paramSpecs, params); len(missingKeysObjectParamNames) != 0 { return fmt.Errorf("missing keys for these params which are required in ParamSpec's properties %v", missingKeysObjectParamNames) } - return nil } - -func neededParamsNamesAndTypes(paramSpecs []v1beta1.ParamSpec) ([]string, map[string]v1beta1.ParamType) { - var neededParamsNames []string +func neededParamsNamesAndTypes(paramSpecs []v1beta1.ParamSpec) (sets.String, map[string]v1beta1.ParamType) { + neededParamsNames := sets.String{} neededParamsTypes := make(map[string]v1beta1.ParamType) - neededParamsNames = make([]string, 0, len(paramSpecs)) for _, inputResourceParam := range paramSpecs { - neededParamsNames = append(neededParamsNames, inputResourceParam.Name) + neededParamsNames.Insert(inputResourceParam.Name) neededParamsTypes[inputResourceParam.Name] = inputResourceParam.Type } return neededParamsNames, neededParamsTypes } - -func providedParamsNames(params []v1beta1.Param) []string { - providedParamsNames := make([]string, 0, len(params)) - for _, param := range params { - providedParamsNames = append(providedParamsNames, param.Name) - } - return providedParamsNames -} - -func missingParamsNames(neededParams []string, providedParams []string, paramSpecs []v1beta1.ParamSpec) []string { - missingParamsNames := list.DiffLeft(neededParams, providedParams) +func missingParamsNames(neededParams sets.String, providedParams sets.String, paramSpecs []v1beta1.ParamSpec) []string { + missingParamsNames := neededParams.Difference(providedParams) var missingParamsNamesWithNoDefaults []string - for _, param := range missingParamsNames { - for _, inputResourceParam := range paramSpecs { - if inputResourceParam.Name == param && inputResourceParam.Default == nil { - missingParamsNamesWithNoDefaults = append(missingParamsNamesWithNoDefaults, param) - } + for _, inputResourceParam := range paramSpecs { + if missingParamsNames.Has(inputResourceParam.Name) && inputResourceParam.Default == nil { + missingParamsNamesWithNoDefaults = append(missingParamsNamesWithNoDefaults, inputResourceParam.Name) } } return missingParamsNamesWithNoDefaults diff --git a/pkg/reconciler/taskrun/validate_taskrun_test.go b/pkg/reconciler/taskrun/validate_taskrun_test.go index 79d0943e434..69ee004cf8c 100644 --- a/pkg/reconciler/taskrun/validate_taskrun_test.go +++ b/pkg/reconciler/taskrun/validate_taskrun_test.go @@ -44,9 +44,8 @@ func TestValidateResolvedTask_ValidParams(t *testing.T) { { Name: "bar", Type: v1beta1.ParamTypeString, - }, - { - Name: "zoo", + }, { + Name: "include", Type: v1beta1.ParamTypeString, }, { Name: "arrayResultRef", @@ -81,7 +80,7 @@ func TestValidateResolvedTask_ValidParams(t *testing.T) { rtr := &resources.ResolvedTask{ TaskSpec: &task.Spec, } - p := []v1beta1.Param{{ + p := v1beta1.Params{{ Name: "foo", Value: *v1beta1.NewStructuredValues("somethinggood"), }, { @@ -104,14 +103,17 @@ func TestValidateResolvedTask_ValidParams(t *testing.T) { "key3": "val3", }), }} - m := []v1beta1.Param{{ - Name: "zoo", - Value: *v1beta1.NewStructuredValues("a", "b", "c"), - }} - if err := ValidateResolvedTask(ctx, p, &v1beta1.Matrix{Params: m}, rtr); err != nil { + m := &v1beta1.Matrix{ + Include: []v1beta1.IncludeParams{{ + Name: "build-1", + Params: v1beta1.Params{{ + Name: "include", Value: v1beta1.ParamValue{Type: v1beta1.ParamTypeString, StringVal: "string-1"}, + }}, + }}, + } + if err := ValidateResolvedTask(ctx, p, m, rtr); err != nil { t.Fatalf("Did not expect to see error when validating TaskRun with correct params but saw %v", err) } - t.Run("alpha-extra-params", func(t *testing.T) { ctx := config.ToContext(ctx, &config.Config{FeatureFlags: &config.FeatureFlags{EnableAPIFields: "alpha"}}) extra := v1beta1.Param{ @@ -122,8 +124,11 @@ func TestValidateResolvedTask_ValidParams(t *testing.T) { Name: "extraarray", Value: *v1beta1.NewStructuredValues("i", "am", "an", "extra", "array", "param"), } - if err := ValidateResolvedTask(ctx, append(p, extra), &v1beta1.Matrix{Params: append(m, extraarray)}, rtr); err != nil { - t.Fatalf("Did not expect to see error when validating TaskRun with correct params but saw %v", err) + for _, include := range m.Include { + include.Params = append(include.Params, extraarray) + } + if err := ValidateResolvedTask(ctx, append(p, extra), m, rtr); err != nil { + t.Fatalf("Did not expect to see error when validating TaskRun with extra params but saw %v", err) } }) } @@ -182,12 +187,12 @@ func TestValidateResolvedTask_InvalidParams(t *testing.T) { rtr: &resources.ResolvedTask{ TaskSpec: &task.Spec, }, - params: []v1beta1.Param{{ + params: v1beta1.Params{{ Name: "foobar", Value: *v1beta1.NewStructuredValues("somethingfun"), }}, matrix: &v1beta1.Matrix{ - Params: []v1beta1.Param{{ + Params: v1beta1.Params{{ Name: "barfoo", Value: *v1beta1.NewStructuredValues("bar", "foo"), }}, @@ -197,26 +202,50 @@ func TestValidateResolvedTask_InvalidParams(t *testing.T) { rtr: &resources.ResolvedTask{ TaskSpec: &task.Spec, }, - params: []v1beta1.Param{{ + params: v1beta1.Params{{ Name: "foo", Value: *v1beta1.NewStructuredValues("bar", "foo"), }}, + }, { + name: "invalid-string-in-matrix-params", + rtr: &resources.ResolvedTask{ + TaskSpec: &task.Spec, + }, + matrix: &v1beta1.Matrix{ + Params: v1beta1.Params{{ + Name: "foo", + Value: *v1beta1.NewStructuredValues("bar"), + }}}, }, { name: "invalid-type-in-matrix", rtr: &resources.ResolvedTask{ TaskSpec: &task.Spec, }, matrix: &v1beta1.Matrix{ - Params: []v1beta1.Param{{ - Name: "bar", + Params: v1beta1.Params{{ + Name: "foo", Value: *v1beta1.NewStructuredValues("bar", "foo"), }}}, + }, { + name: "invalid-arr-in-matrix-include", + rtr: &resources.ResolvedTask{ + TaskSpec: &task.Spec, + }, + matrix: &v1beta1.Matrix{ + Include: []v1beta1.IncludeParams{{ + Name: "build-1", + Params: v1beta1.Params{{ + Name: "bar", + Value: *v1beta1.NewStructuredValues("bar", "foo"), + }}, + }}, + }, }, { name: "missing object param keys", rtr: &resources.ResolvedTask{ TaskSpec: &task.Spec, }, - params: []v1beta1.Param{{ + params: v1beta1.Params{{ Name: "foo", Value: *v1beta1.NewStructuredValues("test"), }, {
-name
+params
-string + +Params +
-

Name the specified combination

+

Params is a list of parameters used to fan out the pipelineTask +Params takes only Parameters of type "array" +Each array element is supplied to the PipelineTask by substituting params of type "string" in the underlying Task. +The names of the params in the Matrix must match the names of the params in the underlying Task that they will be substituting.

-params
+include
- -Params + +IncludeParamsList
-

Params takes only Parameters of type "string" -The names of the params must match the names of the params in the underlying Task

+(Optional) +

Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix. +Note that Include is in preview mode and not yet supported.