From f41b562cee07b67f1d01378d5eb23042f747331b Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Mon, 10 Oct 2022 17:59:08 +0200 Subject: [PATCH] feat(common): add improved handling of CRD updates (#250) * feat(common): add improved handling of CRD updates * actaullyadd the code * fix --- charts/common/Chart.yaml | 2 +- .../templates/lib/util/_crd-updater.tpl | 86 +++++++++++++++++++ charts/common/templates/loader/_apply.tpl | 2 + charts/common/values.yaml | 8 +- 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 charts/common/templates/lib/util/_crd-updater.tpl diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml index b50065d3..5478ff1a 100644 --- a/charts/common/Chart.yaml +++ b/charts/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 10.6.12 +version: 10.7.0 diff --git a/charts/common/templates/lib/util/_crd-updater.tpl b/charts/common/templates/lib/util/_crd-updater.tpl new file mode 100644 index 00000000..9e1cb3a5 --- /dev/null +++ b/charts/common/templates/lib/util/_crd-updater.tpl @@ -0,0 +1,86 @@ +{{- define "tc.common.lib.util.crd.update" -}} +{{- $fullName := include "tc.common.names.fullname" . -}} +{{- if .Values.updateCRD }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: {{ .Release.Namespace }} + name: {{ $fullName }}-crds + annotations: + "helm.sh/hook": pre-install, pre-upgrade + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation +data: +{{- range $path, $bytes := .Files.Glob "crds/*.yaml" }} + {{ $path | trimPrefix "crds/" }}: {{ $.Files.Get $path | quote }} +{{- end }} +--- +apiVersion: batch/v1 +kind: Job +metadata: + namespace: {{ .Release.Namespace }} + name: {{ $fullName }}-crds + annotations: + "helm.sh/hook": pre-install, pre-upgrade + "helm.sh/hook-weight": "-4" + "helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation +spec: + template: + spec: + serviceAccountName: {{ $fullName }}-crds + containers: + - name: {{ $fullName }}-crds + image: {{ .Values.kubectlImage }} + volumeMounts: + - name: crds + mountPath: /etc/crds + readOnly: true + command: ["kubectl", "apply", "-f", "/etc/crds"] + volumes: + - name: {{ $fullName }}-crds + configMap: + name: {{ $fullName }}-crds + restartPolicy: OnFailure +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ $fullName }}-crds + annotations: + "helm.sh/hook": pre-install, pre-upgrade + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation +rules: + - apiGroups: ["apiextensions.k8s.io"] + resources: ["customresourcedefinitions"] + verbs: ["create", "get", "list", "watch", "patch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ $fullName }}-crds + annotations: + "helm.sh/hook": pre-install, pre-upgrade + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ $fullName }}-crds +subjects: + - kind: ServiceAccount + name: {{ $fullName }}-crds + namespace: {{ .Release.Namespace }} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ $fullName }}-crds + namespace: {{ .Release.Namespace }} + annotations: + "helm.sh/hook": pre-install, pre-upgrade + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation +{{- end }} +{{- end -}} diff --git a/charts/common/templates/loader/_apply.tpl b/charts/common/templates/loader/_apply.tpl index e8634da9..e0f7b8c4 100644 --- a/charts/common/templates/loader/_apply.tpl +++ b/charts/common/templates/loader/_apply.tpl @@ -59,4 +59,6 @@ Secondary entrypoint and primary loader for the common chart {{ include "tc.common.scale.portal" . | nindent 0 }} {{ include "tc.common.spawner.networkpolicy" . | nindent 0 }} + + {{ include "tc.common.lib.util.crd.update" . | nindent 0 }} {{- end -}} diff --git a/charts/common/values.yaml b/charts/common/values.yaml index 93556d40..1634964f 100644 --- a/charts/common/values.yaml +++ b/charts/common/values.yaml @@ -132,7 +132,6 @@ image: # -- Image Selector allows for easy picking a different image dict, important for the SCALE GUI imageSelector: "image" - # -- Override the command(s) for the default container command: [] @@ -143,6 +142,13 @@ args: [] # Primarily for the SCALE GUI extraArgs: [] +# -- update the CRD's on helm update +# This does NOT include CRD's of dependencies. +# enabled by default for optimal performance on TrueNAS SCALE +# DEVNOTE: Also slightly alteres the install logic in a non breaking way +# DEVNOTE 2: Disabled for now so we can test on a limited number of charts initially +updateCRD: false + # -- Set Container Timezone TZ: UTC