mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
Add additional e2e tests for 'kyverno test'
Signed-off-by: Trey Dockendorf <tdockendorf@osc.edu>
This commit is contained in:
parent
00b8da9219
commit
db4fec0eeb
8 changed files with 139 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
name: test
|
||||
name: test-simple
|
||||
policies:
|
||||
- policy.yaml
|
||||
resources:
|
25
test/cli/test/variables/cm-array-example.yaml
Normal file
25
test/cli/test/variables/cm-array-example.yaml
Normal file
|
@ -0,0 +1,25 @@
|
|||
apiVersion: kyverno.io/v1
|
||||
kind: ClusterPolicy
|
||||
metadata:
|
||||
name: cm-array-example
|
||||
spec:
|
||||
validationFailureAction: enforce
|
||||
background: false
|
||||
rules:
|
||||
- name: validate-role-annotation
|
||||
context:
|
||||
- name: roles-dictionary
|
||||
configMap:
|
||||
name: roles-dictionary
|
||||
namespace: default
|
||||
match:
|
||||
resources:
|
||||
kinds:
|
||||
- Pod
|
||||
validate:
|
||||
message: "The role {{ request.object.metadata.annotations.role }} is not in the allowed list of roles: {{ \"roles-dictionary\".data.\"allowed-roles\" }}."
|
||||
deny:
|
||||
conditions:
|
||||
- key: "{{ request.object.metadata.annotations.role }}"
|
||||
operator: NotIn
|
||||
value: "{{ \"roles-dictionary\".data.\"allowed-roles\" }}"
|
21
test/cli/test/variables/cm-variable-example.yaml
Normal file
21
test/cli/test/variables/cm-variable-example.yaml
Normal file
|
@ -0,0 +1,21 @@
|
|||
apiVersion: kyverno.io/v1
|
||||
kind: ClusterPolicy
|
||||
metadata:
|
||||
name: cm-variable-example
|
||||
spec:
|
||||
rules:
|
||||
- name: example-configmap-lookup
|
||||
context:
|
||||
- name: dictionary
|
||||
configMap:
|
||||
name: some-config-map
|
||||
namespace: some-namespace
|
||||
match:
|
||||
resources:
|
||||
kinds:
|
||||
- Pod
|
||||
validate:
|
||||
pattern:
|
||||
metadata:
|
||||
labels:
|
||||
my-environment-name: "{{dictionary.data.env}}"
|
43
test/cli/test/variables/resources.yaml
Normal file
43
test/cli/test/variables/resources.yaml
Normal file
|
@ -0,0 +1,43 @@
|
|||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-env-test
|
||||
labels:
|
||||
my-environment-name: test
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:latest
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-env-dev
|
||||
labels:
|
||||
my-environment-name: dev
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.12
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-web
|
||||
annotations:
|
||||
role: web
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:latest
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-app
|
||||
annotations:
|
||||
role: app
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.12
|
24
test/cli/test/variables/test.yaml
Normal file
24
test/cli/test/variables/test.yaml
Normal file
|
@ -0,0 +1,24 @@
|
|||
name: test-variables
|
||||
policies:
|
||||
- cm-variable-example.yaml
|
||||
- cm-array-example.yaml
|
||||
resources:
|
||||
- resources.yaml
|
||||
variables: variables.yaml
|
||||
results:
|
||||
- policy: cm-variable-example
|
||||
rule: example-configmap-lookup
|
||||
resource: test-env-test
|
||||
status: pass
|
||||
- policy: cm-variable-example
|
||||
rule: example-configmap-lookup
|
||||
resource: test-env-dev
|
||||
status: fail
|
||||
- policy: cm-array-example
|
||||
rule: validate-role-annotation
|
||||
resource: test-web
|
||||
status: fail
|
||||
- policy: cm-array-example
|
||||
rule: validate-role-annotation
|
||||
resource: test-app
|
||||
status: pass
|
25
test/cli/test/variables/variables.yaml
Normal file
25
test/cli/test/variables/variables.yaml
Normal file
|
@ -0,0 +1,25 @@
|
|||
policies:
|
||||
- name: cm-variable-example
|
||||
rules:
|
||||
- name: example-configmap-lookup
|
||||
values:
|
||||
dictionary.data.env: test
|
||||
resources:
|
||||
- name: test-env-test
|
||||
values:
|
||||
request.object.metadata.name: test-env-test
|
||||
- name: test-env-dev
|
||||
values:
|
||||
request.object.metadata.name: test-env-dev
|
||||
- name: cm-array-example
|
||||
rules:
|
||||
- name: validate-role-annotation
|
||||
values:
|
||||
roles-dictionary.data.allowed-roles: "[\"app\",\"test\"]"
|
||||
resources:
|
||||
- name: test-web
|
||||
values:
|
||||
request.object.metadata.annotations.role: web
|
||||
- name: test-app
|
||||
values:
|
||||
request.object.metadata.annotations.role: app
|
Loading…
Add table
Reference in a new issue