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:
parent
696c7e924b
commit
942814e942
9 changed files with 84 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
apiVersion: kuttl.dev/v1beta1
|
||||
kind: TestStep
|
||||
apply:
|
||||
- policy.yaml
|
||||
assert:
|
||||
- policy-assert.yaml
|
|
@ -0,0 +1,4 @@
|
|||
apiVersion: kuttl.dev/v1beta1
|
||||
kind: TestStep
|
||||
apply:
|
||||
- policy_exception.yaml
|
|
@ -0,0 +1,5 @@
|
|||
apiVersion: kuttl.dev/v1beta1
|
||||
kind: TestStep
|
||||
apply:
|
||||
- file: resource.yaml
|
||||
shouldFail: true
|
|
@ -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.
|
|
@ -0,0 +1,9 @@
|
|||
apiVersion: kyverno.io/v1
|
||||
kind: ClusterPolicy
|
||||
metadata:
|
||||
name: require-app-label
|
||||
status:
|
||||
conditions:
|
||||
- reason: Succeeded
|
||||
status: "True"
|
||||
type: Ready
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,10 @@
|
|||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: my-pod
|
||||
labels:
|
||||
app: my-test-app
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
Loading…
Add table
Reference in a new issue