mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-09 01:16:55 +00:00
* feat: add fail/warn on deprecated/invalid operators Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: nested for each Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: chainsaw-test.yaml Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> --------- Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package operator
|
|
|
|
import (
|
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
|
"k8s.io/utils/strings/slices"
|
|
)
|
|
|
|
var deprecatedOperators = map[string][]string{
|
|
"In": {"AllIn", "AnyIn"},
|
|
"NotIn": {"AllNotIn", "AnyNotIn"},
|
|
}
|
|
|
|
func GetAllConditionOperators() []string {
|
|
operators := make([]string, 0, len(kyvernov1.ConditionOperators))
|
|
for k := range kyvernov1.ConditionOperators {
|
|
operators = append(operators, k)
|
|
}
|
|
return operators
|
|
}
|
|
|
|
func GetAllDeprecatedOperators() []string {
|
|
operators := make([]string, 0, len(deprecatedOperators))
|
|
for k := range deprecatedOperators {
|
|
operators = append(operators, k)
|
|
}
|
|
return operators
|
|
}
|
|
|
|
func GetDeprecatedOperatorAlternative(op string) []string {
|
|
alts, ok := deprecatedOperators[op]
|
|
if !ok {
|
|
arr := make([]string, 0)
|
|
return arr
|
|
}
|
|
return alts
|
|
}
|
|
|
|
func IsOperatorValid(operator kyvernov1.ConditionOperator) bool {
|
|
return slices.Contains(GetAllConditionOperators(), string(operator))
|
|
}
|
|
|
|
func IsOperatorDeprecated(operator kyvernov1.ConditionOperator) bool {
|
|
return slices.Contains(GetAllDeprecatedOperators(), string(operator))
|
|
}
|