Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add helm hook to add manifest annotation #1358

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 67 additions & 3 deletions charts/kubean/templates/prehook-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,77 @@ 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 manifest --all helm.sh/resource-policy=keep
EOF
---
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ $name }}-pre-hook-delete-all-manifest"
namespace: {{ $namespace }}
annotations:
# delete all manifests in pre-hook to avoid being kept due to the resource policy (helm.sh/resource-policy=keep).
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "3"
"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: delete-all-manifest
image: {{ include "kubean.prehookImage" . }}
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- |
bash <<'EOF'
set -ex
kubectl delete manifest --all
EOF
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ $name }}-pre-hook-job
namespace: {{ $namespace }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook": pre-install,pre-upgrade,pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
---
Expand All @@ -69,7 +133,7 @@ kind: ClusterRole
metadata:
name: {{ $name }}-pre-hook-job
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook": pre-install,pre-upgrade,pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
rules:
Expand All @@ -84,7 +148,7 @@ kind: ClusterRoleBinding
metadata:
name: {{ $name }}-pre-hook-job
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook": pre-install,pre-upgrade,pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
roleRef:
Expand Down
Loading