Skip to content

Add pending status support for TaskRun (parity with PipelineRun)ย #9376

@vdemeester

Description

@vdemeester

Problem

PipelineRun supports a "pending" status (spec.status: PipelineRunPending) that allows creating a PipelineRun without immediately starting execution. This is useful for:

  • Scheduling/batch operations where you want to control when execution begins
  • External admission control or approval workflows
  • Resource management and queuing

However, TaskRun does not support this feature. When a TaskRun is created, it immediately starts execution (Pod creation), with no way to defer it.

Expected Behavior

TaskRun should support a pending status similar to PipelineRun:

apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
  name: my-taskrun
spec:
  taskRef:
    name: my-task
  status: "TaskRunPending"  # New: defer execution

When pending:

  • The TaskRun is created but no Pod is created
  • status.startTime is not set
  • Condition is set to Unknown with reason TaskRunPending
  • Clearing spec.status (or setting to empty) starts execution
  • Setting spec.status: TaskRunCancelled cancels without running

Current State

In pkg/apis/pipeline/v1/taskrun_types.go:

const (
    // TaskRunSpecStatusCancelled is the only supported spec status
    TaskRunSpecStatusCancelled = "TaskRunCancelled"
)

In contrast, PipelineRun (pkg/apis/pipeline/v1/pipelinerun_types.go) supports:

  • PipelineRunSpecStatusPending
  • PipelineRunSpecStatusCancelled
  • PipelineRunSpecStatusCancelledRunFinally
  • PipelineRunSpecStatusStoppedRunFinally

Proposed Changes

  1. API (pkg/apis/pipeline/v1/taskrun_types.go):

    • Add TaskRunSpecStatusPending = "TaskRunPending" constant
    • Add TaskRunReasonPending TaskRunReason = "TaskRunPending" reason
    • Add IsPending() helper method
  2. Validation (pkg/apis/pipeline/v1/taskrun_validation.go):

    • Validate that TaskRun cannot be marked pending after it has started
    • Update validateSpecStatus to accept TaskRunPending
  3. Reconciler (pkg/reconciler/taskrun/taskrun.go):

    • Check for pending status before creating Pod
    • Set condition to Unknown with reason TaskRunPending
    • Skip StartTime initialization when pending
    • Return early from reconciliation
  4. Documentation (docs/taskruns.md):

    • Add section similar to "Pending PipelineRuns" in docs/pipelineruns.md
  5. Tests:

    • Add TestReconcileOnPendingTaskRun (similar to TestReconcileOnPendingPipelineRun)
    • Validation tests for pending state constraints

Use Cases

  1. External scheduling: Create TaskRuns in advance, start them based on external triggers
  2. Approval workflows: Require manual approval before task execution
  3. Resource management: Queue tasks and start them when resources are available
  4. Batch operations: Create multiple TaskRuns, start them simultaneously
  5. Testing/debugging: Create TaskRuns in pending state for inspection before running

Related

  • PipelineRun pending was added in commit fbbcf71392e3 (Nov 2020)
  • Documentation: Pending PipelineRuns

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions