Skip to content

VolumeClaimTemplate creates PVC with storageClassName: "" instead of omitting the field #9362

@waveywaves

Description

@waveywaves

Expected Behavior

When a PipelineRun uses a volumeClaimTemplate workspace without specifying storageClassName, the created PVC should omit the storageClassName field entirely. This allows Kubernetes to use the cluster default StorageClass.

Actual Behavior

The PVC is created with storageClassName: '' (empty string). Kubernetes interprets an empty string as "explicitly no StorageClass", which prevents the PVC from binding to a PV.

# Created PVC (broken)
spec:
  storageClassName: ''   # Should be absent, not empty string

Steps to Reproduce the Problem

  1. Create a Pipeline with a workspace:
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
  name: test-pipeline
spec:
  workspaces:
    - name: shared-data
  tasks:
    - name: test-task
      workspaces:
        - name: shared-data
      taskSpec:
        workspaces:
          - name: shared-data
        steps:
          - name: test
            image: busybox
            script: echo "test"
  1. Create a PipelineRun with volumeClaimTemplate (no storageClassName):
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
  name: test-run
spec:
  pipelineRef:
    name: test-pipeline
  workspaces:
    - name: shared-data
      volumeClaimTemplate:
        spec:
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: 1Gi
  1. Inspect the created PVC:
kubectl get pvc -o yaml | grep storageClassName
  1. Observe storageClassName: '' instead of the field being absent

Additional Info

  • Kubernetes version:
1.27+
  • Tekton Pipeline version:
Regression between v0.56.x (working) and v0.59.x (broken)

Possible root cause:

The StorageClassName field in PersistentVolumeClaimSpec is a *string. When the pointer is:

  • nil → field omitted from JSON (correct)
  • points to "" → serialized as storageClassName: "" (bug)

The PVC creation logic in pkg/reconciler/volumeclaim/pvchandler.go or the deepcopy may be inadvertently setting an empty string pointer instead of preserving nil.

Metadata

Metadata

Assignees

Labels

kind/bugCategorizes issue or PR as related to a bug.

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions