Skip to content

Commit

Permalink
models: make kubernetes taint values optional
Browse files Browse the repository at this point in the history
This modifies the validation for KubernetesTaintValue to make the taint
value optional for 'Exists' toleration operators.
  • Loading branch information
etungsten committed Mar 22, 2021
1 parent f2279e1 commit 5b713b1
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions sources/models/src/modeled_types/kubernetes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,14 @@ pub struct KubernetesTaintValue {
lazy_static! {
pub(crate) static ref KUBERNETES_TAINT_VALUE: Regex = Regex::new(
r"(?x)^
[[:alnum:]] # at least one alphanumeric
(
([[:alnum:]._-]{0,61})? # more characters allowed in middle
[[:alnum:]] # have to end with alphanumeric
)?
: # separate the label value from the effect
[[:alnum:]] # values have to start with alphanumeric if they're specified
(
([[:alnum:]._-]{0,61})? # more characters allowed in middle
[[:alnum:]] # values have to end with alphanumeric
)? # only the first alphanumeric is required, further chars optional
)? # the taint value is optional
: # separate the taint value from the effect
[[:alnum:]]{1,253} # effect
$"
)
Expand Down Expand Up @@ -266,14 +268,25 @@ mod test_kubernetes_taint_value {
"value:NoSchedule",
"value:PreferNoSchedule",
"value:NoExecute",
":NoSchedule",
"a:NoSchedule",
"a-b:NoSchedule",
] {
KubernetesTaintValue::try_from(*ok).unwrap();
}
}

#[test]
fn bad_values() {
for err in &[".bad", "bad.", &"a".repeat(254), "value:", ":effect"] {
for err in &[
".bad",
"bad.",
&"a".repeat(254),
"value:",
":",
"-a:NoSchedule",
"a-:NoSchedule",
] {
KubernetesTaintValue::try_from(*err).unwrap_err();
}
}
Expand Down

0 comments on commit 5b713b1

Please sign in to comment.