Skip to content

Commit f63f0d2

Browse files
authored
Merge pull request #1576 from porter-dev/ym/existing_volume_job
chore: allow mounting volumes on job charts
2 parents 709263e + a90c1e6 commit f63f0d2

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

applications/job/form.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,31 @@ tabs:
147147
label: Propagate SIGTERM to child processes.
148148
settings:
149149
default: true
150+
- name: persistence_toggle
151+
contents:
152+
- type: heading
153+
label: Persistent Disks
154+
- type: subtitle
155+
label: Attach persistent disks to your job to retain data across runs.
156+
- type: checkbox
157+
label: Enable Persistence
158+
variable: pvc.enabled
159+
- name: persistent_storage
160+
show_if: pvc.enabled
161+
contents:
162+
- type: number-input
163+
label: Persistent Storage
164+
variable: pvc.storage
165+
placeholder: "ex: 20"
166+
settings:
167+
unit: Gi
168+
default: 20
169+
- type: string-input
170+
label: Mount Path
171+
variable: pvc.mountPath
172+
placeholder: "ex: /mypath"
173+
settings:
174+
default: /mypath
150175
- type: heading
151176
label: Image Settings
152177
- type: subtitle

applications/job/templates/cronjob.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ spec:
175175
readOnly: true
176176
{{ end }}
177177
{{ end }}
178+
{{ if .Values.pvc.enabled }}
179+
volumeMounts:
180+
- name: "{{ include "docker-template.fullname" . }}-storage"
181+
mountPath: {{ .Values.pvc.mountPath }}
182+
{{ end }}
178183
resources:
179184
requests:
180185
cpu: {{ .Values.resources.requests.cpu }}
@@ -245,13 +250,22 @@ spec:
245250
mountPath: /secrets/
246251
readOnly: true
247252
{{ end }}
248-
{{ if or .Values.cloudsql.enabled .Values.fileSecretMounts.enabled}}
253+
{{ if or .Values.cloudsql.enabled .Values.fileSecretMounts.enabled .Values.pvc.enabled}}
249254
volumes:
250255
{{ if .Values.cloudsql.enabled }}
251256
- name: "sidecar-volume-{{ include "docker-template.fullname" . }}"
252257
secret:
253258
secretName: "{{ include "cloudsql.serviceAccountJSONSecret" . }}"
254259
{{ end }}
260+
{{ if .Values.pvc.enabled }}
261+
- name: "{{ include "docker-template.fullname" . }}-storage"
262+
persistentVolumeClaim:
263+
{{- if .Values.pvc.existingVolume }}
264+
claimName: {{ .Values.pvc.existingVolume }}
265+
{{- else }}
266+
claimName: "{{ include "docker-template.fullname" . }}-pvc"
267+
{{- end }}
268+
{{ end }}
255269
{{ if .Values.fileSecretMounts.enabled }}
256270
{{ range .Values.fileSecretMounts.mounts }}
257271
- name: {{ .mountPath }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if and .Values.pvc.enabled (not .Values.pvc.existingVolume) -}}
2+
apiVersion: v1
3+
kind: PersistentVolumeClaim
4+
metadata:
5+
name: "{{ include "docker-template.fullname" . }}-pvc"
6+
spec:
7+
accessModes:
8+
- ReadWriteOnce
9+
resources:
10+
requests:
11+
storage: {{ .Values.pvc.storage }}
12+
{{ end }}

applications/job/validate.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@
6868
}
6969
}
7070
}
71+
},
72+
"pvc": {
73+
"type": "object",
74+
"properties": {
75+
"enabled": {
76+
"type": "boolean",
77+
"default": false
78+
},
79+
"storage": {
80+
"type": "string",
81+
"pattern": "^\\d+(Ki|Mi|Gi|Ti)$",
82+
"default": "20Gi"
83+
},
84+
"mountPath": {
85+
"type": "string",
86+
"default": "/mypath"
87+
},
88+
"existingVolume": {
89+
"type": "string",
90+
"default": ""
91+
}
92+
}
7193
}
7294
}
7395
}

applications/job/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,11 @@ fileSecretMounts:
105105
# enable this conservatively
106106
enableHostIpc: false
107107

108+
pvc:
109+
enabled: false
110+
storage: 20Gi
111+
mountPath: /mypath
112+
existingVolume: ""
113+
108114
# job timeout configuration
109115
activeDeadlineSeconds: # Optional - if not set, will use sidecar.timeout

0 commit comments

Comments
 (0)