mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix mutate wildcard issue (#3193)
Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
parent
0a5aad39cf
commit
04e5f50cde
8 changed files with 107 additions and 3 deletions
|
@ -150,10 +150,12 @@ func (ws *WebhookServer) applyMutation(request *v1beta1.AdmissionRequest, policy
|
|||
return nil, nil, fmt.Errorf("failed to apply policy %s rules %v", policyContext.Policy.Name, engineResponse.GetFailedRules())
|
||||
}
|
||||
|
||||
if engineResponse.PatchedResource.GetKind() != "*" {
|
||||
err := ws.openAPIController.ValidateResource(*engineResponse.PatchedResource.DeepCopy(), engineResponse.PatchedResource.GetAPIVersion(), engineResponse.PatchedResource.GetKind())
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "failed to validate resource mutated by policy %s", policyContext.Policy.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return engineResponse, policyPatches, nil
|
||||
}
|
||||
|
|
18
test/cli/test/wildcard_mutate/kyverno-test.yaml
Normal file
18
test/cli/test/wildcard_mutate/kyverno-test.yaml
Normal file
|
@ -0,0 +1,18 @@
|
|||
name: wildcard-support-in-matchlabels
|
||||
policies:
|
||||
- policy.yaml
|
||||
resources:
|
||||
- resources.yaml
|
||||
results:
|
||||
- policy: mutate-wildcard
|
||||
rule: mutate-wildcard
|
||||
resource: wildcard-mutate
|
||||
patchedResource: patchedResource.yaml
|
||||
kind: Pod
|
||||
result: pass
|
||||
- policy: mutate-wildcard
|
||||
rule: mutate-wildcard
|
||||
resource: wildcard-mutate-fail
|
||||
patchedResource: patchedResource1.yaml
|
||||
kind: Pod
|
||||
result: fail
|
11
test/cli/test/wildcard_mutate/patchedResource.yaml
Normal file
11
test/cli/test/wildcard_mutate/patchedResource.yaml
Normal file
|
@ -0,0 +1,11 @@
|
|||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
annotations:
|
||||
test: app
|
||||
name: wildcard-mutate
|
||||
namespace: default
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:latest
|
||||
name: nginx
|
9
test/cli/test/wildcard_mutate/patchedResource1.yaml
Normal file
9
test/cli/test/wildcard_mutate/patchedResource1.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: wildcard-mutate
|
||||
namespace: default
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:latest
|
||||
name: nginx
|
19
test/cli/test/wildcard_mutate/policy.yaml
Normal file
19
test/cli/test/wildcard_mutate/policy.yaml
Normal file
|
@ -0,0 +1,19 @@
|
|||
apiVersion: kyverno.io/v1
|
||||
kind: ClusterPolicy
|
||||
metadata:
|
||||
name: mutate-wildcard
|
||||
spec:
|
||||
background: false
|
||||
failurePolicy: Ignore
|
||||
rules:
|
||||
- name: mutate-wildcard
|
||||
match:
|
||||
all:
|
||||
- resources:
|
||||
kinds:
|
||||
- "*"
|
||||
mutate:
|
||||
patchStrategicMerge:
|
||||
metadata:
|
||||
annotations:
|
||||
test: "app"
|
18
test/cli/test/wildcard_mutate/resources.yaml
Normal file
18
test/cli/test/wildcard_mutate/resources.yaml
Normal file
|
@ -0,0 +1,18 @@
|
|||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: wildcard-mutate
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:latest
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: wildcard-mutate-fail
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:latest
|
19
test/policy.yaml
Normal file
19
test/policy.yaml
Normal file
|
@ -0,0 +1,19 @@
|
|||
apiVersion: kyverno.io/v1
|
||||
kind: ClusterPolicy
|
||||
metadata:
|
||||
name: who-created-this
|
||||
spec:
|
||||
background: false
|
||||
failurePolicy: Ignore
|
||||
rules:
|
||||
- name: who-created-this
|
||||
match:
|
||||
all:
|
||||
- resources:
|
||||
kinds:
|
||||
- "*"
|
||||
mutate:
|
||||
patchStrategicMerge:
|
||||
metadata:
|
||||
annotations:
|
||||
test: "app"
|
8
test/resources.yaml
Normal file
8
test/resources.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-require-image-tag-pass
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:latest
|
Loading…
Add table
Reference in a new issue