add post delete hook

This commit is contained in:
Stavros kois
2022-11-14 22:14:43 +02:00
parent ac116e7de4
commit fdfefd9bb5
2 changed files with 34 additions and 1 deletions

View File

@@ -44,7 +44,7 @@ questions:
group: Networking
schema:
type: boolean
default: false
default: true
- variable: dnsConfig
label: DNS Configuration

View File

@@ -0,0 +1,33 @@
{{ $values := (. | mustDeepCopy) }}
{{ $_ := set $values "common" (dict "nameSuffix" "wg-easy") }}
{{ $ip := .Values.wgeasy.client_address_range | replace "x" "0" }}
apiVersion: batch/v1
kind: Job
metadata:
name: post-delete-routes-wg-easy
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded
rollme: {{ randAlphaNum 5 | quote }}
spec:
template:
metadata:
name: post-delete-routes-wg-easy
spec:
restartPolicy: Never
containers:
- name: {{ .Chart.Name }}-post-delete-routes-wg-easy
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/bash
- -c
- |
echo "Deleting routes created by the app..."
netmask=$(ip route | grep {{ $ip }})
netmask=$(echo $netmask | grep -o -E '/.\d*')
netmask=${netmask#/}
echo "Matched routes to delete... {{ $ip }}/$netmask"
ip route del {{ $ip }}/$netmask || echo "Route deletion failed..."
echo "Routes deleted..."