Skip to content

Commit 61215cd

Browse files
committed
Sorting out the weekly cronjob for pvc auto deletion, also adding someting to value yaml to turn it off
1 parent 0142922 commit 61215cd

5 files changed

Lines changed: 105 additions & 1 deletion

File tree

helm/blueapi/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A Helm chart deploying a worker pod that runs Bluesky plans
99
| Key | Type | Default | Description |
1010
|-----|------|---------|-------------|
1111
| affinity | object | `{}` | May be required to run on specific nodes (e.g. the control machine) |
12+
| autodeletion.enabled | bool | `true` | |
1213
| debug.enabled | bool | `false` | If enabled, runs debugpy, allowing port-forwarding to expose port 5678 or attached vscode instance |
1314
| debug.log_to_stderr | bool | `false` | If enabled configures debugpy to use the option `--log-to-stderr` |
1415
| debug.suspend | bool | `false` | If enabled does not start the service on startup This allows connecting to the pod and starting the service manually to allow debugging on the cluster |

helm/blueapi/templates/configmap.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@ data:
4646
time-stamper.sh: |-
4747
{{ $files.Get "files/scripts/time-stamper.sh" | indent 4 }}
4848
{{- end }}
49+
50+
---
51+
{{- if .Values.pvcautodeletion.enabled }}
52+
apiVersion: v1
53+
kind: ConfigMap
54+
metadata:
55+
name : {{include "blueapi.fullname" . }}-pvc-autodeletion-script
56+
data:
57+
{{- $files := .Files }}
58+
pvc-autodeletion.sh: |-
59+
{{ $files.Get "files/scripts/pvc-autodeletion.sh" | indent 4 }}
60+
{{- end }}

helm/blueapi/templates/cronjob.yaml

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ spec:
4545
spec:
4646
# amount of attempts of labeling a pvc
4747
backoffLimit: 3
48-
# job stops after 60 secounds
48+
# job stops after 60 seconds
4949
activeDeadlineSeconds: 60
5050
template:
5151
spec:
@@ -77,3 +77,83 @@ spec:
7777
command: ["/scripts/time-stamper.sh"]
7878
restartPolicy: OnFailure
7979
{{- end }}
80+
81+
{{- if .Values.pvcautodeletion.enabled }}
82+
apiVersion: v1
83+
kind: ServiceAccount
84+
metadata:
85+
name: {{ include "blueapi.fullname" . }}-pvcautodeletion
86+
namespace: {{ .Release.Namespace }}
87+
automountServiceAccountToken: true
88+
---
89+
apiVersion: rbac.authorization.k8s.io/v1
90+
kind: Role
91+
metadata:
92+
name: {{ include "blueapi.fullname" . }}-pvcautodeletion
93+
namespace: {{ .Release.Namespace }}
94+
rules:
95+
- apiGroups: [""]
96+
resources: ["pods", "persistentvolumeclaims"]
97+
verbs: ["get", "list", "patch"]
98+
---
99+
apiVersion: rbac.authorization.k8s.io/v1
100+
kind: RoleBinding
101+
metadata:
102+
name: {{ include "blueapi.fullname" . }}-pvcautodeletion
103+
namespace: {{ .Release.Namespace }}
104+
subjects:
105+
- kind: ServiceAccount
106+
name: {{ include "blueapi.fullname" . }}-pvcautodeletion
107+
namespace: {{ .Release.Namespace }}
108+
roleRef:
109+
kind: Role
110+
name: {{ include "blueapi.fullname" . }}-pvcautodeletion
111+
apiGroup: rbac.authorization.k8s.io
112+
---
113+
apiVersion: batch/v1
114+
kind: CronJob
115+
metadata:
116+
name: {{ include "blueapi.fullname" . }}-pvcautodeletion
117+
namespace: {{ .Release.Namespace }}
118+
spec:
119+
concurrencyPolicy: Forbid
120+
successfulJobsHistoryLimit: 3
121+
failedJobsHistoryLimit: 1
122+
schedule: "@weekly"
123+
124+
jobTemplate:
125+
spec:
126+
# amount of attempts of labeling a pvc
127+
backoffLimit: 3
128+
# job stops after 300 seconds
129+
activeDeadlineSeconds: 300
130+
template:
131+
spec:
132+
serviceAccountName: {{ include "blueapi.fullname" . }}-pvcautodeletion
133+
{{- with .Values.tolerations }}
134+
tolerations:
135+
{{- toYaml . | nindent 12 }}
136+
{{- end }}
137+
138+
volumes:
139+
- name : {{include "blueapi.fullname" . }}-pvc-autodeletion-script
140+
configMap:
141+
name: {{include "blueapi.fullname" . }}-pvc-autodeletion-script
142+
defaultMode: 0555
143+
144+
145+
containers:
146+
- name: pvcautodeletion
147+
env:
148+
- name: RELEASE_NAME
149+
value: {{ .Release.Name }}
150+
- name: RELEASE_NAMESPACE
151+
value: {{ .Release.Namespace }}
152+
volumeMounts:
153+
- name: {{include "blueapi.fullname" . }}-pvc-autodeletion-script
154+
mountPath: /scripts
155+
image: bitnami/kubectl:latest
156+
imagePullPolicy: IfNotPresent
157+
command: ["/scripts/pvc-deletion.sh"]
158+
restartPolicy: OnFailure
159+
{{- end }}

helm/blueapi/values.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
"description": "May be required to run on specific nodes (e.g. the control machine)",
99
"type": "object"
1010
},
11+
"autodeletion": {
12+
"type": "object",
13+
"properties": {
14+
"enabled": {
15+
"type": "boolean"
16+
}
17+
}
18+
},
1119
"debug": {
1220
"type": "object",
1321
"properties": {

helm/blueapi/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ initContainer:
227227
timeStampCron:
228228
enabled: true
229229

230+
autodeletion:
231+
enabled: true
232+
230233
debug:
231234
# -- If enabled, runs debugpy, allowing port-forwarding to expose port 5678 or attached vscode instance
232235
enabled: false

0 commit comments

Comments
 (0)