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

Add taskSpec resources validation #4547

Merged

Conversation

Yongxuanzhang
Copy link
Member

@Yongxuanzhang Yongxuanzhang commented Feb 4, 2022

Changes

This PR introduces the taskSpec resources validation, and mark the taskrun failed reason to ReasonFailedValidation. Before this commit the reason will be recognized as CouldntGetTask.

FIxes: #4512

/kind bug

Submitter Checklist

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

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in or deleted (only if no user facing changes)

Release Notes

NONE

@tekton-robot tekton-robot added release-note-none Denotes a PR that doesnt merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Feb 4, 2022
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 4, 2022
@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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.4% 0.7

@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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.4% 0.6

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Feb 4, 2022
pkg/reconciler/taskrun/validate_resources_test.go Outdated Show resolved Hide resolved
@@ -142,3 +142,18 @@ func ValidateResolvedTaskResources(ctx context.Context, params []v1beta1.Param,

return nil
}

func ValidateTaskSpecRequestResources(ctx context.Context, taskSpec *v1beta1.TaskSpec) error {
Copy link
Member

Choose a reason for hiding this comment

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

Is this method only exported so that it can be tested from package taskrun_test?

If so, this is generally not a best practice. It both means the method will be unnecessarily exported to external users, who may depend on its behavior not changing. The reason the test is in package taskrun_test is to be able to test only exported behaviors, so perhaps we should change it to package taskrun and test unexported methods/behaviors.

Copy link
Member Author

@Yongxuanzhang Yongxuanzhang Feb 4, 2022

Choose a reason for hiding this comment

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

It is exported to be used in taskrun.go -> prepare(), similar like ValidateResolvedTaskResources. I forgot to add comment before.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I see, I will make it unexported

pkg/reconciler/taskrun/validate_resources_test.go Outdated Show resolved Hide resolved
@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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.4% 0.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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.4% 0.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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.4% 0.7

@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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.8% 1.1

@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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.8% 1.1

@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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.7% 0.9

@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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.7% 0.9

@Yongxuanzhang Yongxuanzhang force-pushed the validate-taskspec-resources branch from f90119b to b271af6 Compare February 4, 2022 20:13
@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/reconciler/taskrun/taskrun.go 80.1% 79.5% -0.7
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.7% 0.9

@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/reconciler/taskrun/taskrun.go 80.1% 80.4% 0.2
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.7% 0.9

@Yongxuanzhang
Copy link
Member Author

/test pull-tekton-pipeline-alpha-integration-tests

@Yongxuanzhang Yongxuanzhang marked this pull request as ready for review February 5, 2022 00:02
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 5, 2022
@Yongxuanzhang Yongxuanzhang force-pushed the validate-taskspec-resources branch from 76f607f to a3c66dd Compare February 7, 2022 16:46
@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/reconciler/taskrun/taskrun.go 80.1% 80.4% 0.2
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.7% 0.9

@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/reconciler/taskrun/taskrun.go 80.1% 80.4% 0.2
pkg/reconciler/taskrun/validate_resources.go 93.8% 94.7% 0.9

@Yongxuanzhang
Copy link
Member Author

/test pull-tekton-pipeline-integration-tests
/test pull-tekton-pipeline-alpha-integration-tests

@Yongxuanzhang
Copy link
Member Author

/cc @wlynch

@tekton-robot tekton-robot requested a review from wlynch February 8, 2022 18:33
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: imjasonh

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 Feb 8, 2022
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.

How will this act with LimitRange ? aka is the validation done pre or post applying limit range ? (I think it's pre). This means it only validates the users request – aka if there is LimitRange, then it would pass the validation but could fail later (LimitRange being mis-configured). I think that's fine, but I just want to make sure it is.

@Yongxuanzhang
Copy link
Member Author

How will this act with LimitRange ? aka is the validation done pre or post applying limit range ? (I think it's pre). This means it only validates the users request – aka if there is LimitRange, then it would pass the validation but could fail later (LimitRange being mis-configured). I think that's fine, but I just want to make sure it is.

This is a good question. And I agree that if LimitRange is mis-configured it will pass this and fail somewhere else. Validating LimitRange is out of the scope of this PR and issue. This one mainly focuses on validating the resources requested in taskSpec.

@vdemeester
Copy link
Member

Sounds good @Yongxuanzhang 🎉
/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 9, 2022
@tekton-robot tekton-robot merged commit c0ab5f3 into tektoncd:main Feb 9, 2022
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-none Denotes a PR that doesnt merit a release note. 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.

TaskRun Reason doesn't properly describe error for invalid ResourceRequest
4 participants