0

I need to install the same helm Chart to different namespaces, so multiple times. The chart contains cluster scoped resources like ClusterRoles or CustomResourceDefinitions.

The problem is I can only install it once, the second time I have an "already exists not managed by helm" error.

What I've tried:

  • Putting CRDs in a separate folder, works well, except that I can't since my CRDs contain helm values and the crds folder doesn't accept templates.
  • Using something like this:
{{- $crds := lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" .Release.Namespace "path.to.new.crd" -}}
{{- if not $crds -}}
{{- end }}

But this isn't ideal either, because if I install the same helm to the same namespace twice, the resources get deleted, the third time they appear again, fourth they disappear, and so on.

Does anybody have a more elegant solution to this?

Reda Drissi
  • 1,532
  • 3
  • 20
  • 32
  • 1
    Is this publicly available chart, or did you atuhor it yourself? Can you share it? It's possible your only solution is to use separate charts for CRDs, following [Chart best practices](https://helm.sh/docs/chart_best_practices/custom_resource_definitions/#method-2-separate-charts) –  Oct 28 '21 at 12:58
  • When the primary way to install Istio was using Helm, for example, it had an "init chart" that contained only CRDs, and then the main infrastructure chart. – David Maze Oct 28 '21 at 13:07
  • keep the first resource created even with chart deleted ``` annotations: "helm.sh/resource-policy": keep ``` – Vasiliy Ratanov Aug 15 '22 at 16:08

1 Answers1

0

Keep the first resource created using "helm.sh/resource-policy": keep even when chart deleted

{{- $priorityClassExists := lookup "scheduling.k8s.io/v1" "PriorityClass" "" .Values.global.priority.high }}
{{- if not $priorityClassExists }}
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  annotations:
    "helm.sh/resource-policy": keep
  name: {{ .Values.global.priority.high }}
value: 1000000
globalDefault: false
description: "This priority class should be used for critical things only."
{{- end }}
Vasiliy Ratanov
  • 302
  • 1
  • 6