{{- /* do not update crds here, please update in /victoria-metrics-operator/crd.yaml */ -}}
{{- /* this is used to add "helm.sh/resource-policy: keep" annotation for each crd */ -}}
{{- /* see this pull request https://github.com/VictoriaMetrics/helm-charts/pull/771 for details */ -}}
{{- $ctx := dict "helm" . }}
{{- if and .Values.crds.plain (not .Values.crds.enabled) }}
  {{- fail "When CRDs are disabled (`crds.enabled: false`) you need to disable plain CRD rendering (`crds.plain: false`)" -}}
{{- end -}}
{{- if and (not .Values.crds.plain) .Values.crds.enabled }}
  {{- $files := .Files }}
  {{- $crds := $files.Get "crd.yaml" | splitList "---" }}
  {{- $annotations := mergeOverwrite ((include "vm-operator.crds.annotations" .) | fromYaml) .Values.crds.annotations -}}
  {{- $extra := dict "metadata" (dict "annotations" $annotations) -}}
  {{- range $crds }}
    {{- $crd := merge (fromYaml .) $extra }}
    {{- range $attrKey, $attrValue := $crd }}
      {{- $attrKey }}: {{ toJson $attrValue }}
      {{- printf "\n" -}}
    {{ end }}
    {{- print "\n---\n" }}
  {{- end }}
{{- end }}
