diff --git a/chart/charts/crds/README.md b/chart/charts/crds/README.md index 03e0fc568..8a704da86 100644 --- a/chart/charts/crds/README.md +++ b/chart/charts/crds/README.md @@ -6,6 +6,10 @@ A Helm chart that collects CustomResourceDefinitions (CRDs) from Mayastor. | Key | Description | Default | |:----|:------------|:--------| +| csi.​volumeSnapshots.​annotations | Annotations to be added to all CRDs |
{

}
| | csi.​volumeSnapshots.​enabled | Install Volume Snapshot CRDs | `true` | +| csi.​volumeSnapshots.​keep | Keep CRDs on chart uninstall | `true` | +| jaeger.​annotations | Annotations to be added to all CRDs |
{

}
| | jaeger.​enabled | Install Jaeger CRDs | `true` | +| jaeger.​keep | Keep CRDs on chart uninstall | `true` | diff --git a/chart/charts/crds/templates/_helpers.tpl b/chart/charts/crds/templates/_helpers.tpl index 6f667038b..d90113dcb 100644 --- a/chart/charts/crds/templates/_helpers.tpl +++ b/chart/charts/crds/templates/_helpers.tpl @@ -1,19 +1,20 @@ {{/* vim: set filetype=mustache: */}} {{/* - This returns a "1" if the CRD is absent in the cluster + Adds extra annotations to CRDs. This targets two scenarios: preventing CRD recycling in case + the chart is removed; and adding custom annotations. + NOTE: This function assumes the element `metadata.annotations` already exists. + Usage: - {{- if (include "crdIsAbsent" (list )) -}} - # CRD Yaml - {{- end -}} + {{- include "crds.extraAnnotations" .Values.csi.volumeSnapshots | nindent 4 }} */}} -{{- define "crdIsAbsent" -}} - {{- $crdName := index . 0 -}} - {{- $crd := lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" "" $crdName -}} - {{- $output := "1" -}} - {{- if $crd -}} - {{- $output = "" -}} - {{- end -}} - {{- $output -}} -{{- end -}} \ No newline at end of file +{{- define "crds.extraAnnotations" -}} +{{- if .keep -}} +helm.sh/resource-policy: keep +{{ end }} +{{- with .annotations }} + {{- toYaml . }} +{{- end }} +{{- end -}} + diff --git a/chart/charts/crds/templates/csi-volume-snapshot-class.yaml b/chart/charts/crds/templates/csi-volume-snapshot-class.yaml index a4d650cb3..c3695c5d1 100644 --- a/chart/charts/crds/templates/csi-volume-snapshot-class.yaml +++ b/chart/charts/crds/templates/csi-volume-snapshot-class.yaml @@ -1,12 +1,11 @@ {{- if .Values.csi.volumeSnapshots.enabled -}} -{{- $crdName := "volumesnapshotclasses.snapshot.storage.k8s.io" -}} -{{- if (include "crdIsAbsent" (list $crdName)) -}} apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: api-approved.kubernetes.io: https://github.com/kubernetes-csi/external-snapshotter/pull/814 controller-gen.kubebuilder.io/version: v0.11.3 + {{- include "crds.extraAnnotations" .Values.csi.volumeSnapshots | nindent 4 }} creationTimestamp: null name: volumesnapshotclasses.snapshot.storage.k8s.io spec: @@ -149,4 +148,3 @@ status: conditions: [] storedVersions: [] {{- end -}} -{{- end -}} diff --git a/chart/charts/crds/templates/csi-volume-snapshot-content.yaml b/chart/charts/crds/templates/csi-volume-snapshot-content.yaml index af6559f2b..a10c75af2 100644 --- a/chart/charts/crds/templates/csi-volume-snapshot-content.yaml +++ b/chart/charts/crds/templates/csi-volume-snapshot-content.yaml @@ -1,12 +1,11 @@ {{- if .Values.csi.volumeSnapshots.enabled -}} -{{- $crdName := "volumesnapshotcontents.snapshot.storage.k8s.io" -}} -{{- if (include "crdIsAbsent" (list $crdName)) -}} apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: api-approved.kubernetes.io: https://github.com/kubernetes-csi/external-snapshotter/pull/814 controller-gen.kubebuilder.io/version: v0.11.3 + {{- include "crds.extraAnnotations" .Values.csi.volumeSnapshots | nindent 4 }} creationTimestamp: null name: volumesnapshotcontents.snapshot.storage.k8s.io spec: @@ -487,4 +486,3 @@ status: conditions: [] storedVersions: [] {{- end -}} -{{- end -}} diff --git a/chart/charts/crds/templates/csi-volume-snapshot.yaml b/chart/charts/crds/templates/csi-volume-snapshot.yaml index 0152c6607..8a1168f16 100644 --- a/chart/charts/crds/templates/csi-volume-snapshot.yaml +++ b/chart/charts/crds/templates/csi-volume-snapshot.yaml @@ -1,12 +1,11 @@ {{- if .Values.csi.volumeSnapshots.enabled -}} -{{- $crdName := "volumesnapshots.snapshot.storage.k8s.io" -}} -{{- if (include "crdIsAbsent" (list $crdName)) -}} apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: api-approved.kubernetes.io: https://github.com/kubernetes-csi/external-snapshotter/pull/814 controller-gen.kubebuilder.io/version: v0.11.3 + {{- include "crds.extraAnnotations" .Values.csi.volumeSnapshots | nindent 4 }} creationTimestamp: null name: volumesnapshots.snapshot.storage.k8s.io spec: @@ -389,4 +388,3 @@ status: conditions: [] storedVersions: [] {{- end -}} -{{- end -}} diff --git a/chart/charts/crds/templates/jaeger.yaml b/chart/charts/crds/templates/jaeger.yaml index d34c2361e..68d025f6c 100644 --- a/chart/charts/crds/templates/jaeger.yaml +++ b/chart/charts/crds/templates/jaeger.yaml @@ -1,10 +1,12 @@ {{- if .Values.jaeger.enabled -}} -{{- $crdName := "jaegers.jaegertracing.io" -}} -{{- if (include "crdIsAbsent" (list $crdName)) -}} apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: jaegers.jaegertracing.io + {{- if or (.Values.jaeger.keep) (.Values.jaeger.annotations) }} + annotations: + {{- include "crds.extraAnnotations" .Values.jaeger | nindent 4 }} + {{- end }} labels: app: jaeger-operator spec: @@ -46,4 +48,3 @@ spec: subresources: status: {} {{- end -}} -{{- end -}} diff --git a/chart/charts/crds/values.yaml b/chart/charts/crds/values.yaml index 724652e16..fdda41f28 100644 --- a/chart/charts/crds/values.yaml +++ b/chart/charts/crds/values.yaml @@ -1,8 +1,21 @@ jaeger: # -- Install Jaeger CRDs enabled: true + # -- Keep CRDs on chart uninstall + keep: true + # -- Annotations to be added to all CRDs + annotations: {} + # Example for Argo CD to prevent CRDs from being recycled + # argocd.argoproj.io/sync-options: Prune=false csi: volumeSnapshots: # -- Install Volume Snapshot CRDs enabled: true + # -- Keep CRDs on chart uninstall + keep: true + # -- Annotations to be added to all CRDs + annotations: {} + # Example for Argo CD to prevent CRDs from being recycled + # argocd.argoproj.io/sync-options: Prune=false +