mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 19:05:27 +00:00
add validate_namespace test runner
This commit is contained in:
parent
d92026f94a
commit
b494dec7f3
4 changed files with 40 additions and 2 deletions
examples/best_practices
pkg/testrunner
test/scenarios/test
|
@ -5,6 +5,16 @@ metadata:
|
|||
spec:
|
||||
rules:
|
||||
- name: check-default-namespace
|
||||
match:
|
||||
resources:
|
||||
kinds:
|
||||
- Pod
|
||||
validate:
|
||||
message: "A none 'default' namespace is required"
|
||||
anyPattern:
|
||||
- metadata:
|
||||
namespace: "!default"
|
||||
- name: check-namespace-exist
|
||||
match:
|
||||
resources:
|
||||
kinds:
|
||||
|
@ -14,5 +24,3 @@ spec:
|
|||
anyPattern:
|
||||
- metadata:
|
||||
namespace: "?*"
|
||||
- metadata:
|
||||
namespace: "!default"
|
||||
|
|
|
@ -2,6 +2,7 @@ apiVersion: v1
|
|||
kind: Pod
|
||||
metadata:
|
||||
name: myapp-pod
|
||||
namespace: default
|
||||
labels:
|
||||
app: myapp
|
||||
spec:
|
||||
|
|
|
@ -79,3 +79,7 @@ func Test_validate_image_tag_latest_pass(t *testing.T) {
|
|||
func Test_mutate_pod_disable_automoutingapicred_pass(t *testing.T) {
|
||||
testScenario(t, "test/scenarios/test/scenario_mutate_pod_disable_automountingapicred.yaml")
|
||||
}
|
||||
|
||||
func Test_validate_default_namespace(t *testing.T) {
|
||||
testScenario(t, "test/scenarios/test/scenario_validate_default_namespace.yaml")
|
||||
}
|
||||
|
|
25
test/scenarios/test/scenario_validate_default_namespace.yaml
Normal file
25
test/scenarios/test/scenario_validate_default_namespace.yaml
Normal file
|
@ -0,0 +1,25 @@
|
|||
# file path relative to project root
|
||||
input:
|
||||
policy: examples/best_practices/policy_validate_default_namespace.yaml
|
||||
resource: examples/best_practices/resources/resource_default_namespace.yaml
|
||||
expected:
|
||||
validation:
|
||||
policyresponse:
|
||||
policy: validate-namespace
|
||||
resource:
|
||||
kind: Pod
|
||||
apiVersion: v1
|
||||
# this is set to pass resource NS check
|
||||
# actual valiation is defined through rule success=false
|
||||
namespace: 'default'
|
||||
name: myapp-pod
|
||||
rules:
|
||||
- name: check-default-namespace
|
||||
type: Validation
|
||||
message: "Validation rule 'check-default-namespace' failed to validate patterns defined in anyPattern. A none 'default' namespace is required; anyPattern[0] failed at path /metadata/namespace/"
|
||||
success: false
|
||||
- name: check-namespace-exist
|
||||
type: Validation
|
||||
message: "Validation rule 'check-namespace-exist' anyPattern[0] succesfully validated"
|
||||
success: true
|
||||
|
Loading…
Add table
Reference in a new issue