mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix: kyverno test ignores namespace of resources in resource.yaml (#8348)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
029a62a504
commit
53b4eaf140
3 changed files with 55 additions and 0 deletions
16
test/cli/test/disallow-service/kyverno-test.yaml
Normal file
16
test/cli/test/disallow-service/kyverno-test.yaml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
name: disallow-service
|
||||||
|
policies:
|
||||||
|
- policy.yaml
|
||||||
|
resources:
|
||||||
|
- resource.yaml
|
||||||
|
results:
|
||||||
|
- policy: disallow-service
|
||||||
|
rule: disallow-service
|
||||||
|
resources: [svc1]
|
||||||
|
kind: Service
|
||||||
|
result: skip
|
||||||
|
- policy: disallow-service
|
||||||
|
rule: disallow-service
|
||||||
|
resources: [svc2]
|
||||||
|
kind: Service
|
||||||
|
result: fail
|
26
test/cli/test/disallow-service/policy.yaml
Normal file
26
test/cli/test/disallow-service/policy.yaml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
kind: ClusterPolicy
|
||||||
|
metadata:
|
||||||
|
name: disallow-service
|
||||||
|
spec:
|
||||||
|
validationFailureAction: Validate
|
||||||
|
failurePolicy: Ignore
|
||||||
|
rules:
|
||||||
|
- name: disallow-service
|
||||||
|
match:
|
||||||
|
all:
|
||||||
|
- resources:
|
||||||
|
kinds:
|
||||||
|
- Service
|
||||||
|
preconditions:
|
||||||
|
any:
|
||||||
|
- key: "{{ request.object.metadata.namespace }}"
|
||||||
|
operator: NotEquals
|
||||||
|
value: "ns1"
|
||||||
|
- key: "{{ request.object.metadata.name }}"
|
||||||
|
operator: AnyNotIn
|
||||||
|
value: ["svc1", "svc2"]
|
||||||
|
validate:
|
||||||
|
message: >-
|
||||||
|
Can't create a service. Sorry...
|
||||||
|
anyPattern:
|
||||||
|
- kind: "!Service"
|
13
test/cli/test/disallow-service/resource.yaml
Normal file
13
test/cli/test/disallow-service/resource.yaml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# should be skipped
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: svc1
|
||||||
|
namespace: ns1
|
||||||
|
---
|
||||||
|
# should fail (wrong namespace)
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: svc2
|
||||||
|
namespace: ns3
|
Loading…
Add table
Reference in a new issue