From 9cf7590959acd9ad9518e62d56f5941885614446 Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Mon, 26 Sep 2022 19:11:10 +0530 Subject: [PATCH] Fix taskrun not working with workspace having volumeClaimTemplate This will move the auto name generation of workspace to happen after the pvc is created for volumeClaimTemplate and then name will be generated for workspace of volumeClaimTemplate type Added an example Fix #5537 --- .../workspace-with-volumeClaimTemplate.yaml | 24 +++++++++++++++++++ pkg/reconciler/taskrun/taskrun.go | 21 ++++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 examples/v1beta1/taskruns/workspace-with-volumeClaimTemplate.yaml diff --git a/examples/v1beta1/taskruns/workspace-with-volumeClaimTemplate.yaml b/examples/v1beta1/taskruns/workspace-with-volumeClaimTemplate.yaml new file mode 100644 index 00000000000..03295ef8db7 --- /dev/null +++ b/examples/v1beta1/taskruns/workspace-with-volumeClaimTemplate.yaml @@ -0,0 +1,24 @@ +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + generateName: task-with-workspace-run- +spec: + taskSpec: + steps: + - name: list-files + image: ubuntu + script: ls $(workspaces.read-allowed.path) + workspaces: + - name: read-allowed + workspaces: + - name: read-allowed + volumeClaimTemplate: + metadata: + name: pvc + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + volumeMode: Filesystem diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index 2d36a8281b4..d19fef28578 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -448,16 +448,6 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1beta1.TaskRun, rtr *re recorder := controller.GetEventRecorder(ctx) var err error - // Get the randomized volume names assigned to workspace bindings - workspaceVolumes := workspace.CreateVolumes(tr.Spec.Workspaces) - - ts, err := applyParamsContextsResultsAndWorkspaces(ctx, tr, rtr, workspaceVolumes) - if err != nil { - logger.Errorf("Error updating task spec parameters, contexts, results and workspaces: %s", err) - return err - } - tr.Status.TaskSpec = ts - // Get the TaskRun's Pod if it should have one. Otherwise, create the Pod. var pod *corev1.Pod @@ -505,6 +495,17 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1beta1.TaskRun, rtr *re // This is used by createPod below. Changes to the Spec are not updated. tr.Spec.Workspaces = taskRunWorkspaces } + + // Get the randomized volume names assigned to workspace bindings + workspaceVolumes := workspace.CreateVolumes(tr.Spec.Workspaces) + + ts, err := applyParamsContextsResultsAndWorkspaces(ctx, tr, rtr, workspaceVolumes) + if err != nil { + logger.Errorf("Error updating task spec parameters, contexts, results and workspaces: %s", err) + return err + } + tr.Status.TaskSpec = ts + pod, err = c.createPod(ctx, ts, tr, rtr, workspaceVolumes) if err != nil { newErr := c.handlePodCreationError(tr, err)