Skip to content

Commit 0c4068e

Browse files
fix: prune before transforming
1 parent 30bb1e9 commit 0c4068e

File tree

4 files changed

+110
-136
lines changed

4 files changed

+110
-136
lines changed

charts/common/templates/_render.tpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
{{- $base := tpl (index $.__common.resources $resourceName "defaults") (list $ $templateCtx) | fromYaml }}
3737
{{- $_ := (list $ $base $resource) | include "common.utils.deepMerge" }}
3838
{{- $result := $.__common.fcallResult }}
39+
{{/* We should prune before transforming */}}
40+
{{- $_ := (list $ $result) | include "common.utils.pruneOutput" }}
41+
{{- $prunedResult := $.__common.fcallResult }}
3942
{{- if hasKey (index $.__common.resources $resourceName) "transforms" }}
4043
{{- $transformsTpl := index $.__common.resources $resourceName "transforms" }}
41-
{{- $_ := tpl $transformsTpl (list $ $result) }}
44+
{{- $_ := tpl $transformsTpl (list $ $prunedResult) }}
4245
{{- $result = $.__common.fcallResult }}
4346
{{- end }}
44-
{{- $_ := (list $ $result) | include "common.utils.pruneOutput" }}
45-
{{- $prunedResult := $.__common.fcallResult }}
46-
{{ $prunedResult | toYaml }}
47+
{{ $result | toYaml }}
4748
---
4849
{{- end }}
4950
{{- end }}

charts/common/templates/functions/_utils.tpl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -395,24 +395,24 @@ Example:
395395
{{- $hasIndexKey := and (hasKey $pathObj "indexKey") (not (empty $pathObj.indexKey)) -}}
396396
{{- $defaults := index $pathObj "defaultFor" | default list -}}
397397
{{- range $key, $value := $current -}}
398-
{{/* We need deepCopy here to prevent reference sharing between list items */}}
399-
{{- $newObj := deepCopy $value -}}
400-
{{- if $hasIndexKey -}}
401-
{{/* Strip any suffix after @ from the key, the
402-
driver here is that often there is no single
403-
unique parameter to use as indexKey */}}
404-
{{- $baseKey := regexReplaceAll "@.*$" $key "" -}}
405-
{{- $_ := set $newObj $pathObj.indexKey $baseKey -}}
406-
{{/* Apply defaults if any exist */}}
407-
{{- if $hasDefaults -}}
408-
{{- range $defaultKey := $defaults -}}
409-
{{- if not (hasKey $newObj $defaultKey) -}}
410-
{{- $_ := set $newObj $defaultKey $baseKey -}}
411-
{{- end -}}
412-
{{- end -}}
413-
{{- end -}}
414-
{{- end -}}
415-
{{- $resultList = append $resultList $newObj -}}
398+
{{/* We need deepCopy here to prevent reference sharing between list items */}}
399+
{{- $newObj := deepCopy $value -}}
400+
{{- if $hasIndexKey -}}
401+
{{/* Strip any suffix after @ from the key, the
402+
driver here is that often there is no single
403+
unique parameter to use as indexKey */}}
404+
{{- $baseKey := regexReplaceAll "@.*$" $key "" -}}
405+
{{- $_ := set $newObj $pathObj.indexKey $baseKey -}}
406+
{{/* Apply defaults if any exist */}}
407+
{{- if $hasDefaults -}}
408+
{{- range $defaultKey := $defaults -}}
409+
{{- if not (hasKey $newObj $defaultKey) -}}
410+
{{- $_ := set $newObj $defaultKey $baseKey -}}
411+
{{- end -}}
412+
{{- end -}}
413+
{{- end -}}
414+
{{- end -}}
415+
{{- $resultList = append $resultList $newObj -}}
416416
{{- end -}}
417417
{{/* Direct mutation of parent */}}
418418
{{- $_ := set $parent $lastKey $resultList -}}

0 commit comments

Comments
 (0)