From 11180bd5030dd6f7840e7fa1e7e99612adee64ce Mon Sep 17 00:00:00 2001 From: jklein Date: Sat, 29 Aug 2026 01:04:40 +0200 Subject: [PATCH] bentopdf: render byte counts as plain decimals (1.0.1+up2.8.7) multiplyQuantity turned its input into a string with printf "%v". The null-safe fallback helpers from #99 pass values through fromYaml, which parses every number as float64, and Go's "%v" switches float64 to exponential notation from about 1e6 upwards. A bare byte count like 1048576 therefore arrived as "1.048576e+06", the suffix check rejected "e+06" and the render aborted. The same printf sat on the second output path, for a non-integer product (a fractional limitFactor - typed "number", not "integer", in this chart's values.schema.json, so ordinary values reach it). That one never passes the suffix check, so it produced an invalid quantity silently and only the API server would have rejected the manifest on apply. Both are now routed through a formatNumber helper that forces decimal notation and trims the padding zeros. Strings ("512Mi") pass through untouched, so the default render is unchanged. Part of #157. The helper is a verbatim copy of the fix already merged for template-chart, zipline, voucher-vault and outline - multiplyQuantity is the same duplicated code in every chart. --- bentopdf/Chart.yaml | 2 +- bentopdf/templates/_helpers.tpl | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bentopdf/Chart.yaml b/bentopdf/Chart.yaml index bf2c923..fe22c8b 100644 --- a/bentopdf/Chart.yaml +++ b/bentopdf/Chart.yaml @@ -5,7 +5,7 @@ icon: https://raw.githubusercontent.com/alam00000/bentopdf/main/public/images/fa type: application -version: 1.0.0+up2.8.7 +version: 1.0.1+up2.8.7 appVersion: "2.8.7" maintainers: diff --git a/bentopdf/templates/_helpers.tpl b/bentopdf/templates/_helpers.tpl index 1d4cf66..e350a9f 100644 --- a/bentopdf/templates/_helpers.tpl +++ b/bentopdf/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 "bentopdf.multiplyQuantity" -}} -{{- $quantity := printf "%v" .quantity -}} +{{- $quantity := include "bentopdf.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 "bentopdf.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 "bentopdf.formatNumber" -}} +{{- if kindIs "float64" . -}} +{{- regexReplaceAll "\\.?0+$" (printf "%.10f" .) "" -}} +{{- else -}} +{{- printf "%v" . -}} {{- end -}} {{- end -}}