|
| 1 | +# In this contrived example two different kinds of workspace volume are used to thread |
| 2 | +# data through a pipeline's tasks. |
| 3 | +# 1. A projected volume combines a: |
| 4 | +# - ConfigMap as source of recipe data. |
| 5 | +# - Secret to store a password. |
| 6 | +# 2. A PVC is used to share data from one task to the next. |
| 7 | +# |
| 8 | +# The end result is a pipeline that first checks if the password is correct and, if so, |
| 9 | +# copies data out of a recipe store onto a shared volume. The recipe data is then read |
| 10 | +# by a subsequent task and printed to screen. |
| 11 | +apiVersion: v1 |
| 12 | +kind: ConfigMap |
| 13 | +metadata: |
| 14 | + name: sensitive-recipe-storage |
| 15 | +data: |
| 16 | + brownies: | |
| 17 | + 1. Heat oven to 325 degrees F |
| 18 | + 2. Melt 1/2 cup butter w/ 1/2 cup cocoa, stirring smooth. |
| 19 | + 3. Remove from heat, allow to cool for a few minutes. |
| 20 | + 4. Transfer to bowl. |
| 21 | + 5. Whisk in 2 eggs, one at a time. |
| 22 | + 6. Stir in vanilla. |
| 23 | + 7. Separately combine 1 cup sugar, 1/4 cup flour, 1 cup chopped |
| 24 | + walnuts and pinch of salt |
| 25 | + 8. Combine mixtures. |
| 26 | + 9. Bake in greased pan for 30 minutes. Watch carefully for |
| 27 | + appropriate level of gooeyness. |
| 28 | +--- |
| 29 | +apiVersion: v1 |
| 30 | +kind: Secret |
| 31 | +metadata: |
| 32 | + name: secret-password |
| 33 | +type: Opaque |
| 34 | +data: |
| 35 | + password: aHVudGVyMg== |
| 36 | +--- |
| 37 | +apiVersion: v1 |
| 38 | +kind: PersistentVolumeClaim |
| 39 | +metadata: |
| 40 | + name: shared-task-storage |
| 41 | +spec: |
| 42 | + resources: |
| 43 | + requests: |
| 44 | + storage: 16Mi |
| 45 | + volumeMode: Filesystem |
| 46 | + accessModes: |
| 47 | + - ReadWriteOnce |
| 48 | +--- |
| 49 | +apiVersion: tekton.dev/v1beta1 |
| 50 | +kind: Task |
| 51 | +metadata: |
| 52 | + name: fetch-secure-data |
| 53 | +spec: |
| 54 | + workspaces: |
| 55 | + - name: secure-store |
| 56 | + - name: filedrop |
| 57 | + steps: |
| 58 | + - name: fetch-and-write |
| 59 | + image: ubuntu |
| 60 | + script: | |
| 61 | + if [ "hunter2" = "$(cat $(workspaces.secure-store.path)/password)" ]; then |
| 62 | + cp $(workspaces.secure-store.path)/recipe.txt $(workspaces.filedrop.path) |
| 63 | + else |
| 64 | + echo "wrong password!" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +--- |
| 68 | +apiVersion: tekton.dev/v1beta1 |
| 69 | +kind: Task |
| 70 | +metadata: |
| 71 | + name: print-data |
| 72 | +spec: |
| 73 | + workspaces: |
| 74 | + - name: storage |
| 75 | + readOnly: true |
| 76 | + params: |
| 77 | + - name: filename |
| 78 | + steps: |
| 79 | + - name: print-secrets |
| 80 | + image: ubuntu |
| 81 | + script: cat $(workspaces.storage.path)/$(params.filename) |
| 82 | +--- |
| 83 | +apiVersion: tekton.dev/v1beta1 |
| 84 | +kind: Pipeline |
| 85 | +metadata: |
| 86 | + name: fetch-and-print-recipe |
| 87 | +spec: |
| 88 | + workspaces: |
| 89 | + - name: data-store |
| 90 | + - name: shared-data |
| 91 | + tasks: |
| 92 | + - name: fetch-the-recipe |
| 93 | + taskRef: |
| 94 | + name: fetch-secure-data |
| 95 | + workspaces: |
| 96 | + - name: secure-store |
| 97 | + workspace: data-store |
| 98 | + - name: filedrop |
| 99 | + workspace: shared-data |
| 100 | + - name: print-the-recipe |
| 101 | + taskRef: |
| 102 | + name: print-data |
| 103 | + # Note: this is currently required to ensure order of write / read on PVC is correct. |
| 104 | + runAfter: |
| 105 | + - fetch-the-recipe |
| 106 | + params: |
| 107 | + - name: filename |
| 108 | + value: recipe.txt |
| 109 | + workspaces: |
| 110 | + - name: storage |
| 111 | + workspace: shared-data |
| 112 | +--- |
| 113 | +apiVersion: tekton.dev/v1beta1 |
| 114 | +kind: PipelineRun |
| 115 | +metadata: |
| 116 | + generateName: recipe-time- |
| 117 | +spec: |
| 118 | + pipelineRef: |
| 119 | + name: fetch-and-print-recipe |
| 120 | + workspaces: |
| 121 | + - name: data-store |
| 122 | + projected: |
| 123 | + sources: |
| 124 | + - secret: |
| 125 | + name: secret-password |
| 126 | + - configMap: |
| 127 | + name: sensitive-recipe-storage |
| 128 | + items: |
| 129 | + - key: brownies |
| 130 | + path: recipe.txt |
| 131 | + - name: shared-data |
| 132 | + persistentVolumeClaim: |
| 133 | + claimName: shared-task-storage |
0 commit comments