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

TEP-0061, Allow custom task to be embedded. #3901

Merged
merged 4 commits into from
May 25, 2021

Conversation

ScrapCodes
Copy link
Contributor

@ScrapCodes ScrapCodes commented Apr 28, 2021

Changes

TEP-0061, Allow custom task to be embedded

  1. API changes, This PR adds new APIs i.e. adds a field Spec *EmbeddedRunSpec to RunSpec
  2. An embedded task will accept new field Spec with type runtime.RawExtension in addition to ApiVersion and Kind fields of type string (as part of runtime.TypeMeta) :
  3. Validation changes, in addition to adding support for Run.RunSpec.Spec the validations will be changed to support "One of Run.RunSpec.Spec or Run.RunSpec.Ref" only and not both as part of a single API request to kubernetes.
  4. Unit tests + e2e test to cover the newly added fields and above mentioned validations.
  5. Documentation changes associated with TEP-0061.
    References:
  6. TEP-0061 Allow custom task to be embedded in pipeline, design. community#415
  7. Custom Tasks: question with taskSpec #3682
  8. https://github.com/tektoncd/community/blob/main/teps/0061-allow-custom-task-to-be-embedded-in-pipeline.md

@Tomcli
@pritidesai
@afrittoli
@animeshsingh

/cc @sbwsg @imjasonh

/kind feature

Closes #3682

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


# It is now possible to embed the spec of a custom task in a Run resource, whether stand-alone or embedded in a Pipeline.

e.g.

          apiVersion: tekton.dev/v1alpha1
          kind: Run
          metadata:
            name: simpletasklooprun
          spec:
            params:
              - name: word
                value:
                  - jump
                  - land
              - name: suffix
                value: ing
            spec:
              apiVersion: custom.tekton.dev/v1alpha1
              kind: TaskLoop
              spec:
                # This is a new field, which comprises of custom-task spec.
                taskRef:
                  name: simpletask
                iterateParam: word
                timeout: 60s
                retries: 2


1. API changes, This PR adds new APIs i.e. adds a field `Spec *EmbeddedRunSpec` to `RunSpec`
2. An embedded task will accepts new field `Spec` with type `runtime.RawExtension` in addition to
    `ApiVersion` and `Kind` fields of type string (as part of `runtime.TypeMeta`) 
3. Validation changes, in addition to adding support for `Run.RunSpec.Spec` the validations will be changed
    to support "One of `Run.RunSpec.Spec` or `Run.RunSpec.Ref` " only and not both as part of a single
    API request to kubernetes.

action required: Developers of custom controllers (existing and new), who would like to support
 embedded spec for their custom task, need to implement the logic required to extract, validate
 and use the custom task spec from the new RunSpec.Spec field. Please review the documentation
 on upgrading, for more details and some examples.

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 28, 2021
@tekton-robot
Copy link
Collaborator

Hi @ScrapCodes. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 28, 2021
@ScrapCodes ScrapCodes force-pushed the implementation_tep_61 branch 2 times, most recently from 967685d to 716d12a Compare April 28, 2021 13:37
@ScrapCodes ScrapCodes changed the title TEP-0061 Implementation Part(1/3), Allow custom task to be embedded in PipelineRun. TEP-0061 (1/3), Allow custom task to be embedded. Apr 28, 2021
@ScrapCodes ScrapCodes marked this pull request as draft April 28, 2021 13:50
@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 29, 2021
@ScrapCodes ScrapCodes marked this pull request as ready for review April 29, 2021 05:26
@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 Apr 29, 2021
@tekton-robot tekton-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 29, 2021
@pritidesai
Copy link
Member

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 29, 2021
@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/v1alpha1/run_validation.go 87.5% 90.9% 3.4
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.6% 95.9% 0.3
pkg/controller/filter.go 95.5% 97.1% 1.6
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.8% -0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.1% 92.2% 0.1

@Tomcli
Copy link
Contributor

Tomcli commented Apr 29, 2021

@ScrapCodes looks like you haven't run hack/update-codegen.sh to regenerate the api code

@afrittoli
Copy link
Member

Changes

##TEP-0061 (1/3), Allow custom task to be embedded.

    This is first in the three part series of PRs for implementing the TEP-0061.
  1. API changes, This PR adds new APIs i.e. adds a field Spec *v1beta1.EmbeddedTask to RunSpec
  2. An embedded task will accept new field Spec with type runtime.RawExtension in addition to ApiVersion and Kind fields of type string (as part of runtime.TypeMeta) :
  3. Validation changes, in addition to adding support for Run.RunSpec.Spec the validations will be changed to support "One of Run.RunSpec.Spec or Run.RunSpec.Ref" only and not both as part of a single API request to kubernetes.
  4. Unit tests to cover the newly added fields and above mentioned validations.

(2/3) Will consist of an e2e test.

To be honest, I would feel more comfortable having the E2E test part of this PR.
The PR is not too large, so it would be ok to have all in one go in fact.

(3/3) Documentation changes associated with TEP-0061.

Again, I would prefer to have this in the same PR, but I'm ok with having it as a follow-up, as long as we merge both PR as part of the same release.

/kind feature

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

 1. API changes, This PR adds new APIs i.e. adds a field `Spec *v1beta1.EmbeddedTask` to `RunSpec`
 2. An embedded task will accepts new field `Spec` with type `runtime.RawExtension` in addition to
     `ApiVersion` and `Kind` fields of type string (as part of `runtime.TypeMeta`) 
 3. Validation changes, in addition to adding support for `Run.RunSpec.Spec` the validations will be changed
     to support "One of `Run.RunSpec.Spec` or `Run.RunSpec.Ref` " only and not both as part of a single
    API request to kubernetes.

NIT: Could you add a more high level description on top or the release notes, something along the lines of
"It is now possible to embed the spec of a custom task in a Run resource, whether stand-alone or embedded in a Pipeline.
[include a yaml example]. Embedding the spec of a custom task depends on this being supported in each custom task controller that wants to support this feature."

action required: For developers of custom controllers (existing and new), now a `RunSpec`
 can have a `Ref` or `Spec`, Scenario, where custom controller supports either or both `Ref`
 and `Spec`. Please update the validation logic so that it responds with proper validation errors
 or response to the user for missing a `Ref` and or `Spec`.

Could you keep this block ^^^ together with the release notes? Having two blocks might break the release notes automation.

I think it's a good idea to make a call for action, but we could say that "Developers of custom controllers (existing and new), who would like to support embedded spec for their custom task, need to implement the logic required to extract, validate and use the custom task spec from the new RunSpec.Spec field. "

As discussed during the API WG and noted by @imjasonh - having validation of the spec via a validating webhook would mean that all validating webhook of all custom tasks would be invoked for each Run - which might be too much. Perhaps we should recommend async validation during the reconcile cycle instead for now?

References:

  1. tektoncd/community#415
  2. Custom Tasks: question with taskSpec #3682
  3. https://github.com/tektoncd/community/blob/main/teps/0061-allow-custom-task-to-be-embedded-in-pipeline.md

@Tomcli
@pritidesai
@afrittoli
@animeshsingh

/cc @sbwsg @imjasonh

@afrittoli
Copy link
Member

Thanks a lot @ScrapCodes for this, I look forward to this feature! I will review the code today.
We will have release v0.24 next week (it's planned for the 5th), do you think we include this in the milestone for the release?

@ScrapCodes ScrapCodes changed the title TEP-0061 (1/3), Allow custom task to be embedded. TEP-0061 (2/2), Allow custom task to be embedded. Apr 30, 2021
@tekton-robot tekton-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 30, 2021
@ScrapCodes
Copy link
Contributor Author

@ScrapCodes: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Looks like this robot does not interpret nested backticks. So, removed them.

@@ -765,6 +767,22 @@ func (c *Reconciler) createRun(ctx context.Context, rprt *resources.ResolvedPipe
},
}

if rprt.PipelineTask.TaskSpec != nil {
j, err := json.Marshal(rprt.PipelineTask.TaskSpec.Spec)
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 when spec is empty here? do we need a check here rprt.PipelineTask.TaskSpec.Spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is no error for empty spec, in fact a non empty byte sequence is generated. Do you think we should be more defensive here?

Copy link
Member

Choose a reason for hiding this comment

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

I am trying to think if there is any use case where the spec could be empty, could this ever be used in any way?

Since this is not producing any error, its safe to go with the way its implemented now and revisit if needed in future.

@pritidesai
Copy link
Member

the changes looks great @ScrapCodes. I am done reviewing the PR and have requested couple of changes. 🙏

One more thing I am not sure about is all the third party changes, without changing the mod file, how come we are seeing the dependency change 🤔

@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/v1alpha1/run_validation.go 87.5% 95.5% 8.0
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.6% 95.9% 0.3
pkg/controller/filter.go 95.5% 97.1% 1.6
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.8% -0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.1% 92.2% 0.1

@ScrapCodes
Copy link
Contributor Author

the changes looks great @ScrapCodes. I am done reviewing the PR and have requested couple of changes. 🙏

One more thing I am not sure about is all the third party changes, without changing the mod file, how come we are seeing the dependency change 🤔

I am not sure either, they are generated as part of running, hack/update-codegen.sh.

@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/v1alpha1/run_validation.go 87.5% 95.5% 8.0
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.6% 95.9% 0.3
pkg/controller/filter.go 95.5% 97.1% 1.6
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.8% -0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.1% 92.2% 0.1

    It is now possible to embed the spec of a custom task in a Run resource, whether stand-alone in Run or embedded in a Pipeline.

e.g. in a Run using example TaskLoop controller in tektoncd/experimental/task-loop/

          apiVersion: tekton.dev/v1alpha1
          kind: Run
          metadata:
            name: simpletasklooprun
          spec:
            params:
              - name: word
                value:
                  - jump
                  - land
              - name: suffix
                value: ing
            spec:
              apiVersion: custom.tekton.dev/v1alpha1
              kind: TaskLoop
              spec:
                # This is a new field, which comprises of custom-task spec.
                taskRef:
                  name: simpletask
                iterateParam: word
                timeout: 60s
                retries: 2

1. API changes, This PR adds new APIs i.e. adds a field `Spec EmbeddedRunSpec` to `RunSpec`
2. An embedded task will accepts new field `Spec` with type `runtime.RawExtension` in addition to
    `ApiVersion` and `Kind` fields of type string (as part of `runtime.TypeMeta`)
3. Validation changes, in addition to adding support for `Run.RunSpec.Spec` the validations will be changed
    to support "One of `Run.RunSpec.Spec` or `Run.RunSpec.Ref` " only and not both as part of a single
    API request to kubernetes.

    Developers of custom controllers (existing and new), who would
    like to support embedded spec for their custom task,
     need to implement the logic required to extract, validate
    and use the custom task spec from the new RunSpec.Spec field.
    Please review the documentation in docs/runs.md and docs/pipelines.md
@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/v1alpha1/run_validation.go 87.5% 95.5% 8.0
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.6% 95.9% 0.3
pkg/controller/filter.go 95.5% 97.1% 1.6
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.8% -0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.1% 92.2% 0.1

@ScrapCodes
Copy link
Contributor Author

Looks like it is a problem with my local environment. Even after removing those third_party additions, build passes i.e. build passes regardless of those third_party additions are present or not. Is this concerning from the point of view, how build is setup.

@ScrapCodes
Copy link
Contributor Author

Thank you @pritidesai for taking a look. Please take a look again.

Thank you @sbwsg !

Thank you @animeshsingh and @Tomcli for all the support 😄

@pritidesai
Copy link
Member

thank you for all the changes, please address the validation in a follow up PR.

I have updated the PR description to include the issue number and an attempt to fix release-tag.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 25, 2021
@tekton-robot tekton-robot merged commit f911d73 into tektoncd:main May 25, 2021
@Tomcli
Copy link
Contributor

Tomcli commented May 25, 2021

thanks @pritidesai for your review

@ScrapCodes
Copy link
Contributor Author

ScrapCodes commented May 26, 2021

Thank @pritidesai, for correcting me on this.

I have opened a follow-up PR with the validation: #3977

@ScrapCodes ScrapCodes deleted the implementation_tep_61 branch May 26, 2021 11:32
jerop added a commit to jerop/pipeline that referenced this pull request Jan 13, 2022
We already designed and implemented support for 
`Timeouts` and `TaskSpec` in `Custom Tasks`. 

`Timeouts`:
- TEP: tektoncd/community#433
- PR: tektoncd#3976

`TaskSpec`:
- TEP: https://github.com/tektoncd/community/blob/main/teps/0061-allow-custom-task-to-be-embedded-in-pipeline.md
- PR: tektoncd#3901

This item cleans up the todo items in `RunSpec`.
tekton-robot pushed a commit that referenced this pull request Jan 13, 2022
We already designed and implemented support for 
`Timeouts` and `TaskSpec` in `Custom Tasks`. 

`Timeouts`:
- TEP: tektoncd/community#433
- PR: #3976

`TaskSpec`:
- TEP: https://github.com/tektoncd/community/blob/main/teps/0061-allow-custom-task-to-be-embedded-in-pipeline.md
- PR: #3901

This item cleans up the todo items in `RunSpec`.
khrm pushed a commit to openshift/tektoncd-pipeline that referenced this pull request May 19, 2022
We already designed and implemented support for 
`Timeouts` and `TaskSpec` in `Custom Tasks`. 

`Timeouts`:
- TEP: tektoncd/community#433
- PR: tektoncd#3976

`TaskSpec`:
- TEP: https://github.com/tektoncd/community/blob/main/teps/0061-allow-custom-task-to-be-embedded-in-pipeline.md
- PR: tektoncd#3901

This item cleans up the todo items in `RunSpec`.
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/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom Tasks: question with taskSpec
6 participants