kubernetes-sigs / kubernetes-sigs/devops-bench

Promote k8s resource quantity parsing to a shared utility

Open
#116 0 comments 0 reactions 0 assignees View on GitHub

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 7 CPU / 28Gi want 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

  1. 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).
  2. Add the inverse: format a number back to a canonical quantity string, so we can generate values, not just read them.
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.