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

Update PipelineSpec Task validation to prevents errors at runtime #1358

Merged
merged 1 commit into from
Oct 8, 2019

Conversation

vtereso
Copy link

@vtereso vtereso commented Sep 26, 2019

Changes

Currently, if step names are omitted, a duplicate empty value collides in the Pipeline validation. Also, if a Task name uses forbidden characters, pods will fail to be created since it is appended to the name. If the name is omitted (in a single step, which would pass validation) we would get <PipelineRunName>--<Rand>-<ConditionalRefName>-<Rand> for a condition pod and <PipelineRunName>--<Rand> otherwise, where the double hyphen imply the name should be specified. Further, in the catalog and elsewhere it seems to be a well documented practice to include the name.

This PR adds validation to PipelineSpec Task name and TaskRef name validation to ensure that the name are valid Kubernetes names (revokes empty values).

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

Names of Task instances within Pipelines are now validated: they must not be empty, and they must only contain valid characters (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names).

@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Sep 26, 2019
@tekton-robot tekton-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Sep 26, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 96.8% -1.0

@tekton-robot tekton-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 26, 2019
@vtereso
Copy link
Author

vtereso commented Sep 26, 2019

Not sure where within https://github.com/tektoncd/pipeline/blob/master/docs/pipelines.md to update or if it is necessary?

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.8% 0.0

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.8% 0.0

Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

Not sure where within https://github.com/tektoncd/pipeline/blob/master/docs/pipelines.md to update or if it is necessary?

Sounds worth mentioning to me, maybe at:
https://github.com/tektoncd/pipeline/blob/master/docs/pipelines.md#pipeline-tasks ?

Adding hold for the docs but otherwise looks good!

/hold

/lgtm
/approve

(I'm also gonna edit your release notes to include this change!)

@@ -23,6 +23,7 @@ import (
"github.com/tektoncd/pipeline/pkg/list"
"golang.org/x/xerrors"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/validation"
Copy link
Collaborator

Choose a reason for hiding this comment

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

ooo what a handy library!

@tekton-robot tekton-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 27, 2019
@bobcatfish
Copy link
Collaborator

@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 27, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.9% 0.1

@vtereso
Copy link
Author

vtereso commented Sep 27, 2019

Just realized that the TaskRef names weren't being checked either so I just added this as well.

@vtereso vtereso changed the title Update PipelineSpec Task name validation to prevents errors at runtime Update PipelineSpec Task validation to prevents errors at runtime Sep 27, 2019
@bobcatfish
Copy link
Collaborator

Thanks @vtereso !!

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 27, 2019
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

Nice work, thank you!
I have a minor comment on the errors, let me know what you think about it.

pkg/apis/pipeline/v1alpha1/pipeline_validation.go Outdated Show resolved Hide resolved
}
// TaskRef name must be a valid k8s name
if errSlice := validation.IsQualifiedName(t.TaskRef.Name); len(errSlice) != 0 {
return apis.ErrInvalidValue(errSlice[0], "spec.tasks.taskRef")
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

I kinda agree with @afrittoli but I think we can do that in a follow-up. Sounds good @afrittoli @vtereso ?

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 4, 2019
@vtereso
Copy link
Author

vtereso commented Oct 4, 2019

It was an easy change so I returned all the errors

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.9% 0.1

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.9% 0.1

Copy link
Member

@afrittoli afrittoli 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 Oct 4, 2019
@afrittoli
Copy link
Member

/test pull-tekton-pipeline-integration-tests

@afrittoli
Copy link
Member

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 4, 2019
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 4, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.9% 0.1

Copy link
Member

@vdemeester vdemeester 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 Oct 7, 2019
@vdemeester
Copy link
Member

/lgtm cancel
@bobcatfish @vtereso needs cla/google to be fixed for this to be mergeable 😓

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 7, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/pipeline_validation.go 97.8% 97.9% 0.1

@vtereso
Copy link
Author

vtereso commented Oct 7, 2019

The cla is 🆗

Copy link
Member

@vdemeester vdemeester 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 Oct 8, 2019
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bobcatfish, vdemeester

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:
  • OWNERS [bobcatfish,vdemeester]

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 merged commit c722343 into tektoncd:master Oct 8, 2019
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. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants