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

Implement timeout for custom tasks. #3976

Merged
merged 3 commits into from
Aug 5, 2021

Conversation

ScrapCodes
Copy link
Contributor

@ScrapCodes ScrapCodes commented May 26, 2021

Tekton shall give custom task controller an opportunity to respect timeout and do a proper cleanup. It depends on the individual custom task controller implementation - how exactly it responds.

closes #3962

Changes

Tekton controllers does not forcibly update the .status of a Run directly, that responsibility belongs to the Custom Task controller.

  1. Run can be created with a timeout now, and it is upto the custom task controller to support it or not.

  2. Custom tasks inside a PipelineRun with pipeline wide timeout and/or pipeline task level timeout is updated to run with same policy as it is for task runs. On timeout, the run's status is updated with "RunCancelled".

Added relevant tests.

Corresponding TEP update at: tektoncd/community#433

/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


Added timeout support for custom task. 
e.g.

        apiVersion: tekton.dev/v1alpha1
        kind: Run
        metadata:
          generateName: simpletasklooprun
        spec:
          timeout: 10s # set timeouts here.
          params:
            - name: word
              value:
                - jump
                - land
                - roll
            - name: suffix
              value: ing
          ref:
            apiVersion: custom.tekton.dev/v1alpha1
            kind: TaskLoop
            name: simpletaskloop

Existing custom task controller, can either support the new field or ignore it.

@tekton-robot tekton-robot added kind/feature Categorizes issue or PR as related to a new feature. 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 May 26, 2021
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 26, 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.

@ScrapCodes ScrapCodes marked this pull request as draft May 26, 2021 11:12
@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/work-in-progress Indicates that a PR should not merge because it is a work in progress. and removed 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 May 26, 2021
@ScrapCodes ScrapCodes marked this pull request as ready for review May 26, 2021 11:15
@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 May 26, 2021
@afrittoli
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 May 26, 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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 84.0% 85.2% 1.2
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.3% -0.5

@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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 84.0% 85.2% 1.2
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.3% -0.5

@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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 84.0% 85.2% 1.2
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.3% -0.5

@ScrapCodes ScrapCodes marked this pull request as draft May 26, 2021 15:17
@ScrapCodes ScrapCodes force-pushed the custom-task-timeout branch 2 times, most recently from 4c54723 to 78a913b Compare May 27, 2021 11:21
@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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 84.0% 85.2% 1.2
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.3% -0.5

@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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 84.0% 85.2% 1.2
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.3% -0.5

@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 May 27, 2021
@ScrapCodes ScrapCodes marked this pull request as ready for review May 27, 2021 12:08
@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 May 27, 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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 84.0% 85.2% 1.2
pkg/reconciler/pipelinerun/pipelinerun.go 83.8% 83.3% -0.5

    ## Changes

    Today, users can specify a timeout for a component Task of a
    Pipeline (see [PipelineTask.Timeout])

    Remove the existing validation that forbids adding
    PipelineTask.Timeout to a custom task definition.

    The Run type will specify a Timeout field to hold this value when
     created as part of a PipelineRun (or when Runs are created
     directly). Custom Task authors can read and propagate this field if
     desired.

    Tekton-owned controller will not forcibly update the .status of a
    Run directly. This will be the responsibility of Custom Task
    controller.

    For a PipelineRun with either a pipeline level timeout configured
     and/or the custom task level timout configuration, timeout is
    updated to the run with same policy as it is for task runs. On
    timeout, the running run's status is updated with "RunCancelled".

    A Custom Task author can watch for this status update (i.e.
    Run.Spec.Status == RunCancelled) and or Run.HasTimedOut() and
     take any corresponding actions ( i.e. a clean up e.g., cancel a
     cloud build, stop the waiting timer, tear down the approval
     listener).

Example:

     apiVersion: tekton.dev/v1alpha1
     kind: Run
     metadata:
       generateName: simpleexample
     spec:
       timeout: 10s # set timeouts here.
       params:
         - name: searching
           value: the purpose of my existence
       ref:
         apiVersion: custom.tekton.dev/v1alpha1
         kind: Example
         name: exampleName

    Unit and end to end test, ensures that on timeout either Pipeline
    level of task level, the custom task was patched /spec/status as
    RunCancelled.
  1. Removed timeout from custom task limitations

  2. Added an example
@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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 88.9% 89.5% 0.6
pkg/reconciler/pipelinerun/pipelinerun.go 83.4% 82.9% -0.5

@ScrapCodes
Copy link
Contributor Author

/test tekton-pipeline-unit-tests

@ghost
Copy link

ghost commented Aug 5, 2021

@imjasonh @afrittoli do you have time to review this PR before the 0.27 release on Monday?

Copy link
Member

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

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

Looks good to me, just some docs comments otherwise this seems good to go.

docs/runs.md Outdated Show resolved Hide resolved
@@ -51,7 +52,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
k8sApiLables "k8s.io/apimachinery/pkg/labels"
Copy link
Member

Choose a reason for hiding this comment

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

typo: labels

Maybe k8slabels? Or, just keep the original import path, and don't rename it at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed because, labels is freely used as a variable name and it is also imported in the same scope. Do you think it is ok to keep it as labels ? (it failed a style check in my IDE though. )

Copy link
Member

Choose a reason for hiding this comment

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

I don't feel strongly either way, maybe k8slabels

@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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 88.9% 89.5% 0.6
pkg/reconciler/pipelinerun/pipelinerun.go 83.7% 83.2% -0.5

@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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 88.9% 89.5% 0.6
pkg/reconciler/pipelinerun/pipelinerun.go 83.7% 83.2% -0.5

@imjasonh
Copy link
Member

imjasonh commented Aug 5, 2021

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

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.

I have one nit in the docs but otherwise this looks ready to approve from my pov!

#### Developer guide for custom controllers supporting `Timeout`

1. Tekton controllers will never directly update the status of the
`Run`, it is the responsibility of the custom task controller to support
Copy link

Choose a reason for hiding this comment

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

Am I right that what we mean here is that the custom task developer is expected to update the status/condition of the Run? It might be worth describing a simple common status/condition/reason that is used for timeouts. I'm thinking something like:

  1. Once resources or timers are cleaned up it is good practice to set a
    condition on the Run's status of Succeeded/False with a Reason
    of RunTimedOut.

@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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 5, 2021
Co-authored-by: Jason Hall <jasonhall@redhat.com>
@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_types.go 43.8% 61.5% 17.8
pkg/apis/pipeline/v1beta1/pipeline_types.go 95.9% 95.8% -0.1
pkg/reconciler/pipelinerun/cancel.go 88.9% 89.5% 0.6
pkg/reconciler/pipelinerun/pipelinerun.go 83.7% 83.2% -0.5

@ghost
Copy link

ghost commented Aug 5, 2021

/test tekton-pipeline-unit-tests

@ghost
Copy link

ghost commented Aug 5, 2021

/test pull-tekton-pipeline-integration-tests

1 similar comment
@ghost
Copy link

ghost commented Aug 5, 2021

/test pull-tekton-pipeline-integration-tests

@ghost
Copy link

ghost commented Aug 5, 2021

/lgtm

@tekton-robot tekton-robot assigned ghost Aug 5, 2021
@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 5, 2021
@tekton-robot tekton-robot merged commit 50ebf6a into tektoncd:main Aug 5, 2021
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 Denotes a PR that will be considered when it comes time to generate release notes. 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.

Timeout support for custom tasks.
6 participants