Skip to content

Commit 3e8f562

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 3e8f562

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
@@ -32,6 +32,7 @@ A Helm chart deploying a worker pod that runs Bluesky plans
3232
| podAnnotations | object | `{}` | |
3333
| podLabels | object | `{}` | |
3434
| podSecurityContext | object | `{}` | |
35+
| pvcautodeletion.enabled | bool | `true` | |
3536
| readinessProbe | object | `{"failureThreshold":2,"httpGet":{"path":"/healthz","port":"http"},"periodSeconds":10}` | Readiness probe, if configured kubernetes will not route traffic to this pod if failed consecutively. This could allow the service time to recover if it is being overwhelmed by traffic, but without the to ability to load balance or scale up/outwards, upstream services will need to know to back off. This is automatically disabled when in debug mode. |
3637
| resources | object | `{"limits":{"cpu":"2000m","memory":"4000Mi"},"requests":{"cpu":"200m","memory":"400Mi"}}` | Sets the compute resources available to the pod. These defaults are appropriate when using debug mode or an internal PVC and therefore running VS Code server in the pod. In the Diamond cluster, requests must be >= 0.1*limits When not using either of the above, the limits may be lowered. When idle but connected, blueapi consumes ~400MB of memory and 1% cpu and may struggle when allocated less. |
3738
| restartOnConfigChange | bool | `true` | If enabled the blueapi pod will restart on changes to `worker` |

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-deletion.sh: |-
59+
{{ $files.Get "files/scripts/pvc-deletion.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
@@ -174,6 +174,14 @@
174174
"podSecurityContext": {
175175
"type": "object"
176176
},
177+
"pvcautodeletion": {
178+
"type": "object",
179+
"properties": {
180+
"enabled": {
181+
"type": "boolean"
182+
}
183+
}
184+
},
177185
"readinessProbe": {
178186
"description": "Readiness probe, if configured kubernetes will not route traffic to this pod if failed consecutively. This could allow the service time to recover if it is being overwhelmed by traffic, but without the to ability to load balance or scale up/outwards, upstream services will need to know to back off. This is automatically disabled when in debug mode.",
179187
"type": "object",

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+
pvcautodeletion:
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)