Skip to content

Commit 33726a6

Browse files
authored
Refactor time-stamper.sh script inclusion in ConfigMap
1 parent 079426b commit 33726a6

1 file changed

Lines changed: 6 additions & 19 deletions

File tree

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 }}

0 commit comments

Comments
 (0)