Closed astraw99 closed 1 year ago
Thank you for asking this @astraw99 !
The issue here is that the value of config.yaml
entry is a string. To ytt its not a template, but just a string.
There are two approaches here; a discouraged and a recommended one. I will show you both.
First, you can use ytt's [text templating]() to render a string with variables.
I created a gist for your example. Try it on the playground.
#@ load("@ytt:data", "data")
apiVersion: v1
data:
#@yaml/text-templated-strings
config.yaml: |
cluster: (@= data.values.cluster.config @)
kind: ConfigMap
metadata:
name: my-cm
namespace: default
This works, but you are now responsible for rendering valid YAML.
The better approach here is to create a map which represents your config.yaml
and encode it as YAML.
I created a gist for your example. Try it on the playground.
#@ load("@ytt:data", "data")
#@ load("@ytt:yaml", "yaml")
#@ def config():
cluster: #@ data.values.cluster.config
#@ end
---
apiVersion: v1
data:
config.yaml: #@ yaml.encode(config())
kind: ConfigMap
metadata:
name: my-cm
namespace: default
Now, you don't need to worry about rendering a valid YAML string. The yaml
module takes care of that.
@astraw99 if you have more you'd like support, here... please reply to this issue and we'll reopen. Otherwise, we assume this has been answered (thanks again @mamachanko!)
What steps did you take: A configmap yaml was configed like this: configmap.yaml
data.yaml
Then do
ytt -f ./configmap.yaml --data-values-file ./data.yaml > ytt-demo.yaml
, just got:What happened: See above.
What did you expect: Variable in all K8s resources should be rendered consistently.
Anything else you would like to add: [Additional information that will assist in solving the issue.]
Environment:
ytt --version
): ytt version 0.43.0/etc/os-release
): Mac OS.