Skip to content

Commit

Permalink
Issue 502: Pravega Operator pre-delete hook
Browse files Browse the repository at this point in the history
Signed-off-by: SrishT <[email protected]>
  • Loading branch information
SrishT authored and SrishT committed Feb 5, 2021
1 parent 03fca50 commit a8d0546
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions charts/pravega-operator/templates/pre-delete-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: {{ template "pravega-operator.fullname" . }}-pre-delete
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed
rules:
- apiGroups:
- pravega.pravega.io
resources:
- "*"
verbs:
- get
- list
---

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: {{ template "pravega-operator.fullname" . }}-pre-delete
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed
subjects:
- kind: ServiceAccount
name: {{ template "pravega-operator.fullname" . }}-pre-delete
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: {{ template "pravega-operator.fullname" . }}-pre-delete
apiGroup: rbac.authorization.k8s.io

---

apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "pravega-operator.fullname" . }}-pre-delete
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed

---

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "pravega-operator.fullname" . }}-pre-delete
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed
data:
pre-delete.sh: |
#!/bin/sh
exit_code=0
echo "Checking for PravegaCluster Resource"
ret=$(kubectl get PravegaCluster --all-namespaces --no-headers 2>&1)
if (echo $ret | grep -e "No resources found" -e "the server doesn't have a resource type \"PravegaCluster\"" > /dev/null);
then
echo "None"
else
echo "$ret"
exit_code=1
fi
if [ $exit_code -ne 0 ];
then
echo "Pre-delete Check Failed"
exit $exit_code
fi
echo "Pre-delete Check OK"
---

apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "pravega-operator.fullname" . }}-pre-delete
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "2"
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed
spec:
backoffLimit: 1
activeDeadlineSeconds: 20
template:
metadata:
name: {{ template "pravega-operator.fullname" . }}-pre-delete
spec:
serviceAccountName: {{ template "pravega-operator.fullname" . }}-pre-delete
restartPolicy: Never
containers:
- name: pre-delete-job
image: "{{ .Values.hooks.image.repository }}:{{ .Values.hooks.image.tag }}"
command:
- /scripts/pre-delete.sh
volumeMounts:
- name: sh
mountPath: /scripts
readOnly: true
volumes:
- name: sh
configMap:
name: {{ template "pravega-operator.fullname" . }}-pre-delete
defaultMode: 0555

0 comments on commit a8d0546

Please sign in to comment.