Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion helm/blueapi/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.
Expand Down
27 changes: 26 additions & 1 deletion helm/blueapi/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
72 changes: 72 additions & 0 deletions helm/blueapi/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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: 0
# job stops after 60 secounds
activeDeadlineSeconds: 60
template:
spec:
serviceAccountName: {{ include "blueapi.fullname" . }}-last-used-stamper
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}

volumes:
- name : {{include "blueapi.fullname" . }}-pvc-stamper-script
configMap:
name: {{include "blueapi.fullname" . }}-pvc-stamper-script
defaultMode: 0555


containers:
- name: last-used-stamper
volumeMounts:
- name: {{include "blueapi.fullname" . }}-pvc-stamper-script
mountPath: /scripts
image: bitnami/kubectl:latest
imagePullPolicy: IfNotPresent
command: ["/scripts/time-stamper.sh"]
restartPolicy: OnFailure
19 changes: 19 additions & 0 deletions helm/blueapi/templates/tests/test-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading