Skip to content

Support optional workspaces #46

@vdemeester

Description

@vdemeester

Problem

Tekton supports optional workspaces — a task can declare a workspace as optional, and the pipeline can choose not to bind it. Steps can check whether an optional workspace is bound using when expressions or $(workspaces.name.bound).

Currently chisel/mallet does not handle the optional: true field on workspace declarations.

Tekton Spec

apiVersion: tekton.dev/v1
kind: Task
metadata:
  name: my-task
spec:
  workspaces:
  - name: credentials
    optional: true
  steps:
  - name: check
    image: alpine
    script: |
      if [ "$(workspaces.credentials.bound)" = "true" ]; then
        echo "Using credentials from workspace"
      else
        echo "No credentials provided, using defaults"
      fi

Also works in when expressions:

when:
- input: $(workspaces.credentials.bound)
  operator: in
  values: ["true"]

Upstream examples

  • optional-workspaces.yaml
  • using-optional-workspaces-in-when-expressions.yaml

Implementation

  1. Parse optional: true on workspace declarations
  2. Don't error when an optional workspace is not bound
  3. Substitute $(workspaces.name.bound) with true/false
  4. When not bound, $(workspaces.name.path) should resolve to empty string or a defined sentinel

Acceptance Criteria

  • optional: true workspaces don't require binding
  • $(workspaces.name.bound) resolves to true/false
  • Unbound optional workspace doesn't cause errors
  • Works in when expressions
  • optional-workspaces* upstream examples pass
  • Works with both chisel and mallet

Jira: SRVKP-11415 (sub-gap)
Parent tracking: #41

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions