Files
kubesphere/config/ks-core/charts/ks-crds/templates/post-delete-crd-job.yaml
liujian 14bbc45531 fix: graceful delete ks-core (#6182)
* fix: graceful delete ks-core

Signed-off-by: joyceliu <joyceliu@yunify.com>

* fix: graceful delete ks-core

Signed-off-by: joyceliu <joyceliu@yunify.com>

---------

Signed-off-by: joyceliu <joyceliu@yunify.com>
Co-authored-by: joyceliu <joyceliu@yunify.com>
2024-09-19 18:45:10 +08:00

90 lines
2.5 KiB
YAML

{{- $kubeVersion := .Capabilities.KubeVersion }}
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Release.Name }}-post-delete-crd-scripts"
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "-3"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed
data:
map.yaml: |
mappings:
{{- range $path, $_ := .Files.Glob "crds/**" }}
{{- $crd := $.Files.Get $path | fromYaml }}
{{- range $_, $version := $crd.spec.versions }}
- deprecatedAPI: "apiVersion: {{ $crd.spec.group }}/{{ $version.name }}\nkind: {{ $crd.spec.names.kind }}\n"
removedInVersion: "{{ $kubeVersion }}"
{{- end }}
{{- end }}
{{ (.Files.Glob "scripts/post-delete.sh").AsConfig | indent 2 }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: "{{ .Release.Name }}-post-delete-crd"
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "-3"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: "{{ .Release.Name }}-post-delete-crd"
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "-3"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: "{{ .Release.Name }}-post-delete-crd"
namespace: {{ .Release.Namespace }}
---
{{- $crdNameList := list }}
{{- range $path, $_ := .Files.Glob "crds/**" }}
{{- $crd := $.Files.Get $path | fromYaml }}
{{- $crdNameList = append $crdNameList $crd.metadata.name }}
{{- end }}
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-post-delete-crd"
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "-2"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
spec:
restartPolicy: Never
serviceAccountName: "{{ .Release.Name }}-post-delete-crd"
containers:
- name: post-delete-job
image: {{ template "kubectl.image" . }}
command:
- /bin/bash
- /scripts/post-delete.sh
- '{{ join " " $crdNameList }}'
- /scripts/map.yaml
volumeMounts:
- mountPath: /scripts
name: scripts
resources: {{- toYaml .Values.kubectl.resources | nindent 12 }}
volumes:
- name: scripts
configMap:
name: "{{ .Release.Name }}-post-delete-crd-scripts"
defaultMode: 420