1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 09:26:54 +00:00
kyverno/pkg/engine/variables/operator/utils.go
Vishal Choudhary 82b65aebc4
feat: add fail/warn on deprecated/invalid operators (#8624)
* 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>
2024-01-31 08:40:28 +00:00

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