From 35b4ce0a4217147c2aa298a5ede8ebe9edd7571f Mon Sep 17 00:00:00 2001 From: jklein Date: Sat, 29 Aug 2026 01:09:12 +0200 Subject: [PATCH] patchmon: render byte counts without exponential notation (7.0.1+up2.1.3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The null-safe fallback helpers from #99 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" The same "%v" sits a second time on the output of a non-integral product, where it never passes the suffix check — a fractional limitFactor together with a bare number rendered a silently invalid quantity ("1.4999985e+06") that only the API server rejects on apply. Both call sites now go through a new patchmon.formatNumber helper, which forces decimal notation for float64 and passes strings ("512Mi") through untouched. This is the canonical fix agreed in #157, taken over verbatim from template-chart with this chart's define prefix, so multiplyQuantity stays the same copy in every chart. Teil von #157. --- patchmon/Chart.yaml | 2 +- patchmon/templates/_helpers.tpl | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/patchmon/Chart.yaml b/patchmon/Chart.yaml index 95b0002..f06dc76 100644 --- a/patchmon/Chart.yaml +++ b/patchmon/Chart.yaml @@ -5,7 +5,7 @@ icon: https://raw.githubusercontent.com/PatchMon/PatchMon/main/frontend/public/a type: application -version: 7.0.0+up2.1.3 +version: 7.0.1+up2.1.3 appVersion: "2.1.3" maintainers: diff --git a/patchmon/templates/_helpers.tpl b/patchmon/templates/_helpers.tpl index eb9d1d5..5baae8e 100644 --- a/patchmon/templates/_helpers.tpl +++ b/patchmon/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 "patchmon.multiplyQuantity" -}} -{{- $quantity := printf "%v" .quantity -}} +{{- $quantity := include "patchmon.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 "patchmon.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 "patchmon.formatNumber" -}} +{{- if kindIs "float64" . -}} +{{- regexReplaceAll "\\.?0+$" (printf "%.10f" .) "" -}} +{{- else -}} +{{- printf "%v" . -}} {{- end -}} {{- end -}}