Skip to content

Commit bdf8952

Browse files
committed
feat: add last-used-stamper cronjob
1 parent e80b4af commit bdf8952

7 files changed

Lines changed: 44 additions & 39 deletions

File tree

helm/blueapi/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ A Helm chart deploying a worker pod that runs Bluesky plans
4444
| serviceAccount.create | bool | `false` | |
4545
| serviceAccount.name | string | `""` | |
4646
| startupProbe | object | `{"failureThreshold":5,"httpGet":{"path":"/healthz","port":"http"},"periodSeconds":10}` | A more lenient livenessProbe to allow the service to start fully. This is automatically disabled when in debug mode. |
47+
| timeStampCron.enabled | bool | `true` | |
4748
| tolerations | list | `[]` | May be required to run on specific nodes (e.g. the control machine) |
4849
| tracing | object | `{"fastapi":{"excludedURLs":"/healthz"},"otlp":{"enabled":false,"protocol":"http/protobuf","server":{"host":"http://opentelemetry-collector.tracing","port":4318}}}` | Exclude health probe requests from tracing by default to prevent spamming |
4950
| volumeMounts | list | `[{"mountPath":"/config","name":"worker-config","readOnly":true}]` | Additional volumeMounts on the output StatefulSet definition. Define how volumes are mounted to the container referenced by using the same name. |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
# Get PVCs belonging to this blueapi release
3+
ALL_PVC=$(kubectl get pvc -n $RELEASE_NAMESPACE \
4+
-o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | \
5+
grep "^$RELEASE_NAME-scratch-")
6+
# Get all PVCs currently mounted by running pods
7+
MOUNTED_PVCS=$(kubectl get pods -n $RELEASE_NAMESPACE \
8+
-o=jsonpath='{.items[*].spec.volumes[*].persistentVolumeClaim.claimName}' | tr ' ' '\n' | sort -u)
9+
NOW=$(date +%s)
10+
#loop through all the pvcs annotating ones thare are mounted or lack a last-used stamp
11+
for pvc in $ALL_PVC; do
12+
# Checks if Annotation for last-used is empty
13+
ANNOTATION=$(kubectl get pvc "$pvc" -n $RELEASE_NAMESPACE -o=jsonpath='{.metadata.annotations.last-used}')
14+
# -z checks if ANNOTATION is empty, if its empty or mounted to updates last-used else it ignores it
15+
if [ -z "$ANNOTATION" ]; then
16+
kubectl annotate --overwrite pvc "$pvc" -n $RELEASE_NAMESPACE last-used="$NOW"
17+
elif echo "$MOUNTED_PVCS" | grep -qx "$pvc"; then
18+
kubectl annotate --overwrite pvc "$pvc" -n $RELEASE_NAMESPACE last-used="$NOW"
19+
fi
20+
done

helm/blueapi/templates/configmap.yaml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,14 @@ data:
3535
---
3636
{{- end }}
3737

38+
---
39+
{{- if .Values.timeStampCron.enabled }}
3840
apiVersion: v1
3941
kind: ConfigMap
4042
metadata:
4143
name : {{include "blueapi.fullname" . }}-pvc-stamper-script
4244
data:
43-
time-stamper.sh: |
44-
#!/bin/sh
45-
# Get PVCs belonging to this blueapi release
46-
ALL_PVC=$(kubectl get pvc -n {{ .Release.Namespace }} \
47-
-o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | \
48-
grep "^{{ .Release.Name }}-scratch-")
49-
# Get all PVCs currently mounted by running pods
50-
MOUNTED_PVCS=$(kubectl get pods -n {{ .Release.Namespace }} \
51-
-o=jsonpath='{.items[*].spec.volumes[*].persistentVolumeClaim.claimName}' | tr ' ' '\n' | sort -u)
52-
NOW=$(date +%s)
53-
#loop through all the pvcs annotating ones thare are mounted or lack a last-used stamp
54-
for pvc in $ALL_PVC; do
55-
ANNOTATION=$(kubectl get pvc "$pvc" -n {{ .Release.Namespace }} -o=jsonpath='{.metadata.annotations.last-used}')
56-
if [ -z "$ANNOTATION" ]; then
57-
kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW"
58-
elif echo "$MOUNTED_PVCS" | grep -qx "$pvc"; then
59-
kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW"
60-
fi
61-
done
45+
{{- $files := .Files }}
46+
time-stamper.sh: |-
47+
{{ $files.Get "files/scripts/time-stamper.sh" | indent 4 }}
48+
{{- end }}

helm/blueapi/templates/cronjob.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spec:
4343
jobTemplate:
4444
spec:
4545
# amount of attempts of labeling a pvc
46-
backoffLimit: 0
46+
backoffLimit: 3
4747
# job stops after 60 secounds
4848
activeDeadlineSeconds: 60
4949
template:
@@ -63,6 +63,11 @@ spec:
6363

6464
containers:
6565
- name: last-used-stamper
66+
env:
67+
- name: RELEASE_NAME
68+
value: {{ .Release.Name }}
69+
- name: RELEASE_NAMESPACE
70+
value: {{ .Release.Namespace }}
6671
volumeMounts:
6772
- name: {{include "blueapi.fullname" . }}-pvc-stamper-script
6873
mountPath: /scripts

helm/blueapi/templates/tests/test-cronjob.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

helm/blueapi/values.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@
292292
}
293293
}
294294
},
295+
"timeStampCron": {
296+
"type": "object",
297+
"properties": {
298+
"enabled": {
299+
"type": "boolean"
300+
}
301+
}
302+
},
295303
"tolerations": {
296304
"description": "May be required to run on specific nodes (e.g. the control machine)",
297305
"type": "array"

helm/blueapi/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ initContainer:
224224
# -- Size of persistent volume
225225
size: "1Gi"
226226

227+
timeStampCron:
228+
enabled: true
229+
227230
debug:
228231
# -- If enabled, runs debugpy, allowing port-forwarding to expose port 5678 or attached vscode instance
229232
enabled: false

0 commit comments

Comments
 (0)