Skip to content

Commit

Permalink
feat(helm): add s3 bucket retention job
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Terrizzi authored and bsctl committed Dec 14, 2022
1 parent 6a6c9a3 commit f44980c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
56 changes: 56 additions & 0 deletions charts/kamaji-etcd/templates/etcd_job_s3retention.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{- if .Values.backup.enabled -}}
{{- if .Values.backup.s3.retention -}}
apiVersion: batch/v1
kind: Job
metadata:
labels:
{{- include "etcd.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": post-install,post-upgrade,post-rollback
"helm.sh/hook-weight": "5"
"helm.sh/hook-delete-policy": "hook-succeeded,hook-failed"
name: "{{ .Release.Name }}-s3-retention"
namespace: {{ .Release.Namespace }}
spec:
template:
metadata:
name: "{{ .Release.Name }}"
spec:
serviceAccountName: {{ include "etcd.serviceAccountName" . }}
restartPolicy: OnFailure
containers:
- name: minio-client
image: {{ include "minio-client.fullyQualifiedDockerImage" . }}
imagePullPolicy: {{ .Values.backup.s3.image.pullPolicy }}
command:
- bash
- -c
- |-
cd ${MC_CONFIG_DIR}
if $MC alias set myminio {{ .Values.backup.s3.url }} {{ .Values.backup.s3.accessKey }} {{ .Values.backup.s3.secretKey }} \
&& $MC ping myminio -c 3 -e 3 ; then
echo -e "\nCheck for already created object lifecycle management rule(s):"
if $MC ilm ls myminio/{{ .Values.backup.s3.bucket }} ; then
echo -e "\nObject lifecycle management rule(s) found - Clean up:"
$MC ilm rm --all --force myminio/{{ .Values.backup.s3.bucket }}
else
echo -e "\nNo object lifecycle management rule(s) found - Continue"
fi
echo -e "\nAdding object lifecycle management rule(s):"
$MC ilm add {{ .Values.backup.s3.retention }} myminio/{{ .Values.backup.s3.bucket }}
$MC ilm ls myminio/{{ .Values.backup.s3.bucket }}
else
echo -e "\nERROR: S3 storage could not be configured;\nCheck your S3 URL/Credentials or network connectivity"
exit 1
fi
env:
- name: MC_CONFIG_DIR
value: /tmp
- name: MC
value: "/usr/bin/mc --config-dir ${MC_CONFIG_DIR}"
securityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions charts/kamaji-etcd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ backup:
url: http://mys3storage:9000
# -- The S3 storage bucket
bucket: mybucket
# -- The S3 storage object lifecycle management rules
retention: "" #"--expiry-days 7"
# -- The S3 storage ACCESS KEY credential
accessKey: minio
# -- The S3 storage SECRET KEY credential
Expand Down

0 comments on commit f44980c

Please sign in to comment.