Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

validate matrix for duplicate params #6308

Merged

Conversation

pritidesai
Copy link
Member

Changes

In case of task/pipeline params, the validation we have in place catches duplicate params i.e. parameters defined multiple times with the same name results in a validation error. The same validation was missing from matrix.params and matrix.Include.params. This PR is implementing such validation. matrix.params and matrix.include.params. also specifies a list of array parameters where a user could define the same parameter twice by mistake.

/kind bug

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings)
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

Validate matrix.params and matrix.include.params such that specifying duplicate parameters is caught by the validation.

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 7, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.1% 99.1% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.1% 99.1% 0.0

Copy link
Member

@jerop jerop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @pritidesai!

pkg/apis/pipeline/v1/pipeline_validation_test.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1/matrix_types.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1/param_types.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1/pipeline_types_test.go Outdated Show resolved Hide resolved
Copy link
Member

@jerop jerop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pritidesai pritidesai force-pushed the validate-matrix-for-duplicate-params branch from 7a05011 to 9001a58 Compare March 8, 2023 03:08
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.0% 99.1% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.0% 99.1% 0.0

@pritidesai pritidesai force-pushed the validate-matrix-for-duplicate-params branch from 9001a58 to eed059d Compare March 8, 2023 17:05
In case of task/pipeline params, the validation we have in place catches
duplicate params i.e. parameters defined multiple times with the same name
results in a validation error.
The same validation was missing from matrix.params and matrix.Include.
matrix.params also takes a list of array parameters where a user could
define the same parameter twice by mistake.

Signed-off-by: pritidesai <pdesai@us.ibm.com>
@pritidesai pritidesai force-pushed the validate-matrix-for-duplicate-params branch from eed059d to 56f0ed8 Compare March 8, 2023 17:05
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.0% 99.1% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.0% 99.1% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.0% 99.1% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.0% 99.1% 0.0

@pritidesai
Copy link
Member Author

pritidesai commented Mar 8, 2023

thank you @jerop for the review, overall I have rephrased the validation error from:

params names must be unique, the same param: duplicate-param is defined multiple times at: tasks[0].params[1].name, tasks[0].params[2].name

to:

parameter names must be unique, the parameter "duplicate-param" is also defined at: tasks[0].params[1].name, tasks[0].params[2].name

@@ -275,7 +275,7 @@ func (pt *PipelineTask) validateMatrix(ctx context.Context) (errs *apis.FieldErr
errs = errs.Also(pt.Matrix.validateCombinationsCount(ctx))
}
errs = errs.Also(pt.Matrix.validateParameterInOneOfMatrixOrParams(pt.Params))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering about the overlap between this validation for uniqueness and the one in validateParameterInOneOfMatrixOrParams -- maybe this check should be for all params in a pipelinetask (whether it's in params or matrix.params or matrix.include.params) -- wdyt @pritidesai?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

summary: can we remove validateParameterInOneOfMatrixOrParams?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest not removing validateParameterInOneOfMatrixOrParams.

validateParameterInOneOfMatrixOrParams checks the params against the pipelineTask.params and validates that a pipelineTask.matrix.Params.foobar is not defined in pipelineTask.params. This validation serves its purpose of comparing params in two separate sections which is still necessary. It is necessary because the error being reported is very clear that a param can either exist in a pipelineTask.params or pipelineTask.matrix.params. What it does not catch is duplicates within pipelineTask.matrix.Params since a set is created based on pipelineTask.matrix.Params. The set will automatically make sure to have just a single occurrence of any parameter.

The duplicate check validateDuplicateParameters each per section, helps identify where exactly the duplicates are and validateParameterInOneOfMatrixOrParams compares two sections with a clear error message.

So, to summarize, I would keep these checks as is. Let me know if you think different. I am happy to apply more simplification.

Now, what it reminds me of, we do not have a test for checking if pipelineTask.matrix.include.params does not exist in pipelineTask.params.

so instead of only iterating over m.params, collect params defined in matrix.include.params:

func (m *Matrix) validateParameterInOneOfMatrixOrParams(params []Param) (errs *apis.FieldError) {
	matrixParameterNames := sets.NewString()
	if m != nil {
		for _, param := range m.Params {
			matrixParameterNames.Insert(param.Name)
		}
		for _, param := range m.Include.Params {
			matrixParameterNames.Insert(param.Name)
		}
	}
	for _, param := range params {
		if matrixParameterNames.Has(param.Name) {
			errs = errs.Also(apis.ErrMultipleOneOf("matrix["+param.Name+"]", "params["+param.Name+"]"))
		}
	}
	return errs
}

thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to keep pt.validateParameterInOneOfMatrixOrParams and m.validateDuplicateParameters separate

and agreed with checking for duplicates between pt.params and m.include.params -- the code sample you have looks great to me

cc @EmmaMunley

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Priti! Opened a PR for this here to include in next milestone release: #6349

Copy link
Member

@jerop jerop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @pritidesai!

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jerop

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 9, 2023
Copy link
Member

@lbernick lbernick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 9, 2023
@pritidesai
Copy link
Member Author

/retest

1 similar comment
@jerop
Copy link
Member

jerop commented Mar 10, 2023

/retest

@jerop jerop closed this Mar 10, 2023
@jerop jerop reopened this Mar 10, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.0% 99.1% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 99.1% 99.1% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 99.0% 99.1% 0.0

@tekton-robot tekton-robot merged commit 47e2f16 into tektoncd:main Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants