Skip to main content

validate_jitter_bounds

Function validate_jitter_bounds 

Source
pub fn validate_jitter_bounds(field: &str, jitter: &str) -> ValidationResult
Expand description

Validate a present Go-style jitter duration: it must parse (same parser validate_jitter and the scheduler use) AND must not exceed MAX_JITTER.

The bounds half is a TIGHTENING of an existing rule, so it is admission-only — the controller re-runs the shared aggregates as a hard stop at reconcile, and adding this to one of them would brick a stored CR carrying an over-24h jitter rather than merely refusing the next edit. Call it from the webhook’s per-kind validate_*_admission_extras, never from a shared aggregate.

Takes a bare &str (not Option<&str>) because every caller is already inside an if let Some(j) over the field it is checking.

use kopiur_api::validate::validate_jitter_bounds;

assert!(validate_jitter_bounds("spec.schedule.jitter", "10m").is_ok());
// Exactly the cap is fine; a second past it is not.
assert!(validate_jitter_bounds("spec.schedule.jitter", "24h").is_ok());
assert!(validate_jitter_bounds("spec.schedule.jitter", "86401s").is_err());
// Garbage is rejected by the parse half.
assert!(validate_jitter_bounds("spec.schedule.jitter", "soon").is_err());