-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 502: Pravega Operator pre-delete hook
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.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
charts/pravega-operator/templates/pre-delete-hooks.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |