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

Custom task without api version return validation error #6505

Merged
merged 1 commit into from
Apr 25, 2023

Conversation

Yongxuanzhang
Copy link
Member

@Yongxuanzhang Yongxuanzhang commented Apr 6, 2023

Changes

This commit closes #6459. For a customtask reference in a pipelinetask, if the Kind is non-empty and not "Task" or "ClusterTask", then it should be a Custom task and api version should be set. If not then validation webhook should return error. TaskRun's taskRef validation will be handled separately in #6557

/kind bug

Signed-off-by: Yongxuan Zhang yongxuanzhang@google.com

Submitter Checklist

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

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • 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

Custom task without api version returns validation error

@tekton-robot tekton-robot added kind/bug Categorizes issue or PR as related to a bug. release-note-none Denotes a PR that doesnt merit a release note. labels Apr 6, 2023
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 6, 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/pipeline_types.go 97.1% 97.1% 0.0
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.9% 0.1

@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/pipeline_types.go 97.1% 97.1% 0.0
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.9% 0.1

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.

We'll need to modify the isCustomTask functions introduced in #6447.

Also (nit) there are some typos in the PR title/description where custom is spelled "custome", please fix.

pkg/apis/pipeline/v1/pipeline_types.go Outdated Show resolved Hide resolved
@Yongxuanzhang Yongxuanzhang changed the title Custome task without api version return validation error Custom task without api version return validation error Apr 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/pipeline_types.go 97.1% 97.2% 0.1
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 96.0% 0.1

@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/pipeline_types.go 97.1% 97.2% 0.1
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 96.0% 0.1


notCustomTaskKinds := map[TaskKind]bool{
"": true,
NamespacedTaskKind: true,
Copy link
Member

Choose a reason for hiding this comment

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

@jerop can you take a look here? I'm not sure if validation runs before or after defaulting. If the user sets "kind" = Task, didn't we decide that should be a custom task?

Copy link
Member

Choose a reason for hiding this comment

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

if user sets kind to task:

  • if apiversion is non-empty --> custom task
  • if apiversion is empty --> task (because this is what we default to, we add kind but leave apiversion as empty)

Copy link
Member

Choose a reason for hiding this comment

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

Do you or @Yongxuanzhang know whether defaulting runs before or after validation? (I couldn't find the answer here or here). If validation runs before defaulting, using kind = "Task" would be treated here as a Task when it's actually a custom task. But if defaulting runs first, using kind = "Task" is correctly treated here as a Task. My guess is the logic is correct since e2e tests are passing, but want to double check.

pkg/apis/pipeline/v1/pipeline_types.go Outdated Show resolved Hide resolved
@@ -123,6 +123,27 @@ func TestPipeline_Validate_Failure(t *testing.T) {
Message: `expected at least one, got none`,
Paths: []string{"spec.description", "spec.params", "spec.resources", "spec.tasks", "spec.workspaces"},
},
}, {
Copy link
Member

Choose a reason for hiding this comment

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

@Yongxuanzhang please add test cases where kind is set to:

  • "Task"
  • ClusterTask"
  • ""

Then add 3 more test cases that are exactly like above, but then APIVersion is also set

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.

please update the docs and add release notes 🙏🏾

@jerop jerop added this to the Pipelines v0.47 milestone Apr 11, 2023
@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 18, 2023
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 19, 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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0

pkg/apis/pipeline/v1/pipeline_validation.go Outdated Show resolved Hide resolved
Comment on lines 136 to 139
case pt.TaskRef != nil && !notCustomTaskKinds[pt.TaskRef.Kind]:
errs = errs.Also(pt.validateCustomTask())
case pt.TaskRef != nil && pt.TaskRef.APIVersion != "":
Copy link
Member

Choose a reason for hiding this comment

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

This might be more readable as:

case pt.TaskRef != nil:
  if pt.TaskRef.APIVersion != "" || !notCustomTaskKinds[pt.TaskRef.Kind] {
    pt.validateCustomTask()
  }

(Also could the double negative !notCustomTaskKinds be made into a positive?)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not so easy to merge these 2, there are some cases in this switch control, it seems not add readability with this

pkg/apis/pipeline/v1/pipeline_types.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/apis/pipeline/v1/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0

@Yongxuanzhang
Copy link
Member Author

/retest

taskKinds := map[TaskKind]bool{
"": true,
NamespacedTaskKind: true,
"ClusterTask": true,
Copy link
Member

Choose a reason for hiding this comment

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

we don't have cluster tasks in v1

Suggested change
"ClusterTask": true,

Copy link
Member

Choose a reason for hiding this comment

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

I think this section of our docs is wrong: https://github.com/tektoncd/pipeline/blob/main/docs/tasks.md#task-vs-clustertask ("There is no v1 API specification for ClusterTask but a v1beta1 clustertask can still be referenced in a v1 pipeline.")

Copy link
Member

Choose a reason for hiding this comment

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

I think this might not have been correct: #6587

pkg/apis/pipeline/v1beta1/pipeline_validation.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/pipeline_validation_test.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/pipeline_validation_test.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/pipeline_validation_test.go Outdated Show resolved Hide resolved
pkg/apis/pipeline/v1beta1/pipeline_validation_test.go Outdated Show resolved Hide resolved
p: &Pipeline{
ObjectMeta: metav1.ObjectMeta{Name: "pipeline"},
Spec: PipelineSpec{
Tasks: []PipelineTask{{Name: "foo", TaskRef: &TaskRef{Kind: "Example", Name: ""}}},
Copy link
Member

Choose a reason for hiding this comment

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

what happens if there was apiversion but no kind?

Copy link
Member Author

@Yongxuanzhang Yongxuanzhang Apr 20, 2023

Choose a reason for hiding this comment

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

It's tested in another test (pipelinetask validate), I will move these cases there.

Spec: PipelineSpec{
Tasks: []PipelineTask{{Name: "foo", TaskSpec: &EmbeddedTask{
TypeMeta: runtime.TypeMeta{
Kind: "Example",
Copy link
Member

Choose a reason for hiding this comment

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

what happens if there was apiversion but no kind?

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.

please add docs and release notes

@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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesnt merit a release note. labels Apr 20, 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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.1% 99.1% 0.0

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernick

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 Apr 20, 2023
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 Apr 25, 2023
This commit closes tektoncd#6459. For a customtask reference in a pipelinetask,
if the Kind is non-empty and not "Task" or "ClusterTask", then it should
be a Custom task and api version should be set. If not then validation
webhook should return error. TaskRun's taskRef validation will be
handled separately in tektoncd#6557

Signed-off-by: Yongxuan Zhang yongxuanzhang@google.com
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Apr 25, 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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.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/pipeline_validation.go 99.4% 99.4% 0.0
pkg/apis/pipeline/v1beta1/pipeline_validation.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.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2023
@tekton-robot tekton-robot merged commit 7d6cd81 into tektoncd:main Apr 25, 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/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.

Any non-empty Kind with empty APIVersion in TaskRef is a Task
4 participants