Skip to content

fix(utils): reject mi, ni and ui as quantity suffixes - #2748

Open
ArfiArfath21 wants to merge 1 commit into
kubernetes-client:masterfrom
ArfiArfath21:quantity-reject-invalid-binary-suffixes
Open

ArfiArfath21 wants to merge 1 commit into
kubernetes-client:masterfrom
ArfiArfath21:quantity-reject-invalid-binary-suffixes

Conversation

@ArfiArfath21

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

parse_quantity and format_quantity only rejected ki among the binary suffixes, so mi, ni and ui were accepted as base-1024 negative exponents (parse_quantity("1mi") returned 1/1024, format_quantity(Decimal(1), "mi") returned "1024mi"). Binary suffixes are now limited to Ki, Mi, Gi, Ti, Pi and Ei, as in apimachinery's quantity.go. A typo such as 512mi now raises ValueError instead of silently becoming a tiny number.

Which issue(s) this PR fixes:

Fixes #2746

Special notes for your reviewer:

Tests added to TestUtilsUnitTests in kubernetes/e2e_test/test_utils.py; they fail on master and pass with this change.

AI assistance disclosure: prepared with Claude Code; I reviewed the change and ran the tests locally.

Does this PR introduce a user-facing change?

`kubernetes.utils.parse_quantity` and `format_quantity` now raise `ValueError` for the invalid binary suffixes `mi`, `ni` and `ui` instead of accepting them.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Oct 16, 2026
@kubernetes-prow
kubernetes-prow Bot requested a review from roycaihw October 16, 2026 18:16
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ArfiArfath21
Once this PR has been reviewed and has the lgtm label, please assign roycaihw for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow
kubernetes-prow Bot requested a review from yliaog October 16, 2026 18:16
@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: ArfiArfath21 / name: ArfiArfath21 (b976cf7)

@kubernetes-prow kubernetes-prow Bot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 16, 2026
@ArfiArfath21
ArfiArfath21 force-pushed the quantity-reject-invalid-binary-suffixes branch from 694d9a8 to c831a6d Compare October 16, 2026 18:17
@ArfiArfath21

Copy link
Copy Markdown
Author

/easycla

parse_quantity and format_quantity only rejected 'ki' among the binary
suffixes, so 'mi', 'ni' and 'ui' were accepted as base-1024 negative
exponents (e.g. parse_quantity('1mi') == 1/1024). Binary suffixes are limited
to Ki, Mi, Gi, Ti, Pi and Ei.
@ArfiArfath21
ArfiArfath21 force-pushed the quantity-reject-invalid-binary-suffixes branch from c831a6d to b976cf7 Compare October 16, 2026 18:23
@ArfiArfath21

Copy link
Copy Markdown
Author

/easycla

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse_quantity/format_quantity accept invalid binary suffixes mi, ni and ui

1 participant