1
0
Fork 0
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:
Lukasz Jakimczuk 2021-10-29 14:48:22 +02:00 committed by GitHub
parent 373420aa6d
commit 40b579ccd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}