terratest icon indicating copy to clipboard operation
terratest copied to clipboard

Helm: Problem unmarshalling a yaml template with mutliple documents inside

Open JotaP opened this issue 3 years ago • 7 comments

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.

JotaP avatar Aug 24 '20 17:08 JotaP

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.

yorinasub17 avatar Aug 24 '20 19:08 yorinasub17

Ok, thanks for the info (I'll split the template for now).

JotaP avatar Aug 25 '20 09:08 JotaP

Thanks for follow up, but let's keep this open as a feature request to support this semantic.

yorinasub17 avatar Aug 25 '20 13:08 yorinasub17

Ok! ;)

JotaP avatar Aug 25 '20 14:08 JotaP

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

edify42 avatar May 26 '21 07:05 edify42

Any update on this or any workaround?

sabeer6870 avatar Apr 06 '23 17:04 sabeer6870

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?

Mo0rBy avatar Oct 02 '23 13:10 Mo0rBy