Nikolay
Nikolay

Reputation: 33

Convert string to YAML map

In values.yaml I have another yaml config encoded to base64. In a template I decode it with

{{ $config := b64dec .Values.config }}

and I need to access it like a map, so what is needed is a kind of analogue of file AsConfig but for string.

Upvotes: 3

Views: 7660

Answers (1)

edbighead
edbighead

Reputation: 6334

You can use Helm's fromYaml function (haven't found any documentation besides this commit)

config.yaml which is encoded with cat config.yaml | base64

xxx: yyy
zzz: qqq

values.yaml

config: eHh4OiB5eXkKenp6OiBxcXEK

secret.yaml

{{ $config :=  (b64dec .Values.config) | fromYaml  }}
apiVersion: v1
kind: Secret
metadata:
  name: secret
type: Opaque
data:
  test: {{  $config.xxx }}

helm template

/mnt/c/home/chart> helm template .
---
# Source: chart/templates/secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: secret
type: Opaque
data:
  test: yyy

Upvotes: 6

Related Questions