kubernetes-sigs / kubernetes-sigs/devops-bench
Promote k8s resource quantity parsing to a shared utility
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31
- Forks
- 15
- Avg merge
- 6d 23h
- Merged PRs (30d)
- 20
Description
Context
We already have working Kubernetes resource quantity parsing in the bench: to_number() in devops_bench/verification/verifiers/resource_property.py handles the binary suffixes (Ki/Mi/Gi/Ti/Pi/Ei), the decimal ones (n/u/m/k/M/G/T/P/E), and is careful not to coerce bare numeric strings like "1.2" so image tags stay literal. ResourcePropertyVerifier uses it so live-cluster comparisons like 200m vs 50m are numeric instead of lexical.
The problem is that it's private to the verification module. Quantity handling is needed all over the place, and anything outside verification that wants to reason about these values today has to reach into a verifier file for it:
- provider and stack sizing (see the ResourceQuota/LimitRange discussion on #76, where quota numbers like
7CPU /28Giwant to become overridable variables) - validating sizing values that tasks pass through
infrastructure.variables - any future host-shape to quota derivation, or "does this task seed fit the namespace quota" checks
Proposal
- Promote the parsing to a shared utility, something like
devops_bench/k8s/quantity.py, and have the verifier import it from there (no behavior change). - Add the inverse: format a number back to a canonical quantity string, so we can generate values, not just read them.
- Possibly a small Quantity type with comparison/arithmetic, so callers don't juggle floats and re-format by hand.
Non-goals
Adding the kubernetes Python client as a dependency just to get kubernetes.utils.quantity.parse_quantity. The homegrown parser is small and already tested (tests/unit/verification/test_resource_property.py); it just lives in the wrong place.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with devops_bench/verification/verifiers/resource_property.py and tests/unit/verification/test_resource_property.py to understand the existing parser and its covered behavior. Trace the verifier's imports before choosing the shared utility boundary, then clarify whether the inverse formatter and optional Quantity type are in scope. Done means callers use the shared location without behavior regressions and the new quantity behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kubernetes, python
- Domain
- infrastructure, tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100