mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
Improving readability (#2638)
Signed-off-by: Łukasz Jakimczuk <lukasz.j@giantswarm.io>
This commit is contained in:
parent
373420aa6d
commit
40b579ccd7
1 changed files with 11 additions and 5 deletions
|
@ -182,22 +182,28 @@ func validateValueWithStringPattern(log logr.Logger, value interface{}, pattern
|
|||
// Upon encountering InRange operator split the string by `-` and basically
|
||||
// verify the result of (x >= leftEndpoint & x <= rightEndpoint)
|
||||
if operatorVariable == operator.InRange {
|
||||
gt := validateValueWithStringPattern(log, value, fmt.Sprintf(">=%s", strings.Split(pattern, "-")[0]))
|
||||
endpoints := strings.Split(pattern, "-")
|
||||
leftEndpoint, rightEndpoint := endpoints[0], endpoints[1]
|
||||
|
||||
gt := validateValueWithStringPattern(log, value, fmt.Sprintf(">=%s", leftEndpoint))
|
||||
if !gt {
|
||||
return false
|
||||
}
|
||||
pattern = fmt.Sprintf("<=%s", strings.Split(pattern, "-")[1])
|
||||
pattern = fmt.Sprintf("<=%s", rightEndpoint)
|
||||
operatorVariable = operator.LessEqual
|
||||
}
|
||||
|
||||
// Upon encountering NotInRange operator split the string by `!-` and basically
|
||||
// verify the result of (x < leftEndpoint | x > rightEndpoint)
|
||||
if operatorVariable == operator.NotInRange {
|
||||
gt := validateValueWithStringPattern(log, value, fmt.Sprintf("<%s", strings.Split(pattern, "!-")[0]))
|
||||
if gt {
|
||||
endpoints := strings.Split(pattern, "!-")
|
||||
leftEndpoint, rightEndpoint := endpoints[0], endpoints[1]
|
||||
|
||||
lt := validateValueWithStringPattern(log, value, fmt.Sprintf("<%s", leftEndpoint))
|
||||
if lt {
|
||||
return true
|
||||
}
|
||||
pattern = fmt.Sprintf(">%s", strings.Split(pattern, "!-")[1])
|
||||
pattern = fmt.Sprintf(">%s", rightEndpoint)
|
||||
operatorVariable = operator.More
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue