Skip to content

Commit

Permalink
add helm hook to add manifest annotation
Browse files Browse the repository at this point in the history
Signed-off-by: KubeKyrie <shaolong.qin@daocloud.io>
  • Loading branch information
KubeKyrie committed Sep 2, 2024
1 parent ef75d62 commit 68ec2c7
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions charts/kubean/templates/prehook-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,70 @@ spec:
configMap:
name: {{ $name }}-pre-manifests
---
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ $name }}-pre-hook-add-manifest-annotation"
namespace: {{ $namespace }}
annotations:
# only for pre-upgrade and do not need this for pre-install
"helm.sh/hook": pre-upgrade
"helm.sh/hook-weight": "4"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
metadata:
name: {{ $name }}
labels:
app.kubernetes.io/instance: {{ $name | quote }}
spec:
serviceAccountName: {{ $name }}-pre-hook-job
restartPolicy: Never
containers:
- name: keep-manifest
image: {{ include "kubean.prehookImage" . }}
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- |
bash <<'EOF'
set -ex
kubectl annotate deployment.apps --all helm.sh/resource-policy=keep
EOF
---
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ $name }}-pre-hook-remove-manifest-annotation"
namespace: {{ $namespace }}
annotations:
# remove annotation so that manifest could be deleted by helm when uninstall kubean
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "4"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
metadata:
name: {{ $name }}
labels:
app.kubernetes.io/instance: {{ $name | quote }}
spec:
serviceAccountName: {{ $name }}-pre-hook-job
restartPolicy: Never
containers:
- name: remove-manifest-annotation
image: {{ include "kubean.prehookImage" . }}
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- |
bash <<'EOF'
set -ex
kubectl annotate manifest --all helm.sh/resource-policy-
EOF
---
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down

0 comments on commit 68ec2c7

Please sign in to comment.