Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The crds have been moved from the templates/ to crds/ folder. When helm upgrade is run, helm will delete the crds because they're no longer in the generated template. To prevent deletion, we patch the 2 CRDs with the "helm.sh/resource-policy": "keep". Helm will skip deletion of resources with these annotation. Also, converted the hooks to a job as helm kills the pod before kubectl exec is run. With job, helm waits until the pod is run and reaches completion. Signed-off-by: Anish Ramasekar <anish.ramasekar@gmail.com>
- Loading branch information
Showing
2 changed files
with
103 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
manifest_staging/charts/secrets-store-csi-driver/templates/keep-crds-upgrade-hook.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: {{ template "sscd.fullname" . }}-keep-crds | ||
{{ include "sscd.labels" . | indent 2 }} | ||
annotations: | ||
helm.sh/hook: pre-upgrade | ||
helm.sh/hook-delete-policy: "hook-succeeded,before-hook-creation" | ||
helm.sh/hook-weight: "2" | ||
rules: | ||
- apiGroups: ["apiextensions.k8s.io"] | ||
resources: ["customresourcedefinitions"] | ||
verbs: ["get", "patch"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: {{ template "sscd.fullname" . }}-keep-crds | ||
{{ include "sscd.labels" . | indent 2 }} | ||
annotations: | ||
helm.sh/hook: pre-upgrade | ||
helm.sh/hook-delete-policy: "hook-succeeded,before-hook-creation" | ||
helm.sh/hook-weight: "2" | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ template "sscd.fullname" . }}-keep-crds | ||
namespace: {{ .Release.Namespace }} | ||
roleRef: | ||
kind: ClusterRole | ||
name: {{ template "sscd.fullname" . }}-keep-crds | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ template "sscd.fullname" . }}-keep-crds | ||
namespace: {{ .Release.Namespace }} | ||
{{ include "sscd.labels" . | indent 2 }} | ||
annotations: | ||
helm.sh/hook: pre-upgrade | ||
helm.sh/hook-delete-policy: "hook-succeeded,before-hook-creation" | ||
helm.sh/hook-weight: "2" | ||
--- | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {{ template "sscd.fullname" . }}-keep-crds | ||
namespace: {{ .Release.Namespace }} | ||
{{ include "sscd.labels" . | indent 2 }} | ||
annotations: | ||
helm.sh/hook: pre-upgrade | ||
helm.sh/hook-weight: "2" | ||
helm.sh/hook-delete-policy: "hook-succeeded,before-hook-creation" | ||
spec: | ||
backoffLimit: 0 | ||
template: | ||
metadata: | ||
name: crds-keep | ||
spec: | ||
serviceAccountName: {{ template "sscd.fullname" . }}-keep-crds | ||
restartPolicy: Never | ||
containers: | ||
- name: crds-keep | ||
image: "{{ .Values.linux.crds.image.repository }}:{{ .Values.linux.crds.image.tag }}" | ||
args: | ||
- patch | ||
- crd | ||
- secretproviderclasses.secrets-store.csi.x-k8s.io | ||
- secretproviderclasspodstatuses.secrets-store.csi.x-k8s.io | ||
- -p | ||
- '{"metadata":{"annotations": {"helm.sh/resource-policy": "keep"}}}' | ||
imagePullPolicy: {{ .Values.linux.crds.image.pullPolicy }} | ||
nodeSelector: | ||
kubernetes.io/os: linux |