tableconvertor: parse memory quantities via resource.ParseQuantity#627
Draft
tamalsaha wants to merge 1 commit into
Draft
tableconvertor: parse memory quantities via resource.ParseQuantity#627tamalsaha wants to merge 1 commit into
tamalsaha wants to merge 1 commit into
Conversation
The previous fmt.Sscanf-based parser only accepted strict binary
suffixes (Ki, Mi, Gi, Ti) or a trailing 'B'. Kubernetes resource
quantities legitimately emit plain integers ("8589934592"), SI units
("1G", "1k"), exponential ("1e9"), and decimal-with-suffix ("1.5Gi")
forms via resource.Quantity.String(); all of those were rejected and
the resulting error propagated up, failing the entire row render in
formatResourceMemoryFn.
Delegate to resource.ParseQuantity + AsApproximateFloat64, which is
the canonical way to convert any Kubernetes quantity string to a
numeric value. The package is already imported.
Signed-off-by: Tamal Saha <tamal@appscode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
convertSizeToBytesinpkg/tableconvertor/util.gousedfmt.Sscanfwith a strict format string and required either a binary suffix (Ki/Mi/Gi/Ti) or a trailingB. Legit Kubernetes quantity strings — plain integer bytes (8589934592), SI units (1G,1k), decimal-with-suffix (1.5Gi), exponentials — all returned an error.formatResourceMemoryFn(k8s_fmt_resource_memory) and fails the entire row render.resource.ParseQuantity(...).AsApproximateFloat64().k8s.io/apimachinery/pkg/api/resourceis already imported.Test plan
make unit-testsk8s_fmt_resource_memoryagainst pods with: a raw-byte allocatable value, anMi-suffixed limit, a decimal1.5Girequest, and an SI1Gvalue — confirm all render without error.🤖 Generated with Claude Code