Skip to content

Commit

Permalink
chore(bors): merge pull request #458
Browse files Browse the repository at this point in the history
458: feat(chart): prevent CRDs from being recycled r=tiagolobocastro a=cmontemuino

<!

Co-authored-by: cmontemuino <1761056+cmontemuino@users.noreply.github.com>
  • Loading branch information
mayastor-bors and cmontemuino committed Mar 27, 2024
2 parents 23092a3 + 4ab5529 commit 8edc783
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 29 deletions.
12 changes: 8 additions & 4 deletions chart/charts/crds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ A Helm chart that collects CustomResourceDefinitions (CRDs) from Mayastor.

## Values

| Key | Description | Default |
|:----|:------------|:--------|
| csi.&ZeroWidthSpace;volumeSnapshots.&ZeroWidthSpace;enabled | Install Volume Snapshot CRDs | `true` |
| jaeger.&ZeroWidthSpace;enabled | Install Jaeger CRDs | `true` |
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| csi.volumeSnapshots.annotations | object | `{}` | Annotations to be added to all CRDs |
| csi.volumeSnapshots.enabled | bool | `true` | Install Volume Snapshot CRDs |
| csi.volumeSnapshots.keep | bool | `true` | Keep CRDs on chart uninstall |
| jaeger.annotations | object | `{}` | Annotations to be added to all CRDs |
| jaeger.enabled | bool | `true` | Install Jaeger CRDs |
| jaeger.keep | bool | `true` | Keep CRDs on chart uninstall |

27 changes: 14 additions & 13 deletions chart/charts/crds/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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-name>)) -}}
# 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 -}}
{{- define "crds.extraAnnotations" -}}
{{- if .keep -}}
helm.sh/resource-policy: keep
{{ end }}
{{- with .annotations }}
{{- toYaml . }}
{{- end }}
{{- end -}}

4 changes: 1 addition & 3 deletions chart/charts/crds/templates/csi-volume-snapshot-class.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -149,4 +148,3 @@ status:
conditions: []
storedVersions: []
{{- end -}}
{{- end -}}
4 changes: 1 addition & 3 deletions chart/charts/crds/templates/csi-volume-snapshot-content.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -487,4 +486,3 @@ status:
conditions: []
storedVersions: []
{{- end -}}
{{- end -}}
4 changes: 1 addition & 3 deletions chart/charts/crds/templates/csi-volume-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -389,4 +388,3 @@ status:
conditions: []
storedVersions: []
{{- end -}}
{{- end -}}
7 changes: 4 additions & 3 deletions chart/charts/crds/templates/jaeger.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -46,4 +48,3 @@ spec:
subresources:
status: {}
{{- end -}}
{{- end -}}
13 changes: 13 additions & 0 deletions chart/charts/crds/values.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8edc783

Please sign in to comment.