From 05b63738572146bd374deb4db66e53edf4031c4f Mon Sep 17 00:00:00 2001 From: Alexj9837 Date: Wed, 1 Apr 2026 13:29:50 +0000 Subject: [PATCH 01/13] adding time-stamp cronjob to blueapi and a corasponding test --- helm/blueapi/templates/cronjob.yaml | 78 +++++++++++++++++++ .../blueapi/templates/tests/test-cronjob.yaml | 19 +++++ 2 files changed, 97 insertions(+) create mode 100644 helm/blueapi/templates/cronjob.yaml create mode 100644 helm/blueapi/templates/tests/test-cronjob.yaml diff --git a/helm/blueapi/templates/cronjob.yaml b/helm/blueapi/templates/cronjob.yaml new file mode 100644 index 0000000000..d1ff9bf325 --- /dev/null +++ b/helm/blueapi/templates/cronjob.yaml @@ -0,0 +1,78 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "blueapi.fullname" . }}-last-used-stamper + namespace: {{ .Release.Namespace }} +automountServiceAccountToken: true +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "blueapi.fullname" . }}-last-used-stamper + namespace: {{ .Release.Namespace }} +rules: +- apiGroups: [""] + resources: ["pods", "persistentvolumeclaims"] + verbs: ["get", "list", "patch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ include "blueapi.fullname" . }}-last-used-stamper + namespace: {{ .Release.Namespace }} +subjects: +- kind: ServiceAccount + name: {{ include "blueapi.fullname" . }}-last-used-stamper + namespace: {{ .Release.Namespace }} +roleRef: + kind: Role + name: {{ include "blueapi.fullname" . }}-last-used-stamper + apiGroup: rbac.authorization.k8s.io +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "blueapi.fullname" . }}-last-used-stamper + namespace: {{ .Release.Namespace }} +spec: + concurrencyPolicy: Forbid + successfulJobsHistoryLimit: 3 + failedJobsHistoryLimit: 1 + schedule: "*/5 * * * *" + jobTemplate: + spec: + # amount of attempts of labeling a pvc + backoffLimit: 2 + # job stops after 60 secounds + activeDeadlineSeconds: 60 + template: + spec: + serviceAccountName: {{ include "blueapi.fullname" . }}-last-used-stamper + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 12 }} + {{- end }} + containers: + - name: last-used-stamper + image: bitnami/kubectl:1.34.5 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -c + - | + # Get PVCs belonging to this blueapi release + ALL_PVC=$(kubectl get pvc -l "argocd.argoproj.io/instance={{ .Release.Name }}" \ + -o jsonpath='{.items[*].metadata.name}' -n {{ .Release.Namespace }} | tr ' ' '\n') + # Get all PVCs currently mounted by running pods + MOUNTED_PVCS=$(kubectl get pods -n {{ .Release.Namespace }} \ + -o=jsonpath='{.items[*].spec.volumes[*].persistentVolumeClaim.claimName}' | tr ' ' '\n' | sort -u) + NOW=$(date +%s) + for pvc in $ALL_PVC; do + ANNOTATION=$(kubectl get pvc "$pvc" -n {{ .Release.Namespace }} -o=jsonpath='{.metadata.annotations.last-used}') + if [ -z "$ANNOTATION" ]; then + kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW" + elif echo "$MOUNTED_PVCS" | grep -qx "$pvc"; then + kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW" + fi + done + restartPolicy: OnFailure diff --git a/helm/blueapi/templates/tests/test-cronjob.yaml b/helm/blueapi/templates/tests/test-cronjob.yaml new file mode 100644 index 0000000000..52df70cba5 --- /dev/null +++ b/helm/blueapi/templates/tests/test-cronjob.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Pod +metadata: + name: {{ include "blueapi.fullname" . }}-last-used-stamper + annotations: + "helm.sh/hook": test +spec: + serviceAccountName: {{ include "blueapi.fullname" . }}-last-used-stamper + containers: + - name: test + image: bitnami/kubectl:1.34.5 + command: ["/bin/sh", "-c"] + args: + - | + # Get a pod belonging to this release and annotate it, then verify + kubectl annotate --overwrite pod "$HOSTNAME" -n "{{ .Release.Namespace }}" last-used="$(date +%s)" + kubectl get pod "$HOSTNAME" -n "{{ .Release.Namespace }}" \ + -o jsonpath='{.metadata.annotations.last-used}' | grep -q . + restartPolicy: Never From 887543b34031b713733ab497b38e37b063e8a2c7 Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Wed, 1 Apr 2026 14:30:51 +0000 Subject: [PATCH 02/13] changing version so it publishes a chart --- helm/blueapi/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/blueapi/Chart.yaml b/helm/blueapi/Chart.yaml index 08097921fb..a82222806c 100644 --- a/helm/blueapi/Chart.yaml +++ b/helm/blueapi/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number is incremented by the release process. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.0 +version: 1.12.3 # This is the version number of the application being deployed. This version number is incremented by the release process. # Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using. From e014ae2c520944f58a9ea96d01b7213db36de81e Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Wed, 1 Apr 2026 14:47:49 +0000 Subject: [PATCH 03/13] updating tag. --- helm/blueapi/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/blueapi/Chart.yaml b/helm/blueapi/Chart.yaml index a82222806c..958bc197b7 100644 --- a/helm/blueapi/Chart.yaml +++ b/helm/blueapi/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number is incremented by the release process. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.12.3 +version: 1.12.4 # This is the version number of the application being deployed. This version number is incremented by the release process. # Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using. From eef07a9d2e3821db3acaf47a890c5d748e21038d Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Wed, 1 Apr 2026 15:33:19 +0000 Subject: [PATCH 04/13] updating appversion --- helm/blueapi/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/blueapi/Chart.yaml b/helm/blueapi/Chart.yaml index 958bc197b7..e557932b26 100644 --- a/helm/blueapi/Chart.yaml +++ b/helm/blueapi/Chart.yaml @@ -20,4 +20,4 @@ version: 1.12.4 # This is the version number of the application being deployed. This version number is incremented by the release process. # Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "0.1.0" +appVersion: "1.12.4" From 3484be19206d10952b0c793ac95a65231f367579 Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Wed, 1 Apr 2026 15:34:52 +0000 Subject: [PATCH 05/13] update chart --- helm/blueapi/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/blueapi/Chart.yaml b/helm/blueapi/Chart.yaml index e557932b26..5600bbc353 100644 --- a/helm/blueapi/Chart.yaml +++ b/helm/blueapi/Chart.yaml @@ -20,4 +20,4 @@ version: 1.12.4 # This is the version number of the application being deployed. This version number is incremented by the release process. # Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "1.12.4" +appVersion: "1.12.2" From c1703597f5d7c877c083f4dce23acce79ef96d14 Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Wed, 1 Apr 2026 16:06:15 +0000 Subject: [PATCH 06/13] reverting app version for tests --- helm/blueapi/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/blueapi/Chart.yaml b/helm/blueapi/Chart.yaml index 5600bbc353..958bc197b7 100644 --- a/helm/blueapi/Chart.yaml +++ b/helm/blueapi/Chart.yaml @@ -20,4 +20,4 @@ version: 1.12.4 # This is the version number of the application being deployed. This version number is incremented by the release process. # Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "1.12.2" +appVersion: "0.1.0" From c4f9f1a4c0777568dadababd9d134a18d03207ae Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Thu, 2 Apr 2026 07:58:51 +0000 Subject: [PATCH 07/13] updating cronjob version --- helm/blueapi/templates/cronjob.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/blueapi/templates/cronjob.yaml b/helm/blueapi/templates/cronjob.yaml index d1ff9bf325..438eb83a5a 100644 --- a/helm/blueapi/templates/cronjob.yaml +++ b/helm/blueapi/templates/cronjob.yaml @@ -54,7 +54,7 @@ spec: {{- end }} containers: - name: last-used-stamper - image: bitnami/kubectl:1.34.5 + image: bitnami/kubectl:1.31.1 imagePullPolicy: IfNotPresent command: - /bin/sh From 13d6101204d9694dd9a88fc9a9909a5f234542c6 Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Thu, 2 Apr 2026 08:06:50 +0000 Subject: [PATCH 08/13] updating chart --- helm/blueapi/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/blueapi/Chart.yaml b/helm/blueapi/Chart.yaml index 958bc197b7..5262df2133 100644 --- a/helm/blueapi/Chart.yaml +++ b/helm/blueapi/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number is incremented by the release process. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.12.4 +version: 1.12.2 # This is the version number of the application being deployed. This version number is incremented by the release process. # Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using. From 74cd4d3ff4761a8c78997fea24d49a6e7decf130 Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Thu, 2 Apr 2026 09:16:00 +0000 Subject: [PATCH 09/13] setting to latest --- helm/blueapi/templates/cronjob.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/blueapi/templates/cronjob.yaml b/helm/blueapi/templates/cronjob.yaml index 438eb83a5a..228ae2e1a0 100644 --- a/helm/blueapi/templates/cronjob.yaml +++ b/helm/blueapi/templates/cronjob.yaml @@ -54,7 +54,7 @@ spec: {{- end }} containers: - name: last-used-stamper - image: bitnami/kubectl:1.31.1 + image: bitnami/kubectl:latest imagePullPolicy: IfNotPresent command: - /bin/sh From 078caee91480344f6a3112bbd185a2a0d40f4434 Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Thu, 2 Apr 2026 10:23:43 +0000 Subject: [PATCH 10/13] updating the script --- helm/blueapi/templates/cronjob.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/helm/blueapi/templates/cronjob.yaml b/helm/blueapi/templates/cronjob.yaml index 228ae2e1a0..de25f7c549 100644 --- a/helm/blueapi/templates/cronjob.yaml +++ b/helm/blueapi/templates/cronjob.yaml @@ -61,8 +61,9 @@ spec: - -c - | # Get PVCs belonging to this blueapi release - ALL_PVC=$(kubectl get pvc -l "argocd.argoproj.io/instance={{ .Release.Name }}" \ - -o jsonpath='{.items[*].metadata.name}' -n {{ .Release.Namespace }} | tr ' ' '\n') + ALL_PVC=$(kubectl get pvc -n {{ .Release.Namespace }} \ + -o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | \ + grep "^{{ .Release.Name }}-scratch-") # Get all PVCs currently mounted by running pods MOUNTED_PVCS=$(kubectl get pods -n {{ .Release.Namespace }} \ -o=jsonpath='{.items[*].spec.volumes[*].persistentVolumeClaim.claimName}' | tr ' ' '\n' | sort -u) From f60c11b6f8652d5c7ac4708a345de41a1ce3fc47 Mon Sep 17 00:00:00 2001 From: alexj9837 Date: Thu, 2 Apr 2026 10:51:34 +0000 Subject: [PATCH 11/13] updating the chart --- helm/blueapi/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/blueapi/Chart.yaml b/helm/blueapi/Chart.yaml index 5262df2133..ac21970cff 100644 --- a/helm/blueapi/Chart.yaml +++ b/helm/blueapi/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number is incremented by the release process. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.12.2 +version: 1.12.7 # This is the version number of the application being deployed. This version number is incremented by the release process. # Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using. From fb418aad37643278451bf14f25dae349b691f529 Mon Sep 17 00:00:00 2001 From: Alex J Date: Tue, 7 Apr 2026 14:44:01 +0100 Subject: [PATCH 12/13] 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 --- helm/blueapi/Chart.yaml | 2 +- helm/blueapi/templates/configmap.yaml | 27 +++++++++++++++++++++- helm/blueapi/templates/cronjob.yaml | 33 +++++++++++---------------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/helm/blueapi/Chart.yaml b/helm/blueapi/Chart.yaml index ac21970cff..039e2d0d31 100644 --- a/helm/blueapi/Chart.yaml +++ b/helm/blueapi/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number is incremented by the release process. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.12.7 +version: 1.12.9 # This is the version number of the application being deployed. This version number is incremented by the release process. # Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using. diff --git a/helm/blueapi/templates/configmap.yaml b/helm/blueapi/templates/configmap.yaml index aa813e6485..15cfbc4d67 100644 --- a/helm/blueapi/templates/configmap.yaml +++ b/helm/blueapi/templates/configmap.yaml @@ -31,6 +31,31 @@ data: init_config.yaml: |- scratch: {{- toYaml .Values.worker.scratch | nindent 6 }} + +--- {{- end }} ---- +apiVersion: v1 +kind: ConfigMap +metadata: + name : {{include "blueapi.fullname" . }}-pvc-stamper-script +data: + time-stamper.sh: | + #!/bin/sh + # Get PVCs belonging to this blueapi release + ALL_PVC=$(kubectl get pvc -n {{ .Release.Namespace }} \ + -o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | \ + grep "^{{ .Release.Name }}-scratch-") + # Get all PVCs currently mounted by running pods + MOUNTED_PVCS=$(kubectl get pods -n {{ .Release.Namespace }} \ + -o=jsonpath='{.items[*].spec.volumes[*].persistentVolumeClaim.claimName}' | tr ' ' '\n' | sort -u) + NOW=$(date +%s) + #loop through all the pvcs annotating ones thare are mounted or lack a last-used stamp + for pvc in $ALL_PVC; do + ANNOTATION=$(kubectl get pvc "$pvc" -n {{ .Release.Namespace }} -o=jsonpath='{.metadata.annotations.last-used}') + if [ -z "$ANNOTATION" ]; then + kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW" + elif echo "$MOUNTED_PVCS" | grep -qx "$pvc"; then + kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW" + fi + done diff --git a/helm/blueapi/templates/cronjob.yaml b/helm/blueapi/templates/cronjob.yaml index de25f7c549..ab4b7a225c 100644 --- a/helm/blueapi/templates/cronjob.yaml +++ b/helm/blueapi/templates/cronjob.yaml @@ -39,6 +39,7 @@ spec: successfulJobsHistoryLimit: 3 failedJobsHistoryLimit: 1 schedule: "*/5 * * * *" + jobTemplate: spec: # amount of attempts of labeling a pvc @@ -52,28 +53,20 @@ spec: tolerations: {{- toYaml . | nindent 12 }} {{- end }} + + volumes: + - name : {{include "blueapi.fullname" . }}-pvc-stamper-script + configMap: + name: {{include "blueapi.fullname" . }}-pvc-stamper-script + defaultMode: 0500 + + containers: - name: last-used-stamper + volumeMounts: + - name: {{include "blueapi.fullname" . }}-pvc-stamper-script + mountPath: /scripts image: bitnami/kubectl:latest imagePullPolicy: IfNotPresent - command: - - /bin/sh - - -c - - | - # Get PVCs belonging to this blueapi release - ALL_PVC=$(kubectl get pvc -n {{ .Release.Namespace }} \ - -o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | \ - grep "^{{ .Release.Name }}-scratch-") - # Get all PVCs currently mounted by running pods - MOUNTED_PVCS=$(kubectl get pods -n {{ .Release.Namespace }} \ - -o=jsonpath='{.items[*].spec.volumes[*].persistentVolumeClaim.claimName}' | tr ' ' '\n' | sort -u) - NOW=$(date +%s) - for pvc in $ALL_PVC; do - ANNOTATION=$(kubectl get pvc "$pvc" -n {{ .Release.Namespace }} -o=jsonpath='{.metadata.annotations.last-used}') - if [ -z "$ANNOTATION" ]; then - kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW" - elif echo "$MOUNTED_PVCS" | grep -qx "$pvc"; then - kubectl annotate --overwrite pvc "$pvc" -n {{ .Release.Namespace }} last-used="$NOW" - fi - done + command: ["/scripts/time-stamper.sh"] restartPolicy: OnFailure From e80b4afe10cf54f6fb06d9b7b646d49ea912062b Mon Sep 17 00:00:00 2001 From: Alex J Date: Tue, 7 Apr 2026 15:40:34 +0100 Subject: [PATCH 13/13] fix: Last used stamper (#6) * 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 * changing default mode as hitting perm errors * update chart version --- helm/blueapi/Chart.yaml | 2 +- helm/blueapi/templates/cronjob.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm/blueapi/Chart.yaml b/helm/blueapi/Chart.yaml index 039e2d0d31..385f69f9d1 100644 --- a/helm/blueapi/Chart.yaml +++ b/helm/blueapi/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number is incremented by the release process. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.12.9 +version: 1.13.0 # This is the version number of the application being deployed. This version number is incremented by the release process. # Versions are not expected to follow Semantic Versioning. They should reflect the version the application is using. diff --git a/helm/blueapi/templates/cronjob.yaml b/helm/blueapi/templates/cronjob.yaml index ab4b7a225c..0860467d73 100644 --- a/helm/blueapi/templates/cronjob.yaml +++ b/helm/blueapi/templates/cronjob.yaml @@ -43,7 +43,7 @@ spec: jobTemplate: spec: # amount of attempts of labeling a pvc - backoffLimit: 2 + backoffLimit: 0 # job stops after 60 secounds activeDeadlineSeconds: 60 template: @@ -58,7 +58,7 @@ spec: - name : {{include "blueapi.fullname" . }}-pvc-stamper-script configMap: name: {{include "blueapi.fullname" . }}-pvc-stamper-script - defaultMode: 0500 + defaultMode: 0555 containers: