Skip to content

Commit

Permalink
Fix taskrun not working with workspace having volumeClaimTemplate
Browse files Browse the repository at this point in the history
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 tektoncd#5537
  • Loading branch information
piyush-garg committed Sep 26, 2022
1 parent 898baef commit 1532573
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
24 changes: 24 additions & 0 deletions examples/v1beta1/taskruns/workspace-with-volumeClaimTemplate.yaml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 11 additions & 10 deletions pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1532573

Please sign in to comment.