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

[Feature] Add kuttl tests with policy exceptions disabled (#7117)

* added tests

Signed-off-by: Ved Ratan <vedratan8@gmail.com>

* removed redundant code

Signed-off-by: Ved Ratan <vedratan8@gmail.com>

* fix

Signed-off-by: Ved Ratan <vedratan8@gmail.com>

* fix

Signed-off-by: Ved Ratan <vedratan8@gmail.com>

* typo fix and README changes

Signed-off-by: Ved Ratan <vedratan8@gmail.com>

* fix

Signed-off-by: Ved Ratan <vedratan8@gmail.com>

---------

Signed-off-by: Ved Ratan <vedratan8@gmail.com>
This commit is contained in:
Ved Ratan 2023-05-08 03:39:21 +05:30 committed by GitHub
parent 696c7e924b
commit 942814e942
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 1 deletions

View file

@ -4,4 +4,4 @@ This test tries to create policies with invalid timeouts (`< 1` or `> 30`).
## Expected Behavior
Policies shoudl be rejected.
Policies should be rejected.

View file

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

View file

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

View file

@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- file: resource.yaml
shouldFail: true

View file

@ -0,0 +1,7 @@
## Description
This test is attempting to create a resource with the label "app: my-test-app", which would typically violate the policy defined. However, there is a policy exception defined for resources with the same label, which should bypass the policy. Since the Policy Exception feature has not been enabled, the resource will be blocked by the policy instead of being allowed.
## Expected Behavior
The Pod should be blocked.

View file

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

View file

@ -0,0 +1,21 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-app-label
spec:
validationFailureAction: Enforce
background: false
rules:
- name: require-app-label
match:
any:
- resources:
kinds:
- Pod
- Deployment
validate:
message: Pod must include the 'app=my-app' label
pattern:
metadata:
labels:
app: my-app

View file

@ -0,0 +1,21 @@
apiVersion: kyverno.io/v2alpha1
kind: PolicyException
metadata:
name: label-exception
namespace: default
spec:
exceptions:
- policyName: require-app-label
ruleNames:
- require-app-label
match:
any:
- resources:
kinds:
- Pod
- Deployment
namespaces:
- default
selector:
matchLabels:
app: my-test-app

View file

@ -0,0 +1,10 @@
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: my-test-app
spec:
containers:
- name: nginx
image: nginx