Skip to content

Commit fb418aa

Browse files
authored
fix: Last used stamper (#5)
* extra comment * adding the bash script to config map, and pointing to it via the cronjob * updating release tag * was calling bin/bash not bin/sh and bitnami/kubectl doesn't have full bash * updating version
1 parent 5540e23 commit fb418aa

3 files changed

Lines changed: 40 additions & 22 deletions

File tree

helm/blueapi/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515

1616
# This is the chart version. This version number is incremented by the release process.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 1.12.7
18+
version: 1.12.9
1919

2020
# This is the version number of the application being deployed. This version number is incremented by the release process.
2121
# Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using.

helm/blueapi/templates/configmap.yaml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ data:
3131
init_config.yaml: |-
3232
scratch:
3333
{{- toYaml .Values.worker.scratch | nindent 6 }}
34+
35+
---
3436
{{- end }}
3537

36-
---
38+
apiVersion: v1
39+
kind: ConfigMap
40+
metadata:
41+
name : {{include "blueapi.fullname" . }}-pvc-stamper-script
42+
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

helm/blueapi/templates/cronjob.yaml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ spec:
3939
successfulJobsHistoryLimit: 3
4040
failedJobsHistoryLimit: 1
4141
schedule: "*/5 * * * *"
42+
4243
jobTemplate:
4344
spec:
4445
# amount of attempts of labeling a pvc
@@ -52,28 +53,20 @@ spec:
5253
tolerations:
5354
{{- toYaml . | nindent 12 }}
5455
{{- end }}
56+
57+
volumes:
58+
- name : {{include "blueapi.fullname" . }}-pvc-stamper-script
59+
configMap:
60+
name: {{include "blueapi.fullname" . }}-pvc-stamper-script
61+
defaultMode: 0500
62+
63+
5564
containers:
5665
- name: last-used-stamper
66+
volumeMounts:
67+
- name: {{include "blueapi.fullname" . }}-pvc-stamper-script
68+
mountPath: /scripts
5769
image: bitnami/kubectl:latest
5870
imagePullPolicy: IfNotPresent
59-
command:
60-
- /bin/sh
61-
- -c
62-
- |
63-
# Get PVCs belonging to this blueapi release
64-
ALL_PVC=$(kubectl get pvc -n {{ .Release.Namespace }} \
65-
-o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | \
66-
grep "^{{ .Release.Name }}-scratch-")
67-
# Get all PVCs currently mounted by running pods
68-
MOUNTED_PVCS=$(kubectl get pods -n {{ .Release.Namespace }} \
69-
-o=jsonpath='{.items[*].spec.volumes[*].persistentVolumeClaim.claimName}' | tr ' ' '\n' | sort -u)
70-
NOW=$(date +%s)
71-
for pvc in $ALL_PVC; do
72-
ANNOTATION=$(kubectl get pvc "$pvc" -n {{ .Release.Namespace }} -o=jsonpath='{.metadata.annotations.last-used}')
73-
if [ -z "$ANNOTATION" ]; then
74-
kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW"
75-
elif echo "$MOUNTED_PVCS" | grep -qx "$pvc"; then
76-
kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW"
77-
fi
78-
done
71+
command: ["/scripts/time-stamper.sh"]
7972
restartPolicy: OnFailure

0 commit comments

Comments
 (0)