diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index ddb98a3684..90932a92c4 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -205,6 +205,14 @@ func (e *engine) invokeRuleHandler( // TODO: return error ? return resource, nil } + // check preconditions + preconditionsPassed, err := internal.CheckPreconditions(logger, policyContext, rule.GetAnyAllConditions()) + if err != nil { + return resource, handlers.RuleResponses(internal.RuleError(&rule, ruleType, "failed to evaluate preconditions", err)) + } + if !preconditionsPassed { + return resource, handlers.RuleResponses(internal.RuleSkip(&rule, ruleType, "preconditions not met")) + } // process handler return handler.Process(ctx, logger, policyContext, resource, rule) },