Skip to content

tableconvertor: parse memory quantities via resource.ParseQuantity#627

Draft
tamalsaha wants to merge 1 commit into
masterfrom
fix/convert-size-quantity
Draft

tableconvertor: parse memory quantities via resource.ParseQuantity#627
tamalsaha wants to merge 1 commit into
masterfrom
fix/convert-size-quantity

Conversation

@tamalsaha
Copy link
Copy Markdown
Contributor

Summary

  • convertSizeToBytes in pkg/tableconvertor/util.go used fmt.Sscanf with a strict format string and required either a binary suffix (Ki/Mi/Gi/Ti) or a trailing B. Legit Kubernetes quantity strings — plain integer bytes (8589934592), SI units (1G, 1k), decimal-with-suffix (1.5Gi), exponentials — all returned an error.
  • The error propagates from formatResourceMemoryFn (k8s_fmt_resource_memory) and fails the entire row render.
  • Replace with resource.ParseQuantity(...).AsApproximateFloat64(). k8s.io/apimachinery/pkg/api/resource is already imported.

Test plan

  • make unit-tests
  • Render a column that uses k8s_fmt_resource_memory against pods with: a raw-byte allocatable value, an Mi-suffixed limit, a decimal 1.5Gi request, and an SI 1G value — confirm all render without error.

🤖 Generated with Claude Code

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>
@tamalsaha tamalsaha marked this pull request as draft May 19, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant