1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-28 02:18:15 +00:00

chore: add kuttl test for namespace exclusion (#6914)

* chore: add kuttl test for namespace exclusion

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix readme

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* Update test/conformance/kuttl/validate/clusterpolicy/standard/exclude/exclude-namespace/README.md

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-04-13 17:39:55 +02:00 committed by GitHub
parent 39e51a0047
commit cf2502e1ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 66 additions and 0 deletions

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policies.yaml
assert:
- policies-assert.yaml

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- resources.yaml

View file

@ -0,0 +1,11 @@
## Description
This test creates a policy to validate all resources have a `foo: bar` label.
The policy matches on a wildcard but excludes a whole Namespace.
The net result should be any Namespaced resource in the excluded Namespace should not be processed.
It then creates a configmap in the default namespace that doesn't have the expected label.
## Expected Behavior
The configmap should be created successfully as it is excluded by the policy.

View file

@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-label
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready

View file

@ -0,0 +1,30 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-label
spec:
validationFailureAction: Enforce
background: false
rules:
- name: require-label
match:
any:
- resources:
kinds:
- "*"
exclude:
any:
- resources:
namespaces:
- default
preconditions:
all:
- key: "{{ request.operation }}"
operator: NotEquals
value: DELETE
validate:
message: 'Test'
pattern:
metadata:
labels:
foo: bar

View file

@ -0,0 +1,5 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: test-name
namespace: default

View file

@ -1,2 +1,3 @@
## Description
Basic validate test to check that a verify-image policy cannot be created when the policy has wildcard(*) included in match any/all resource block.