Skip to main content

parse_k8s_quantity

Function parse_k8s_quantity 

Source
pub fn parse_k8s_quantity(s: &str) -> Option<i128>
Expand description

Parse a k8s-quantity string into a canonical comparable value (milli of the base unit, as i128). Handles the common suffixes:

  • binary: Ki/Mi/Gi/Ti/Pi/Ei (×1024^n)
  • decimal: k/M/G/T/P/E (×1000^n)
  • m (milli, ÷1000)
  • plain decimal number

Returns None for unparseable input. This is deliberately minimal — it covers the suffixes in real use here; full k8s quantity semantics (sign, exponents, the binary/decimal distinction k8s preserves) are deferred to the scheduler engine that actually does capacity math. Comparison only needs the same input to canonicalize consistently.