Merge pull request #1602 from Poor12/add-post-delete-job

Remove remaining resource when using helm uninstall
This commit is contained in:
karmada-bot 2022-04-14 09:13:56 +08:00 committed by GitHub
commit 9d3a6969c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 0 deletions

View File

@ -41,6 +41,14 @@ $ helm uninstall karmada -n karmada-system
```
The command removes all the Kubernetes components associated with the chart and deletes the release.
> **Note**: There are some RBAC resources that are used by the `preJob` that can not be deleted by the `uninstall` command above. You might have to clean them manually with tools like `kubectl`. You can clean them by commands:
```console
$ kubectl delete sa/karmada-pre-job -nkarmada-system
$ kubectl delete clusterRole/karmada-pre-job
$ kubectl delete clusterRoleBinding/karmada-pre-job
$ kubectl delete ns karmada-system
```
## Example
### 1. Install agent

View File

@ -0,0 +1,48 @@
{{- if and (eq .Values.installMode "host") (eq .Values.certs.mode "auto") }}
{{- $name := include "karmada.name" . -}}
{{- $namespace := include "karmada.namespace" . -}}
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ $name }}-post-delete"
namespace: {{ $namespace }}
labels:
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
parallelism: 1
completions: 1
template:
metadata:
name: {{ $name }}
labels:
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
serviceAccountName: {{ $name }}-pre-job
restartPolicy: Never
containers:
- name: post-delete
image: {{ .Values.postDeleteJob.postDeleteContainerImage }}
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- |
bash <<'EOF'
set -ex
kubectl delete -f /opt/mount/
kubectl delete cm/{{ $name }}-config -n {{ $namespace }}
EOF
volumeMounts:
- name: mount
mountPath: /opt/mount
volumes:
- name: mount
configMap:
name: {{ $name }}-config
{{- end }}

View File

@ -26,6 +26,10 @@ preInstallJob:
postInstallJob:
postInstallContainerImage: bitnami/kubectl:latest
## post-delete job config
postDeleteJob:
postDeleteContainerImage: bitnami/kubectl:latest
## karmada certificate config
certs:
## @param certs.mode "auto" and "custom" are provided