mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
30 lines
881 B
Go
30 lines
881 B
Go
package variables
|
|
|
|
import (
|
|
"github.com/golang/glog"
|
|
kyverno "github.com/nirmata/kyverno/pkg/api/kyverno/v1"
|
|
"github.com/nirmata/kyverno/pkg/engine/context"
|
|
"github.com/nirmata/kyverno/pkg/engine/variables/operator"
|
|
)
|
|
|
|
//Evaluate evaluates the condition
|
|
func Evaluate(ctx context.EvalInterface, condition kyverno.Condition) bool {
|
|
// get handler for the operator
|
|
handle := operator.CreateOperatorHandler(ctx, condition.Operator, SubstituteVariables)
|
|
if handle == nil {
|
|
return false
|
|
}
|
|
return handle.Evaluate(condition.Key, condition.Value)
|
|
}
|
|
|
|
//EvaluateConditions evaluates multiple conditions
|
|
func EvaluateConditions(ctx context.EvalInterface, conditions []kyverno.Condition) bool {
|
|
// AND the conditions
|
|
for _, condition := range conditions {
|
|
if !Evaluate(ctx, condition) {
|
|
glog.V(4).Infof("condition %v failed", condition)
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|