mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-28 18:38:40 +00:00
fix mutate handling of skipped rules (#2557)
This commit is contained in:
parent
e0b1f08a28
commit
e3fe8e0cc1
3 changed files with 18 additions and 4 deletions
|
@ -208,7 +208,7 @@ func mutateResource(rule *kyverno.Rule, ctx *context.Context, resource unstructu
|
|||
mutateResp := &mutateResponse{false, unstructured.Unstructured{}, nil, ""}
|
||||
|
||||
// Pre-conditions checks for the list of foreach rules should ideally be performed once.
|
||||
// Currently they are performed for each entry in the foreach list.
|
||||
// Currently, they are performed for each entry in the foreach list.
|
||||
// Also, the foreach index parameter should be removed and a set of patches should be passed in.
|
||||
anyAllConditions, err := variables.SubstituteAllInPreconditions(logger, ctx, rule.AnyAllConditions)
|
||||
if err != nil {
|
||||
|
@ -221,7 +221,8 @@ func mutateResource(rule *kyverno.Rule, ctx *context.Context, resource unstructu
|
|||
}
|
||||
|
||||
if !variables.EvaluateConditions(logger, ctx, copyConditions) {
|
||||
return errors.Wrapf(err, "preconditions mismatch"), mutateResp
|
||||
mutateResp.skip = true
|
||||
return fmt.Errorf("preconditions mismatch"), mutateResp
|
||||
}
|
||||
|
||||
updatedRule, err := variables.SubstituteAllInRule(logger, ctx, *rule)
|
||||
|
|
|
@ -28,6 +28,21 @@ spec:
|
|||
metadata:
|
||||
labels:
|
||||
color: orange
|
||||
- name: "impossible-rule"
|
||||
match:
|
||||
resources:
|
||||
kinds:
|
||||
- Pod
|
||||
preconditions:
|
||||
all:
|
||||
- key: "not-the-name" # This precondition should always fail!
|
||||
operator: In
|
||||
value: "{{ request.object.metadata.labels | keys(@) }}"
|
||||
mutate:
|
||||
patchStrategicMerge:
|
||||
metadata:
|
||||
labels:
|
||||
something: "something"
|
||||
|
||||
---
|
||||
|
||||
|
|
|
@ -43,8 +43,6 @@ results:
|
|||
patchedResource: patchedResource6.yaml
|
||||
kind: Pod
|
||||
result: pass
|
||||
|
||||
|
||||
- policy: testing/add-ndots
|
||||
rule: add-ndots
|
||||
resource: resource-equal-to-patch-res-for-cp
|
||||
|
|
Loading…
Add table
Reference in a new issue