diff --git a/cmd/cli/kubectl-kyverno/processor/policy_processor.go b/cmd/cli/kubectl-kyverno/processor/policy_processor.go index 7624f7f422..d19d1c4f40 100644 --- a/cmd/cli/kubectl-kyverno/processor/policy_processor.go +++ b/cmd/cli/kubectl-kyverno/processor/policy_processor.go @@ -204,8 +204,11 @@ func (p *PolicyProcessor) makePolicyContext( } resourceValues = vals } - if resourceValues["request.operation"] == "DELETE" { + switch resourceValues["request.operation"] { + case "DELETE": operation = kyvernov1.Delete + case "UPDATE": + operation = kyvernov1.Update } policyContext, err := engine.NewPolicyContext( jp, @@ -217,6 +220,9 @@ func (p *PolicyProcessor) makePolicyContext( if err != nil { log.Log.Error(err, "failed to create policy context") } + if operation == kyvernov1.Update { + policyContext = policyContext.WithOldResource(resource) + } policyContext = policyContext. WithPolicy(policy). WithNamespaceLabels(namespaceLabels).