Skip to content

Commit

Permalink
feat(chart): disable install of CRDs if they already exist
Browse files Browse the repository at this point in the history
Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih committed Mar 15, 2024
1 parent 970c350 commit 39126f4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions chart/charts/crds/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{/* vim: set filetype=mustache: */}}

{{/*
This returns a "1" if the CRD is absent in the cluster
Usage:
{{- if (include "crdIsAbsent" (list <crd-name>)) -}}
# CRD Yaml
{{- end -}}
*/}}
{{- define "crdIsAbsent" -}}
{{- $crdName := index . 0 -}}
{{- $crd := lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" "" $crdName -}}
{{- $output := "1" -}}
{{- if $crd -}}
{{- $output = "" -}}
{{- end -}}

{{- $output -}}
{{- end -}}
3 changes: 3 additions & 0 deletions chart/charts/crds/templates/csi-volume-snapshot-class.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- if and .Values.volumeSnapshots.enabled .Values.volumeSnapshots.snapshotClassesEnabled -}}
{{- $crdName := "volumesnapshotclasses.snapshot.storage.k8s.io" -}}
{{- if (include "crdIsAbsent" (list $crdName)) -}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -147,3 +149,4 @@ status:
conditions: []
storedVersions: []
{{- end -}}
{{- end -}}
3 changes: 3 additions & 0 deletions chart/charts/crds/templates/csi-volume-snapshot-content.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- if and .Values.volumeSnapshots.enabled .Values.volumeSnapshots.snapshotContentsEnabled -}}
{{- $crdName := "volumesnapshotcontents.snapshot.storage.k8s.io" -}}
{{- if (include "crdIsAbsent" (list $crdName)) -}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -485,3 +487,4 @@ status:
conditions: []
storedVersions: []
{{- end -}}
{{- end -}}
3 changes: 3 additions & 0 deletions chart/charts/crds/templates/csi-volume-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- if and .Values.volumeSnapshots.enabled .Values.volumeSnapshots.snapshotsEnabled -}}
{{- $crdName := "volumesnapshots.snapshot.storage.k8s.io" -}}
{{- if (include "crdIsAbsent" (list $crdName)) -}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -387,3 +389,4 @@ status:
conditions: []
storedVersions: []
{{- end -}}
{{- end -}}
3 changes: 3 additions & 0 deletions chart/charts/crds/templates/jaeger.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- if .Values.jaeger.enabled -}}
{{- $crdName := "jaegers.jaegertracing.io" -}}
{{- if (include "crdIsAbsent" (list $crdName)) -}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -44,3 +46,4 @@ spec:
subresources:
status: {}
{{- end -}}
{{- end -}}

0 comments on commit 39126f4

Please sign in to comment.