1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-30 19:35:06 +00:00

update validation logic

This commit is contained in:
shivkumar dudhani 2019-09-28 14:09:46 -07:00
parent ae3059b858
commit 808cccb421
12 changed files with 20 additions and 17 deletions

View file

@ -11,7 +11,7 @@ spec:
- Pod
validate:
message: "A none 'default' namespace is required"
anyPattern:
pattern:
- metadata:
namespace: "!default"
- name: check-namespace-exist
@ -21,6 +21,6 @@ spec:
- Pod
validate:
message: "A namespace is required"
anyPattern:
pattern:
- metadata:
namespace: "?*"

View file

@ -14,6 +14,5 @@ spec:
pattern:
spec:
volumes:
- name: "*"
(hostPath):
- (hostPath):
path: "!/var/lib"

View file

@ -15,7 +15,7 @@ spec:
- Pod
validate:
message: "Disallow use of host's pid namespace and host's ipc namespace"
anyPattern:
pattern:
- spec:
hostPID: false
hostIPC: false

View file

@ -14,5 +14,5 @@ spec:
pattern:
spec:
containers:
- ^(image): "*:latest"
- (image): "*:latest"
imagePullPolicy: "!IfNotPresent"

View file

@ -15,7 +15,7 @@ spec:
- Pod
validate:
message: "Container should not have read-only rootfilesystem"
anyPattern:
pattern:
- spec:
container:
- securityContext:

View file

@ -14,7 +14,7 @@ spec:
pattern:
spec:
containers:
- ^(name): "check-readiness"
- (name): "check-readiness"
readinessProbe:
successThreshold: ">1"
- name: check-livenessProbe-exists
@ -27,7 +27,7 @@ spec:
pattern:
spec:
containers:
- ^(name): "check-liveness"
- (name): "check-liveness"
livenessProbe:
httpGet:
path: "?*"

View file

@ -18,7 +18,7 @@ spec :
pattern:
spec:
containers:
- ^(name): "*"
- (name): "*"
resources:
requests:
memory: "$(<=./../../lim(its/mem)ory)"

View file

@ -197,8 +197,13 @@ func validateMap(resourceMap, patternMap map[string]interface{}, origPattern int
// - Existance
handler := CreateElementHandler(key, patternElement, path)
handlerPath, err := handler.Handle(resourceMap, origPattern)
// if there are resource values at same level, then anchor acts as conditional instead of a strict check
// but if there are non then its a if then check
if err != nil {
return handlerPath, err
if len(resources) == 0 {
return handlerPath, err
}
return "", nil
}
}
// Evaluate resources

View file

@ -2197,7 +2197,6 @@ func TestValidate_anchor_arraymap_fail(t *testing.T) {
"spec": {
"volumes": [
{
"name": "*",
"(hostPath)": {
"path": "!/var/lib"
}

View file

@ -16,10 +16,10 @@ expected:
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/"
message: Validation rule 'check-default-namespace' failed at '/' for resource Pod/default/myapp-pod. A none 'default' namespace is required
success: false
- name: check-namespace-exist
type: Validation
message: "Validation rule 'check-namespace-exist' anyPattern[0] succesfully validated"
success: true
message: Validation rule 'check-namespace-exist' failed at '/' for resource Pod/default/myapp-pod. A namespace is required
success: false

View file

@ -14,5 +14,5 @@ expected:
rules:
- name: validate-hostpid-hostipc
type: Validation
message: Validation rule 'validate-hostpid-hostipc' failed to validate patterns defined in anyPattern. Disallow use of host's pid namespace and host's ipc namespace; anyPattern[0] failed at path /spec/hostIPC/
message: Validation rule 'validate-hostpid-hostipc' failed at '/' for resource Pod//nginx-with-hostpid. Disallow use of host's pid namespace and host's ipc namespace
success: false

View file

@ -14,5 +14,5 @@ expected:
rules:
- name: validate-not-readonly-rootfilesystem
type: Validation
message: Validation rule 'validate-not-readonly-rootfilesystem' failed to validate patterns defined in anyPattern. Container should not have read-only rootfilesystem; anyPattern[0] failed at path /spec/container/
message: Validation rule 'validate-not-readonly-rootfilesystem' failed at '/' for resource Pod//ghost-with-readonly-rootfilesystem. Container should not have read-only rootfilesystem
success: false