Skip to content

Commit 937bcad

Browse files
feat: improve performance
refactor: indent render
1 parent 0c4068e commit 937bcad

File tree

6 files changed

+198
-161
lines changed

6 files changed

+198
-161
lines changed

charts/common/initContainers/10-init-nodeport.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ command:
5555
echo "EXTERNAL_IP=$EXTERNAL_IP" >> /env/init-nodeport
5656
5757
# Process each port in the service
58-
echo "$SERVICE_PORTS" | jq -c '.[]' | while read -r port; do
58+
echo "$SERVICE_PORTS" | jq -c | while read -r port; do
5959
PORT_NAME=$(echo "$port" | jq -r '.name')
6060
NODE_PORT=$(echo "$port" | jq -r '.nodePort')
6161

charts/common/templates/_render.tpl

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
11
{{- define "common.render" }}
2-
{{- if $.Values.debug }}
3-
{{- include "common.init._init" $ }}
4-
{{- else }}
5-
{{- $_ := include "common.init._init" $ }}
6-
{{- end }}
7-
{{- $templateCtx := $.__common.config.templateCtx }}
8-
{{- range $component, $componentValues := $templateCtx.ComponentValues }}
9-
{{- if (default false $componentValues.__enabled) }}
10-
{{- $_ := set $templateCtx "Self" $componentValues }}
11-
{{- $_ := set $templateCtx "name" (printf "%s" $component) }}
12-
{{- range $resourceName, $keysData := $.__common.resourceKeysMap }}
13-
{{- $resourcesList := list }}
14-
{{- if hasKey $keysData "single" }}
15-
{{- range $resourceKey := $keysData.single }}
16-
{{- if hasKey $componentValues $resourceKey }}
17-
{{- $resource := index $componentValues $resourceKey }}
18-
{{- if and (hasKey $resource "__enabled") (eq $resource.__enabled true) }}
19-
{{- $resourcesList = append $resourcesList $resource }}
20-
{{- end }}
21-
{{- end }}
22-
{{- end }}
23-
{{- end }}
24-
{{- if hasKey $keysData "multiple" }}
25-
{{- range $resourceKey := $keysData.multiple }}
26-
{{- if hasKey $componentValues $resourceKey }}
27-
{{- range $resourceName, $resource := (index $componentValues $resourceKey) }}
28-
{{- if and (hasKey $resource "__enabled") (eq $resource.__enabled true) }}
29-
{{- $resourcesList = append $resourcesList $resource }}
30-
{{- end }}
31-
{{- end }}
32-
{{- end }}
33-
{{- end }}
34-
{{- end }}
35-
{{- range $resource := $resourcesList }}
36-
{{- $base := tpl (index $.__common.resources $resourceName "defaults") (list $ $templateCtx) | fromYaml }}
37-
{{- $_ := (list $ $base $resource) | include "common.utils.deepMerge" }}
38-
{{- $result := $.__common.fcallResult }}
39-
{{/* We should prune before transforming */}}
40-
{{- $_ := (list $ $result) | include "common.utils.pruneOutput" }}
41-
{{- $prunedResult := $.__common.fcallResult }}
42-
{{- if hasKey (index $.__common.resources $resourceName) "transforms" }}
43-
{{- $transformsTpl := index $.__common.resources $resourceName "transforms" }}
44-
{{- $_ := tpl $transformsTpl (list $ $prunedResult) }}
45-
{{- $result = $.__common.fcallResult }}
46-
{{- end }}
47-
{{ $result | toYaml }}
2+
{{- if $.Values.debug }}
3+
{{- include "common.init._init" $ }}
4+
{{- else }}
5+
{{- $_ := include "common.init._init" $ }}
6+
{{- end }}
7+
{{- $templateCtx := $.__common.config.templateCtx }}
8+
{{- range $component, $componentValues := $templateCtx.ComponentValues }}
9+
{{- if (default false $componentValues.__enabled) }}
10+
{{- $_ := set $templateCtx "Self" $componentValues }}
11+
{{- $_ := set $templateCtx "name" (printf "%s" $component) }}
12+
{{- range $resourceName, $keysData := $.__common.resourceKeysMap }}
13+
{{- $resourcesList := list }}
14+
{{- if hasKey $keysData "single" }}
15+
{{- range $resourceKey := $keysData.single }}
16+
{{- if hasKey $componentValues $resourceKey }}
17+
{{- $resource := index $componentValues $resourceKey }}
18+
{{- if and (hasKey $resource "__enabled") (eq $resource.__enabled true) }}
19+
{{- $resourcesList = append $resourcesList $resource }}
20+
{{- end }}
21+
{{- end }}
22+
{{- end }}
23+
{{- end }}
24+
{{- if hasKey $keysData "multiple" }}
25+
{{- range $resourceKey := $keysData.multiple }}
26+
{{- if hasKey $componentValues $resourceKey }}
27+
{{- range $resourceName, $resource := (index $componentValues $resourceKey) }}
28+
{{- if and (hasKey $resource "__enabled") (eq $resource.__enabled true) }}
29+
{{- $resourcesList = append $resourcesList $resource }}
30+
{{- end }}
31+
{{- end }}
32+
{{- end }}
33+
{{- end }}
34+
{{- end }}
35+
{{- range $resource := $resourcesList }}
36+
{{- $base := tpl (index $.__common.resources $resourceName "defaults") (list $ $templateCtx) | fromYaml }}
37+
{{- $_ := (list $ $base $resource) | include "common.utils.deepMerge" }}
38+
{{- $result := $.__common.fcallResult }}
39+
{{/* We should prune before transforming */}}
40+
{{- $_ := (list $ $result) | include "common.utils.pruneOutput" }}
41+
{{- $prunedResult := $.__common.fcallResult }}
42+
{{- if hasKey (index $.__common.resources $resourceName) "transforms" }}
43+
{{- $transformsTpl := index $.__common.resources $resourceName "transforms" }}
44+
{{- $_ := tpl $transformsTpl (list $ $prunedResult) }}
45+
{{- $result = $.__common.fcallResult }}
46+
{{- $_ := (list $ $result) | include "common.utils.pruneOutput" }}
47+
{{- $prunedResult = $.__common.fcallResult }}
48+
{{- end }}
49+
{{ $prunedResult | toYaml }}
4850
---
49-
{{- end }}
50-
{{- end }}
51-
{{- end }}
52-
{{- end }}
53-
51+
{{- end }}
52+
{{- end }}
53+
{{- end }}
54+
{{- end }}
5455
{{- end }}

charts/common/templates/functions/_utils.tpl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@ Example:
192192

193193
{{- $ = index . 0 }}
194194
{{- $collection := index . 1 }}
195-
{{- if not (empty $collection) }}
196-
{{- $collection = deepCopy $collection -}}
197-
{{- end }}
198195
{{- $templateCtx := index . 2 -}}
199196
{{- $componentName := index . 3 -}}
200197

@@ -753,7 +750,7 @@ Cache:
753750
{{- if not $.__common.fcallResult.error }}
754751
{{- $value := $.__common.fcallResult.value }}
755752
{{/* Process nested templates */}}
756-
{{- $evalTemplateCtx := deepCopy $templateCtx }}
753+
{{- $evalTemplateCtx := $templateCtx }}
757754
{{- $_ := set $evalTemplateCtx "Self" (index $evalTemplateCtx.ComponentValues (printf "%s" $dep.componentName)) }}
758755
{{- (list $ $value $evalTemplateCtx $componentName) | include "common.utils.templateCollection" }}
759756
{{- $_ := set $dep "evalResult" $.__common.fcallResult.result }}
@@ -827,7 +824,7 @@ Example:
827824
*/}}
828825
{{- $ = index . 0 }}
829826
{{- $template := index . 1 }}
830-
{{- $templateCtx := deepCopy (index . 2) -}}
827+
{{- $templateCtx := index . 2 -}}
831828
{{- $componentName := index . 3 -}}
832829
{{- $type := "" }}
833830

@@ -844,6 +841,11 @@ Example:
844841
{{- $_ := set $templateCtx "componentName" $componentName }}
845842
{{- $templatedVal := (tpl $template $templateCtx) }}
846843

844+
{{/* Unset __deps */}}
845+
{{- if hasKey $templateCtx "__deps" -}}
846+
{{ $_ := unset $templateCtx "__deps" -}}
847+
{{- end -}}
848+
847849
{{/* Format result based on type */}}
848850
{{- if not (empty $type) }}
849851
{{- if eq $type "yaml" }}

0 commit comments

Comments
 (0)