Skip to content

Commit 576bf8f

Browse files
committed
chore: add volume snapshot crd check
1 parent 89a8716 commit 576bf8f

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

deploy/helm/templates/_helpers.tpl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,47 @@ Define the replica count for kubeblocks.
234234
{{- end }}
235235
{{- end }}
236236

237+
{{/*
238+
Validate optional installation preconditions.
239+
*/}}
240+
{{- define "kubeblocks.installationChecks" -}}
241+
{{- if and .Values.installationChecks.kubeblocksCRDs.enabled (ne .Release.Name "test-release") -}}
242+
{{- $requiredKubeBlocksCRDs := list
243+
"clusters.apps.kubeblocks.io"
244+
"componentdefinitions.apps.kubeblocks.io"
245+
"components.apps.kubeblocks.io"
246+
"instancesets.workloads.kubeblocks.io"
247+
"opsrequests.operations.kubeblocks.io"
248+
"addons.extensions.kubeblocks.io"
249+
-}}
250+
{{- $missingKubeBlocksCRDs := list -}}
251+
{{- range $requiredKubeBlocksCRDs -}}
252+
{{- if not (lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" "" .) -}}
253+
{{- $missingKubeBlocksCRDs = append $missingKubeBlocksCRDs . -}}
254+
{{- end -}}
255+
{{- end -}}
256+
{{- if $missingKubeBlocksCRDs -}}
257+
{{- fail (printf "\nKubeBlocks CRD check failed.\n\nMissing required CRDs:\n- %s\n\nInstall the KubeBlocks CRDs first:\n kubectl apply -f deploy/helm/crds\n\nTo skip this check, set:\n --set installationChecks.kubeblocksCRDs.enabled=false" (join "\n- " $missingKubeBlocksCRDs)) -}}
258+
{{- end -}}
259+
{{- end -}}
260+
{{- if and .Values.installationChecks.volumeSnapshotCRDs (ne .Release.Name "test-release") -}}
261+
{{- $requiredAPIs := list
262+
(dict "api" "snapshot.storage.k8s.io/v1/VolumeSnapshotClass" "crd" "volumesnapshotclasses.snapshot.storage.k8s.io")
263+
(dict "api" "snapshot.storage.k8s.io/v1/VolumeSnapshot" "crd" "volumesnapshots.snapshot.storage.k8s.io")
264+
(dict "api" "snapshot.storage.k8s.io/v1/VolumeSnapshotContent" "crd" "volumesnapshotcontents.snapshot.storage.k8s.io")
265+
-}}
266+
{{- $missingCRDs := list -}}
267+
{{- range $requiredAPIs -}}
268+
{{- if not ($.Capabilities.APIVersions.Has .api) -}}
269+
{{- $missingCRDs = append $missingCRDs .crd -}}
270+
{{- end -}}
271+
{{- end -}}
272+
{{- if $missingCRDs -}}
273+
{{- fail (printf "\nVolumeSnapshot CRD check failed.\n\nMissing required CRDs:\n- %s\n\nInstall the CSI snapshot CRDs first:\n kubectl apply -k https://github.com/kubernetes-csi/external-snapshotter/client/config/crd\n\nTo skip this check, set:\n --set installationChecks.volumeSnapshotCRDs=false" (join "\n- " $missingCRDs)) -}}
274+
{{- end -}}
275+
{{- end -}}
276+
{{- end -}}
277+
237278
{{- define "kubeblocks.i18nResourcesName" -}}
238279
{{ include "kubeblocks.fullname" . }}-i18n-resources
239280
{{- end }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{- include "kubeblocks.installationChecks" . -}}

deploy/helm/values.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ client:
4141
# default is 256
4242
burst: ""
4343

44+
## Installation checks.
45+
##
46+
## @param installationChecks.kubeblocksCRDs.enabled - fail installation when required KubeBlocks core CRDs are unavailable.
47+
## @param installationChecks.volumeSnapshotCRDs - fail installation when required VolumeSnapshot CRDs are unavailable.
48+
installationChecks:
49+
kubeblocksCRDs:
50+
enabled: true
51+
volumeSnapshotCRDs: true
52+
4453
## @param nameOverride
4554
##
4655
nameOverride: ""

0 commit comments

Comments
 (0)