mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
c9055ac2ff
* fix(autogen): only generate rule for request kind Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(autogen): use jsoniter instead of std for json Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(atogen): use sets instead of manipulating strings Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(autogen): formatting linter Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(autogen): backwards compatability Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * revert(autogen): old behavior Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix: builds error Signed-off-by: ShutingZhao <shuting@nirmata.com> --------- Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> Signed-off-by: ShutingZhao <shuting@nirmata.com> Co-authored-by: ShutingZhao <shuting@nirmata.com>
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/go-logr/logr"
|
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
|
"github.com/kyverno/kyverno/pkg/autogen"
|
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
|
"github.com/kyverno/kyverno/pkg/engine/handlers"
|
|
"github.com/kyverno/kyverno/pkg/engine/handlers/mutation"
|
|
"github.com/kyverno/kyverno/pkg/engine/internal"
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
)
|
|
|
|
func (e *engine) verifyAndPatchImages(
|
|
ctx context.Context,
|
|
logger logr.Logger,
|
|
policyContext engineapi.PolicyContext,
|
|
) (engineapi.PolicyResponse, unstructured.Unstructured, engineapi.ImageVerificationMetadata) {
|
|
resp := engineapi.NewPolicyResponse()
|
|
policy := policyContext.Policy()
|
|
matchedResource := policyContext.NewResource()
|
|
applyRules := policy.GetSpec().GetApplyRules()
|
|
ivm := engineapi.ImageVerificationMetadata{}
|
|
|
|
policyContext.JSONContext().Checkpoint()
|
|
defer policyContext.JSONContext().Restore()
|
|
|
|
for _, rule := range autogen.ComputeRules(policy, "") {
|
|
startTime := time.Now()
|
|
logger := internal.LoggerWithRule(logger, rule)
|
|
handlerFactory := func() (handlers.Handler, error) {
|
|
if !rule.HasVerifyImages() {
|
|
return nil, nil
|
|
}
|
|
return mutation.NewMutateImageHandler(
|
|
policyContext,
|
|
matchedResource,
|
|
rule,
|
|
e.configuration,
|
|
e.rclientFactory,
|
|
e.ivCache,
|
|
&ivm,
|
|
)
|
|
}
|
|
resource, ruleResp := e.invokeRuleHandler(
|
|
ctx,
|
|
logger,
|
|
handlerFactory,
|
|
policyContext,
|
|
matchedResource,
|
|
rule,
|
|
engineapi.ImageVerify,
|
|
)
|
|
matchedResource = resource
|
|
resp.Add(engineapi.NewExecutionStats(startTime, time.Now()), ruleResp...)
|
|
if applyRules == kyvernov1.ApplyOne && resp.RulesAppliedCount() > 0 {
|
|
break
|
|
}
|
|
}
|
|
return resp, matchedResource, ivm
|
|
}
|