Kubernetes template rendering doesn't work second time

. kubernetes template rendering doesn’t work second time

I’ve two files ‘install-charts.sh’ and ‘MANIFEST’ which fill-in their data from same/common named template “input-generator.getReleasesByInstallSequence”. It takes in an aary of two values where first value is top level value and second is the current element being templated and returns a list.

This takes an array of two values:
- top-level values
- current element being templated
Returns releaseBatches
{{- define "input-generator.getReleasesByInstallSequence" -}}
{{- $top := index . 0 -}}
{{- $element := index . 1 -}}
{{- $releaseBatches := list }}

This template returns a list which has some chart details which are used by both install-charts.sh and MANIFEST file. This is how I’m saving the return list

  {{- $releaseBatches := get ((include "input-generator.getReleasesByInstallSequence" (tuple $ $element)) | fromYaml) "releaseBatches" }}

Both install-charts and MANIFEST are being yaml.safe_load(fileName) in a python script.

The issue is both rendering are not happening together. I mean anyone of either install-charts.sh or MANIFEST gets it’s data correct and other doesn’t get anything. Note: The code is fine and giving whatever data is required. Issue is it’s not giving data to both files when above template code is executed in each files. I’ve wasted two days but couldn’t find anything on this.

What I tried I try be making two templates but with different names but same signature and parameters then also the same issue as mentioned above.

The solution was pretty easy. It took me time to know it. It’s deepCopy which does the work. You can search about Python’s deepCopy which is same in kubernetes template function. So final solution becomes

{{- define "input-generator.getReleasesByInstallSequence" -}}
{{- $top := deepCopy (index . 0) -}}
{{- $element := index . 1 -}}
{{- $releaseBatches := list }}