# Kubernetes template rendering doesn't work second time

**URL:** <https://discuss.kubernetes.io/t/kubernetes-template-rendering-doesnt-work-second-time/18508>\
**Category:** General Discussions\
**Tags:** development, helm, kubernetes-custom-resources\
**Created:** [December 24, 2021, 12:01pm UTC](https://discuss.kubernetes.io/t/kubernetes-template-rendering-doesnt-work-second-time/18508 "2021-12-24T12:01:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sona\_sun](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/sona_sun/32/9197_2.png) [@sona\_sun](https://discuss.kubernetes.io/u/sona_sun)\
**Post date:** [December 24, 2021, 12:01pm UTC](https://discuss.kubernetes.io/t/kubernetes-template-rendering-doesnt-work-second-time/18508/1 "2021-12-24T12:01:15Z")

</div>

. [kubernetes template rendering doesn’t work second time](https://stackoverflow.com/questions/70471337/kubernetes-template-rendering-doesnt-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.

```auto
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

```auto
  {{- $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.

---

<div class="post-metadata">

**Author:** ![sona\_sun](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/sona_sun/32/9197_2.png) [@sona\_sun](https://discuss.kubernetes.io/u/sona_sun)\
**Post date:** [December 28, 2021, 7:13am UTC](https://discuss.kubernetes.io/t/kubernetes-template-rendering-doesnt-work-second-time/18508/2 "2021-12-28T07:13:09Z")

</div>

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

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

```
