Skip to content

Commit 4e8a7a5

Browse files
committed
Document how PVC access modes affect pipeline execution
The access mode configured for a PVC that is used as a workspace volume source may affect how a pipeline is executed, this is not well documented. This commit intend to improve the documentation about this and also provide an example on how to run parallel tasks when using PVC with ReadWriteOnce access mode. - Document how access mode affect task ordering in pipeline under "Specifying Workspace order in a Pipeline" - Provide a full pipeline example of how to use parallel tasks when using a PVC with access mode ReadWriteOnce - We we did provide a "PipelineRun example" under "Example PipelineRun definitions using Workspaces". This commit provide a full PipelineRun example using a workspace. Instead of providing examples of different volume sources here, examples on how to use different VolumeSources is moved to "Specifying VolumeSources in Workspaces" - The VolumeSources persistentVolumeClaim and volumeClaimTemplate both is a PVC, and PVCs has its own peculiarities, e.g. access mode that we document. Both PVC volume sources is moved to a section so we can document the common peculiarities in a single place - Add the workspace variable introduced in tektoncd#2506
1 parent ab391e7 commit 4e8a7a5

File tree

3 files changed

+178
-53
lines changed

3 files changed

+178
-53
lines changed

docs/workspaces.md

Lines changed: 91 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ weight: 5
1717
- [Using `Workspaces` in `Pipelines`](#using-workspaces-in-pipelines)
1818
- [Specifying `Workspace` order in a `Pipeline`](#specifying-workspace-order-in-a-pipeline)
1919
- [Specifying `Workspaces` in `PipelineRuns`](#specifying-workspaces-in-pipelineruns)
20-
- [Example `PipelineRun` definitions using `Workspaces`](#example-pipelinerun-definitions-using-workspaces)
20+
- [Example `PipelineRun` definition using `Workspaces`](#example-pipelinerun-definitions-using-workspaces)
2121
- [Specifying `VolumeSources` in `Workspaces`](#specifying-volumesources-in-workspaces)
22+
- [Using `PersistentVolumeClaims` as `VolumeSource`](#using-persistentvolumeclaims-as-volumesource)
23+
- [Using other types of `VolumeSources`](#using-other-types-of-volumesources)
2224
- [More examples](#more-examples)
2325

2426
## Overview
@@ -118,6 +120,8 @@ The following variables make information about `Workspaces` available to `Tasks`
118120

119121
- `$(workspaces.<name>.path)` - specifies the path to a `Workspace`
120122
where `<name>` is the name of the `Workspace`.
123+
- `$(workspaces.<name>.claim)` - specifies the name of the `PersistentVolumeClaim` used as a volume source for the `Workspace`
124+
where `<name>` is the name of the `Workspace`. If a volume source other than `PersistentVolumeClaim` is used, an empty string is returned.
121125
- `$(workspaces.<name>.volume)`- specifies the name of the `Volume`
122126
provided for a `Workspace` where `<name>` is the name of the `Workspace`.
123127

@@ -244,20 +248,28 @@ The `subPath` specified in a `Pipeline` will be appended to any `subPath` specif
244248

245249
Sharing a `Workspace` between `Tasks` requires you to define the order in which those `Tasks`
246250
will be accessing that `Workspace` since different classes of storage have different limits
247-
for concurrent reads and writes. For example, a `PersistentVolumeClaim` might only allow a
248-
single `Task` writing to it at once.
249-
250-
**Warning:** You *must* ensure that this order is correct. Incorrectly ordering can result
251-
in a deadlock where multiple `Task` `Pods` are attempting to mount a `PersistentVolumeClaim`
252-
for writing at the same time, which would cause the `Tasks` to time out.
253-
254-
To define this order, use the `runAfter` field in your `Pipeline` definition. For more
251+
for concurrent reads and writes. For example, a `PersistentVolumeClaim` with
252+
[access mode](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes)
253+
`ReadWriteOnce` only allow `Tasks` on the same node writing to it at once.
254+
255+
Using parallel `Tasks` in a `Pipeline` will work with `PersistentVolumeClaims` configured with
256+
[access mode](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes)
257+
`ReadWriteMany` or `ReadOnlyMany` but you must ensure that those are available for your storage class.
258+
When using `PersistentVolumeClaims` with access mode `ReadWriteOnce` for parallel `Tasks`, you can configure a
259+
workspace with it's own `PersistentVolumeClaim` for each parallel `Task`. See a full example of a
260+
[Pipeline with parallel tasks using PersistentVolumeClaims](../examples/v1beta1/pipelineruns/pipelinerun-with-parallel-tasks-using-pvc.yaml).
261+
262+
Use the `runAfter` field in your `Pipeline` definition to define when a `Task` should be executed. For more
255263
information, see the [`runAfter` documentation](pipelines.md#runAfter).
256264

265+
**Warning:** You *must* ensure that this order is compatible with the configured access modes for your `PersistentVolumeClaim`.
266+
Parallel `Tasks` using the same `PersistentVolumeClaim` with access mode `ReadWriteOnce`, may execute on
267+
different nodes and be forced to execute sequentially which may cause `Tasks` to time out.
268+
257269
#### Specifying `Workspaces` in `PipelineRuns`
258270

259271
For a `PipelineRun` to execute a `Pipeline` that includes one or more `Workspaces`, it needs to
260-
bind the `Workspace` names to physical volumes using its own `workspaces` field. Each entry in
272+
bind the `Workspace` names to volumes using its own `workspaces` field. Each entry in
261273
this list must correspond to a `Workspace` declaration in the `Pipeline`. Each entry in the
262274
`workspaces` list must specify the following:
263275

@@ -269,12 +281,52 @@ The entry must also include one `VolumeSource`. See [Using `VolumeSources` with
269281

270282
**Note:** If the `Workspaces` specified by a `Pipeline` are not provided at runtime by a `PipelineRun`, that `PipelineRun` will fail.
271283

272-
#### Example `PipelineRun` definitions using `Workspaces`
284+
#### Example `PipelineRun` definition using `Workspaces`
285+
286+
In the example below, a `volumeClaimTemplate` is provided for how a `PersistentVolumeClaim` should be created for a workspace named
287+
`myworkspace` declared in a `Pipeline`. When using `volumeClaimTemplate` a new `PersistentVolumeClaim` is created for
288+
each `PipelineRun` and it allows the user to specify e.g. size and StorageClass for the volume.
289+
290+
```yaml
291+
apiVersion: tekton.dev/v1beta1
292+
kind: PipelineRun
293+
metadata:
294+
generateName: pr-
295+
spec:
296+
pipelineRef:
297+
name: example-pipeline
298+
workspaces:
299+
- name: myworkspace # this workspace name must be declared in the Pipeline
300+
volumeClaimTemplate:
301+
spec:
302+
accessModes:
303+
- ReadWriteOnce # access mode may affect how you can use this volume in parallel tasks
304+
resources:
305+
requests:
306+
storage: 1Gi
307+
```
308+
309+
For examples of using other types of volume sources, see [Specifying `VolumeSources` in `Workspaces`](#specifying-volumesources-in-workspaces).
310+
For a more in-depth example, see the [`Workspaces` in `PipelineRun`](../examples/v1beta1/pipelineruns/workspaces.yaml) YAML sample.
311+
312+
### Specifying `VolumeSources` in `Workspaces`
313+
314+
You can only use a single type of `VolumeSource` per `Workspace` entry. The configuration
315+
options differ for each type. `Workspaces` support the following fields:
316+
317+
#### Using `PersistentVolumeClaims` as `VolumeSource`
318+
319+
`PersistentVolumeClaim` volumes are a good choice for sharing data among `Tasks` within a `Pipeline`.
320+
Beware that the [access mode](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes)
321+
configured for the `PersinstentVolumeClaim` effects how you can use the volume for parallel `Tasks` in a `Pipeline`. See
322+
[Specifying `workspace` order in a `Pipeline`](#specifying-workspace-order-in-a-pipeline) for more information about this.
323+
There are two ways of using `PersistentVolumeClaims` as a `VolumeSource`.
273324

274-
The examples below illustrate how to specify `Workspaces` in your `PipelineRuns`. For a more in-depth example, see the
275-
[`Workspaces` in `PipelineRun`](../examples/v1beta1/pipelineruns/workspaces.yaml) YAML sample.
325+
##### `volumeClaimTemplate`
276326

277-
In the example below, a template is provided for how a `PersistentVolumeClaim` should be created for a workspace named `myworkspace` declared in a `Pipeline`. When using `volumeClaimTemplate` a new `PersistentVolumeClaim` is created for each `PipelineRun` and it allows the user to specify e.g. size and StorageClass for the volume.
327+
The `volumeClaimTemplate` is a template of a [`PersistentVolumeClaim` volume](https://kubernetes.io/docs/concepts/storage/volumes/#persistentvolumeclaim),
328+
created for each `PipelineRun` or `TaskRun`. When the volume is created from a template in a `PipelineRun` or `TaskRun`
329+
it will be deleted when the `PipelineRun` or `TaskRun` is deleted.
278330

279331
```yaml
280332
workspaces:
@@ -288,8 +340,9 @@ workspaces:
288340
storage: 1Gi
289341
```
290342

291-
In the example below, an existing `PersistentVolumeClaim` named `mypvc` is used for a `Workspace`
292-
named `myworkspace` declared in a `Pipeline`. It exposes only the subdirectory `my-subdir` from that `PersistentVolumeClaim`:
343+
##### `persistentVolumeClaim`
344+
345+
The `persistentVolumeClaim` field references an *existing* [`persistentVolumeClaim` volume](https://kubernetes.io/docs/concepts/storage/volumes/#persistentvolumeclaim). The example exposes only the subdirectory `my-subdir` from that `PersistentVolumeClaim`
293346

294347
```yaml
295348
workspaces:
@@ -299,49 +352,21 @@ workspaces:
299352
subPath: my-subdir
300353
```
301354

302-
In the example below, a `ConfigMap` named `my-configmap` is used for a `Workspace`
303-
named `myworkspace` declared in a `Pipeline`:
355+
#### Using other types of `VolumeSources`
304356

305-
```yaml
306-
workspaces:
307-
- name: myworkspace
308-
configmap:
309-
name: my-configmap
310-
```
357+
##### `emptyDir`
311358

312-
In the example below, a `Secret` named `my-secret` is used for a `Workspace`
313-
named `myworkspace` declared in a `Pipeline`:
359+
The `emptyDir` field references an [`emptyDir` volume](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir) which holds
360+
a temporary directory that only lives as long as the `TaskRun` that invokes it. `emptyDir` volumes are **not** suitable for sharing data among `Tasks` within a `Pipeline`.
361+
However, they work well for single `TaskRuns` where the data stored in the `emptyDir` needs to be shared among the `Steps` of the `Task` and discarded after execution.
314362

315363
```yaml
316364
workspaces:
317365
- name: myworkspace
318-
secret:
319-
secretName: my-secret
366+
emptyDir: {}
320367
```
321368

322-
### Specifying `VolumeSources` in `Workspaces`
323-
324-
You can only use a single type of `VolumeSource` per `Workspace` entry. The configuration
325-
options differ for each type. `Workspaces` support the following fields:
326-
327-
#### `emptyDir`
328-
329-
The `emptyDir` field references an [`emptyDir` volume](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir) which holds
330-
a temporary directory that only lives as long as the `TaskRun` that invokes it. `emptyDir` volumes are **not** suitable for sharing data among `Tasks` within a `Pipeline`.
331-
However, they work well for single `TaskRuns` where the data stored in the `emptyDir` needs to be shared among the `Steps` of the `Task` and discarded after execution.
332-
333-
#### `persistentVolumeClaim`
334-
335-
The `persistentVolumeClaim` field references an existing [`persistentVolumeClaim` volume](https://kubernetes.io/docs/concepts/storage/volumes/#persistentvolumeclaim).
336-
`PersistentVolumeClaim` volumes are a good choice for sharing data among `Tasks` within a `Pipeline`.
337-
338-
#### `volumeClaimTemplate`
339-
340-
The `volumeClaimTemplate` is a template of a [`persistentVolumeClaim` volume](https://kubernetes.io/docs/concepts/storage/volumes/#persistentvolumeclaim), created for each `PipelineRun` or `TaskRun`.
341-
When the volume is created from a template in a `PipelineRun` or `TaskRun` it will be deleted when the `PipelineRun` or `TaskRun` is deleted.
342-
`volumeClaimTemplate` volumes are a good choice for sharing data among `Tasks` within a `Pipeline` when the volume is only used during a `PipelineRun` or `TaskRun`. See [`Workspaces` from a volumeClaimTemplate in a `PipelineRun`](../examples/v1beta1/pipelineruns/workspace-from-volumeclaimtemplate.yaml) for a complete example.
343-
344-
#### `configMap`
369+
##### `configMap`
345370

346371
The `configMap` field references a [`configMap` volume](https://kubernetes.io/docs/concepts/storage/volumes/#configmap).
347372
Using a `configMap` as a `Workspace` has the following limitations:
@@ -350,7 +375,14 @@ Using a `configMap` as a `Workspace` has the following limitations:
350375
- The `configMap` you want to use as a `Workspace` must exist prior to submitting the `TaskRun`.
351376
- `configMaps` are [size-limited to 1MB](https://github.com/kubernetes/kubernetes/blob/f16bfb069a22241a5501f6fe530f5d4e2a82cf0e/pkg/apis/core/validation/validation.go#L5042).
352377

353-
#### `secret`
378+
```yaml
379+
workspaces:
380+
- name: myworkspace
381+
configmap:
382+
name: my-configmap
383+
```
384+
385+
##### `secret`
354386

355387
The `secret` field references a [`secret` volume](https://kubernetes.io/docs/concepts/storage/volumes/#secret).
356388
Using a `secret` volume has the following limitations:
@@ -359,6 +391,13 @@ Using a `secret` volume has the following limitations:
359391
- The `secret` you want to use as a `Workspace` must exist prior to submitting the `TaskRun`.
360392
- `secret` are [size-limited to 1MB](https://github.com/kubernetes/kubernetes/blob/f16bfb069a22241a5501f6fe530f5d4e2a82cf0e/pkg/apis/core/validation/validation.go#L5042).
361393

394+
```yaml
395+
workspaces:
396+
- name: myworkspace
397+
secret:
398+
secretName: my-secret
399+
```
400+
362401
If you need support for a `VolumeSource` type not listed above, [open an issue](https://github.com/tektoncd/pipeline/issues) or
363402
a [pull request](https://github.com/tektoncd/pipeline/blob/master/CONTRIBUTING.md).
364403

examples/v1beta1/pipelineruns/pipelinerun-using-different-subpaths-of-workspace.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ spec:
4646
workspace: ws
4747
subPath: dir-1
4848
- name: writer-2
49+
runAfter:
50+
- writer-1
4951
taskRef:
5052
name: writer
5153
workspaces:
@@ -54,7 +56,6 @@ spec:
5456
subPath: dir-2
5557
- name: read-all
5658
runAfter:
57-
- writer-1
5859
- writer-2
5960
params:
6061
- name: directory1
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Task
3+
metadata:
4+
name: write-to-file
5+
spec:
6+
steps:
7+
- name: write
8+
image: ubuntu
9+
script: echo bar > $(workspaces.task-ws.path)/foo
10+
workspaces:
11+
- name: task-ws
12+
---
13+
apiVersion: tekton.dev/v1beta1
14+
kind: Task
15+
metadata:
16+
name: read-two
17+
spec:
18+
workspaces:
19+
- name: ws-a
20+
- name: ws-b
21+
steps:
22+
- name: read-1
23+
image: ubuntu
24+
script: cat $(workspaces.ws-a.path)/foo | grep bar
25+
- name: read-2
26+
image: ubuntu
27+
script: cat $(workspaces.ws-b.path)/foo | grep bar
28+
---
29+
apiVersion: tekton.dev/v1beta1
30+
kind: Pipeline
31+
metadata:
32+
name: pipeline-using-parallel-tasks
33+
spec:
34+
workspaces:
35+
- name: ws-track-a
36+
- name: ws-track-b
37+
tasks:
38+
- name: parallel-writer-a
39+
taskRef:
40+
name: write-to-file
41+
workspaces:
42+
- name: task-ws
43+
workspace: ws-track-a
44+
- name: parallel-writer-b
45+
taskRef:
46+
name: write-to-file
47+
workspaces:
48+
- name: task-ws
49+
workspace: ws-track-b
50+
- name: read-all
51+
runAfter:
52+
- parallel-writer-a
53+
- parallel-writer-b
54+
taskRef:
55+
name: read-two
56+
workspaces:
57+
- name: ws-a
58+
workspace: ws-track-a
59+
- name: ws-b
60+
workspace: ws-track-b
61+
---
62+
apiVersion: tekton.dev/v1beta1
63+
kind: PipelineRun
64+
metadata:
65+
generateName: pr-
66+
spec:
67+
pipelineRef:
68+
name: pipeline-using-parallel-tasks
69+
workspaces:
70+
- name: ws-track-a
71+
volumeClaimTemplate:
72+
spec:
73+
accessModes:
74+
- ReadWriteOnce
75+
resources:
76+
requests:
77+
storage: 1Gi
78+
- name: ws-track-b
79+
volumeClaimTemplate:
80+
spec:
81+
accessModes:
82+
- ReadWriteOnce
83+
resources:
84+
requests:
85+
storage: 1Gi

0 commit comments

Comments
 (0)