diff --git a/packages/apps/vpc/templates/vpc.yaml b/packages/apps/vpc/templates/vpc.yaml index cb860279..784c181b 100644 --- a/packages/apps/vpc/templates/vpc.yaml +++ b/packages/apps/vpc/templates/vpc.yaml @@ -16,7 +16,6 @@ spec: namespaces: - {{ .Release.Namespace }} {{- if .Values.peers }} -{{- $hexLookup := dict "0" 0 "1" 1 "2" 2 "3" 3 "4" 4 "5" 5 "6" 6 "7" 7 "8" 8 "9" 9 "a" 10 "b" 11 "c" 12 "d" 13 "e" 14 "f" 15 }} vpcPeerings: {{- range .Values.peers }} {{- $remoteRelease := printf "virtualprivatecloud-%s" .vpcName }} @@ -24,12 +23,8 @@ spec: {{- $sorted := list $vpcId $remoteVpcId | sortAlpha }} {{- $pairKey := join "/" $sorted }} {{- $pairHash := sha256sum $pairKey }} -{{- $h0 := int (get $hexLookup (substr 0 1 $pairHash)) }} -{{- $h1 := int (get $hexLookup (substr 1 2 $pairHash)) }} -{{- $h2 := int (get $hexLookup (substr 2 3 $pairHash)) }} -{{- $h3 := int (get $hexLookup (substr 3 4 $pairHash)) }} -{{- $byte0 := add (mul $h0 16) $h1 }} -{{- $byte1 := add (mul $h2 16) $h3 }} +{{- $byte0 := int (include "cozy-lib.strings.hexToInt" (substr 0 2 $pairHash)) }} +{{- $byte1 := int (include "cozy-lib.strings.hexToInt" (substr 2 4 $pairHash)) }} {{- $oct3 := int (add (mod $byte0 254) 1) }} {{- $base4 := int (mul (mod $byte1 64) 4) }} {{- if eq $vpcId (index $sorted 0) }} diff --git a/packages/library/cozy-lib/templates/_strings.tpl b/packages/library/cozy-lib/templates/_strings.tpl new file mode 100644 index 00000000..0ba8153f --- /dev/null +++ b/packages/library/cozy-lib/templates/_strings.tpl @@ -0,0 +1,3 @@ +{{- define "cozy-lib.strings.hexToInt" }} +{{- printf "num: 0x%s" . | fromYaml | dig "num" 0 }} +{{- end }}