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

Enhance v1beta1 validation code for pipeline 🍸 #3277

Merged

Conversation

vdemeester
Copy link
Member

@vdemeester vdemeester commented Sep 22, 2020

Changes

This make a better use of knative.dev/pkg apis errors package in order
to make the code simpler, and the report better.

  • This allows reporting multiple validation error at once — so, one
    failure message (webhook error) would be more useful to the user.
  • This reduce if err != nil path, simplifying the code.

This commit tackles Pipeline 🙃

Signed-off-by: Vincent Demeester [email protected]

/cc @pritidesai @jerop @bobcatfish @sbwsg @savitaashture @imjasonh

  • Fix last pieces of tests (few in pipeline_validation_test.go, few elsewhere)
  • Fix flaky dag cyclic test
  • comment and discuss on some errors report

/kind cleanup
/hold

Submitter Checklist

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

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

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

Pipeline validation now reports all the error at once, and is a bit more detailed.

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 22, 2020
@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/v1beta1/param_types.go 87.5% 96.9% 9.4
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 100.0% 2.6

@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/v1beta1/param_types.go 87.5% 96.9% 9.4
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 100.0% 2.6


return nil
errs = errs.Also(validatePipelineResults(ps.Results))
errs = errs.Also(validateTasksAndFinallySection(ps))
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit duplicated (in some weird way) with the task validation above. The whole task and finally validation code could be enhanced in follow-ups

Comment on lines -265 to -269
// Task names are appended to the container name, which must exist and
// must be a valid k8s name
if errSlice := validation.IsQualifiedName(t.Name); len(errSlice) != 0 {
return apis.ErrInvalidValue(strings.Join(errSlice, ","), fmt.Sprintf(prefix+"[%d].name", i))
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is less strict than validatePipelineTaskName so we don't really need to do it, at all

@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/v1beta1/param_types.go 87.5% 96.9% 9.4
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 100.0% 2.6

This make a better use of knative.dev/pkg apis errors package in order
to make the code simpler, *and* the report better.

- This allows reporting multiple validation error at once — so, one
  failure message (webhook error) would be more useful to the user.
- This reduce `if err != nil` path, simplifying the code.

This commit tackles `Pipeline` 🙃

Signed-off-by: Vincent Demeester <[email protected]>
@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/v1beta1/param_types.go 87.5% 96.9% 9.4
pkg/apis/pipeline/v1beta1/pipeline_validation.go 97.4% 100.0% 2.6

Comment on lines +397 to +411
func TestPipelineSpec_Validate_Failure_CycleDAG(t *testing.T) {
name := "invalid pipeline spec with DAG having cyclic dependency"
ps := &PipelineSpec{
Tasks: []PipelineTask{{
Name: "foo", TaskRef: &TaskRef{Name: "foo-task"}, RunAfter: []string{"bar"},
}, {
Name: "bar", TaskRef: &TaskRef{Name: "bar-task"}, RunAfter: []string{"foo"},
}},
}
err := ps.Validate(context.Background())
if err == nil {
t.Errorf("PipelineSpec.Validate() did not return error for invalid pipelineSpec: %s", name)
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Extracted this to not have a flaky unit test. We do validate it errors out but not checking the error as the order is not deterministic (can be foo -> bar -> foo or bar -> foo -> bar, both make senses).

@vdemeester
Copy link
Member Author

/hold cancel
This should be ready. The tests have quite some changes because we weren't checking the error "content", and now we do (so lot's of "addition" there)

@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 Sep 23, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

The only comment I have is a minor style thing: the line lengths are quite long in several areas. This is not a blocker but breaking them up a bit would aid readability a bit I think.

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbwsg

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 Sep 23, 2020
@vdemeester
Copy link
Member Author

The only comment I have is a minor style thing: the line lengths are quite long in several areas. This is not a blocker but breaking them up a bit would aid readability a bit I think.

Yeah indeed. I'll try to make an issue on tech dept in there (and other _validation*.go files). Few "good first issue" could come out of this 😝

Copy link
Contributor

@savitaashture savitaashture 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

@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.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 23, 2020
@tekton-robot tekton-robot merged commit 49d4b5a into tektoncd:master Sep 23, 2020
@vdemeester vdemeester deleted the enhance-pipeline-validation branch September 23, 2020 13:46
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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants