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

Reject embedded Tasks with APIVersion and/or Kind specified #5018

Merged

Conversation

abayer
Copy link
Contributor

@abayer abayer commented Jun 22, 2022

Changes

fixes #4543

If custom tasks are enabled and either of PipelineTask.TaskSpec.APIVersion or PipelineTask.TaskSpec.Kind are specified, the PipelineTask will be treated as a custom task. This is still the case if an actual embedded Task is specified in PipelineTask.TaskSpec.TaskSpec, so we should be failing validation for those cases.

/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
    (if there are no user facing changes, use release note "NONE")

Release Notes

Fail PipelineTask validation if a normal, non-custom embedded task is specified along with `apiVersion` and/or `kind`

@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. labels Jun 22, 2022
@tekton-robot tekton-robot requested review from jerop and lbernick June 22, 2022 16:01
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 22, 2022
@abayer
Copy link
Contributor Author

abayer commented Jun 22, 2022

/assign @wlynch @vdemeester @lbernick @jerop

@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/pipeline_types.go 96.8% 96.9% 0.1


// Reject cases where APIVersion and/or Kind are specified alongside an embedded Task.
// We determine if this is an embedded Task by checking of TaskSpec.TaskSpec.Steps has items.
if pt.TaskSpec != nil && len(pt.TaskSpec.TaskSpec.Steps) > 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If anyone has a better way to determine whether the PipelineTask is, in fact, an embedded Task, I'd love to hear it. =)

Copy link
Member

Choose a reason for hiding this comment

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

We could at least extract this in a function on PipelineTask, so that if we change the way to determine it, it won't change that code (and would make that code more readable ? 🙃 )

Copy link
Member

Choose a reason for hiding this comment

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

We require today that kind is specified if apiVersion is, but we don't check the content of kind and apiVersion.

Should we determine if it's an embedded Task or an embedded custom task based on the content of kind and apiVersion? We could say that (tekton.dev/*, Task) means it's an embedded Task and should be validated accordingly, else it's an embedded custom task and we cannot validate further.

Once we implement PIP, we can add Pipeline to the list types that we validate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vdemeester Good call, doing so.

@afrittoli I thought about that, but decided that it was better to be consistent, especially since Pipeline won't be in pt.TaskSpec.TaskSpec as an inline type.

Copy link
Contributor Author

@abayer abayer Jun 23, 2022

Choose a reason for hiding this comment

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

Also, the current behavior, with custom tasks enabled, with apiVersion/kind and TaskSpec.TaskSpec populated results in a Run getting created and never doing anything, so we're not breaking any existing use cases by being strict. And supporting Task in the TypeMeta would mean changes to reconciler logic to not treat those cases as custom tasks, which doesn't feel like it's worth doing.


// Reject cases where APIVersion and/or Kind are specified alongside an embedded Task.
// We determine if this is an embedded Task by checking of TaskSpec.TaskSpec.Steps has items.
if pt.TaskSpec != nil && len(pt.TaskSpec.TaskSpec.Steps) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

We could at least extract this in a function on PipelineTask, so that if we change the way to determine it, it won't change that code (and would make that code more readable ? 🙃 )

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 23, 2022
@abayer abayer force-pushed the reject-kind-apiversion-in-embedded-taskspec branch from 695dee7 to c4e3812 Compare June 23, 2022 13:00
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 23, 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/apis/pipeline/v1beta1/pipeline_types.go 96.8% 97.0% 0.1

@abayer
Copy link
Contributor Author

abayer commented Jun 23, 2022

/retest

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.

thanks @abayer! Could you document that the api version of a task embedded within a pipeline should match the api version of the pipeline?

func (pt PipelineTask) validateEmbeddedOrType() (errs *apis.FieldError) {
// Reject cases where APIVersion and/or Kind are specified alongside an embedded Task.
// We determine if this is an embedded Task by checking of TaskSpec.TaskSpec.Steps has items.
if pt.TaskSpec != nil && len(pt.TaskSpec.TaskSpec.Steps) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

why is checking if there are steps necessary? can we just check if pt.TaskSpec.TaskSpec != nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pt.TaskSpec.TaskSpec is just an inline TaskSpec, not a pointer, so this was the best I could come up with.

@abayer
Copy link
Contributor Author

abayer commented Jun 27, 2022

@lbernick Not sure about what to document in that regard - what this change is doing is making specifying apiVersion and/or kind and a populated pt.TaskSpec.TaskSpec invalid. So assuming this goes in, you won't be able to specify a Task's apiVersion in a PipelineTask at all.

@lbernick
Copy link
Member

Not sure about what to document in that regard - what this change is doing is making specifying apiVersion and/or kind and a populated pt.TaskSpec.TaskSpec invalid. So assuming this goes in, you won't be able to specify a Task's apiVersion in a PipelineTask at all.

Ah yeah I misspoke-- we could say that embedded Tasks within a Pipeline will create TaskRuns with the same API version as the pipeline

@abayer
Copy link
Contributor Author

abayer commented Jun 28, 2022

@lbernick 👍 - in practice, that's obviously just clarifying what's always been the case, but still worth having. =)

fixes tektoncd#4543

If custom tasks are enabled and either of `PipelineTask.TaskSpec.APIVersion` or `PipelineTask.TaskSpec.Kind` are specified, the `PipelineTask` will be treated as a custom task. This is still the case if an actual embedded `Task` is specified in `PipelineTask.TaskSpec.TaskSpec`, so we should be failing validation for those cases.

Signed-off-by: Andrew Bayer <[email protected]>
@abayer abayer force-pushed the reject-kind-apiversion-in-embedded-taskspec branch from c4e3812 to 71aa0c6 Compare June 28, 2022 13:31
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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:

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

@lbernick
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 28, 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/apis/pipeline/v1beta1/pipeline_types.go 96.8% 97.0% 0.1

@tekton-robot tekton-robot merged commit 88ea861 into tektoncd:main Jun 28, 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 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.

Pipelines don't respect mixed Task API versions
7 participants