Reassign a value in helm chart

Viewed 695

Following is the values.yaml in helm chart:

global:
  namespace: istio
chart-1:
  istioNamespace: istio
chart-2:
  targetNamespace: istio

Is there a way where istioNamespace and targetNamespace can refer global.namespace?

1 Answers

Since this is a YAML, you can make use of its anchor, aliases, merge keys to re-use the values/data.DIY.

In your case, you could do something like this: In the YAML Document, you can refer to a previously defined anchor with an alias

global:
  namespace: &ns "istio"
chart-1:
  istioNamespace: *ns
chart-2:
  targetNamespace: *ns

NOTE: if you try to override this with other values.yaml that might not work as expected. This is useful when you are doing it in the same YAML file.

Here is a reference link. and in official docs as well.

I have tried a few of them in my day to day works with helm charts, and they work pretty well with Values. yaml

Related