Skip to content

Commit

Permalink
Merge pull request #1406 from etungsten/kube-taint-value-optional
Browse files Browse the repository at this point in the history
models: make kubernetes taint values optional
  • Loading branch information
etungsten authored Mar 22, 2021
2 parents f2279e1 + 5b713b1 commit f81034e
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 f81034e

Please sign in to comment.