terratest
terratest copied to clipboard
Helm: Problem unmarshalling a yaml template with mutliple documents inside
Hello,
I'm trying to apply the provided helm examples with a template of my own. My yaml file has multiple documents inside separated with "---" to define different resources (service, deployment, etc.) and when using the UnmarshalK8SYaml
function (github.com/gruntwork-io/terratest/modules/helm), it only seems to pick the first document definition.
Any help would be much appreaciated.
Unfortunately, UnmarshalK8SYaml
is unable to unmarshal multiple documents at the moment due to the way the interface is setup. We'll need to update the function to add support for this by taking in a list of target objects, and figuring out a way to map the object stream to each output.
In the meantime, the best workaround is to split out to one template per object and rendering just that template.
Ok, thanks for the info (I'll split the template for now).
Thanks for follow up, but let's keep this open as a feature request to support this semantic.
Ok! ;)
We ran into this issue as well and had to split the yaml document with the ---
as the delimiter before processing each yaml doc
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/secrets.yaml"})
allRange := strings.Split(output, "---")
for i, rawOutput := range allRange[1:] {
var secret v1.Secret
helm.UnmarshalK8SYaml(t, rawOutput, &secret)
...
}
Would be nice to have a new function to handle the singular case of 1 type which is an array (e.g. var secret []v1.Secret{}
), but I think passing in many structs to be unmarshalled would be quite difficult to manage
Any update on this or any workaround?
I've just encountered this limitation. I used @edify42's suggestions with using string splitting and it works. Any updates on plans to include this feature?