From 800a19801744a0675639230c255a22144f97a5b3 Mon Sep 17 00:00:00 2001 From: jklein Date: Sat, 29 Aug 2026 00:02:51 +0200 Subject: [PATCH] voucher-vault: keep large integer quantities out of exponential notation The null-safe fallback helpers pass values through fromYaml, which parses every number as float64. Go's "%v" switches float64 to exponential notation from about 1e6 upwards, so a bare byte count like 1048576 reached multiplyQuantity as "1.048576e+06" and the render aborted with unsupported resource quantity suffix "e+06" in "1.048576e+06" Both the input and the non-integer product now go through a formatNumber helper that forces decimal notation and trims the padding zeros; strings such as 512Mi pass through untouched. This is the canonical fix agreed for all charts - multiplyQuantity is the same copy everywhere, so deviating here would create drift instead of a solution. Measured against ci/voucher-vault/test-values.yaml on both request keys that get a computed limit (memory, ephemeral-storage): 1048576 renders a limit of "3145728" instead of aborting, and the fallback case 65536 is unchanged at 196608. Part of #157 --- voucher-vault/templates/_helpers.tpl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/voucher-vault/templates/_helpers.tpl b/voucher-vault/templates/_helpers.tpl index 6099f50..9c49673 100644 --- a/voucher-vault/templates/_helpers.tpl +++ b/voucher-vault/templates/_helpers.tpl @@ -67,7 +67,7 @@ Handles plain numbers ("2", "0.5", 1073741824), decimal ("1.5Gi"), binary results are printed without a decimal point. */}} {{- define "voucher-vault.multiplyQuantity" -}} -{{- $quantity := printf "%v" .quantity -}} +{{- $quantity := include "voucher-vault.formatNumber" .quantity -}} {{- $number := regexFind "^[0-9]+(\\.[0-9]+)?" $quantity -}} {{- if not $number -}} {{- fail (printf "cannot parse resource quantity %q" $quantity) -}} @@ -80,7 +80,24 @@ results are printed without a decimal point. {{- if eq $product (floor $product) -}} {{- printf "%d%s" (int64 $product) $suffix -}} {{- else -}} -{{- printf "%v%s" $product $suffix -}} +{{- printf "%s%s" (include "voucher-vault.formatNumber" $product) $suffix -}} +{{- end -}} +{{- end -}} + +{{/* +Render a number as a plain decimal string, never in exponential notation. + +Why this exists (issue #157): the null-safe fallback helpers pass values +through fromYaml, which parses every number as float64. Go's "%v" switches +float64 to exponential notation from about 1e6 upwards, so a bare byte count +like 1048576 became "1.048576e+06" - not a valid Kubernetes quantity, and the +render aborted. Strings ("512Mi") are passed through untouched. +*/}} +{{- define "voucher-vault.formatNumber" -}} +{{- if kindIs "float64" . -}} +{{- regexReplaceAll "\\.?0+$" (printf "%.10f" .) "" -}} +{{- else -}} +{{- printf "%v" . -}} {{- end -}} {{- end -}}