AVarf
AVarf

Reputation: 5149

How to pass the content of a file to Helm values.yaml

I want to use Helm chart of RabbitMQ to set up a cluster but when I try to pass the configuration files that we have at the moment to the values.yaml it doesn't work.

The command that I use:

helm install --dry-run --debug stable/rabbitmq --name testrmq --namespace rmq -f rabbit-values.yaml

rabbit-values.yaml:

rabbitmq:
  plugins: "rabbitmq_management rabbitmq_federation rabbitmq_federation_management rabbitmq_shovel rabbitmq_shovel_management rabbitmq_mqtt rabbitmq_web_stomp rabbitmq_peer_discovery_k8s"
  advancedConfiguration: |-
    {{ .Files.Get "rabbitmq.config" | quote}}

And what I get for advancedConfiguration:

NAME:   testrmq
REVISION: 1
RELEASED: Thu Aug 29 10:09:26 2019
CHART: rabbitmq-5.5.0
USER-SUPPLIED VALUES:
rabbitmq:
  advancedConfiguration: '{{ .Files.Get "rabbitmq.config" | quote}}'
  plugins: rabbitmq_management rabbitmq_federation rabbitmq_federation_management
    rabbitmq_shovel rabbitmq_shovel_management rabbitmq_mqtt rabbitmq_web_stomp rabbitmq_peer_discovery_k8s

I have to mention that:

Upvotes: 29

Views: 64530

Answers (2)

Max
Max

Reputation: 522

As this is google top result, here is some related issue with the solution:

I have some chart, that has a subchart as well as a config folder. I want to pass the content of the config folder down to the subchart, to be used as some file based configmap.

apiVersion: v1
kind: ConfigMap
...
data:
{{ if .Values.files}}
{{- range $k, $v := .Values.files }}
    {{ $k }}:
     {{ $v | indent 2}}
{{- end }}
{{end}}

and calling helm with this beauty:

helm ...  $(for i in $(ls config/); do echo --set-file mySubChart.files.${i//./\\.}=config/$i;done)"

Thanks to @Alfageme for the hint about the dot.

Upvotes: 1

David Maze
David Maze

Reputation: 158908

You can't use Helm templating in the values.yaml file. (Unless the chart author has specifically called the tpl function when the value is used; for this variable it doesn't, and that's usually called out in the chart documentation.)

Your two options are to directly embed the file content in the values.yaml file you're passing in, or to use the

helm install --dry-run --debug \
     stable/rabbitmq \
     --name testrmq \
     --namespace rmq \
     -f rabbit-values.yaml \
     --set-file rabbitmq.advancedConfig=rabbitmq.config

There isn't a way to put a file pointer inside your local values YAML file though.

Upvotes: 39

Related Questions