mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
add require_probes.yaml
This commit is contained in:
parent
ea25ed8460
commit
3e1ef320a8
5 changed files with 57 additions and 2 deletions
|
@ -10,8 +10,8 @@
|
||||||
| Require read only root filesystem | [policy_validate_not_readonly_rootfilesystem.yaml](policy_validate_not_readonly_rootfilesystem.yaml) | best_practices |
|
| Require read only root filesystem | [policy_validate_not_readonly_rootfilesystem.yaml](policy_validate_not_readonly_rootfilesystem.yaml) | best_practices |
|
||||||
| Disallow node ports | [policy_validate_disallow_node_port.yaml](policy_validate_disallow_node_port.yaml) | best_practices |
|
| Disallow node ports | [policy_validate_disallow_node_port.yaml](policy_validate_disallow_node_port.yaml) | best_practices |
|
||||||
| Allow trusted registries | [policy_validate_whitelist_image_registries.yaml](policy_validate_whitelist_image_registries.yaml) |
|
| Allow trusted registries | [policy_validate_whitelist_image_registries.yaml](policy_validate_whitelist_image_registries.yaml) |
|
||||||
| Require resource requests and limits | [policy_validate_pod_resources.yaml](policy_validate_pod_resources.yaml) |
|
| Require resource requests and limits | [policy_validate_pod_resources.yaml](policy_validate_pod_resources.yaml) | best_practices |
|
||||||
| Require pod liveness and readiness probes | [policy_validate_pod_probes.yaml](policy_validate_pod_probes.yaml) |
|
| Require pod liveness and readiness probes | [policy_validate_pod_probes.yaml](policy_validate_pod_probes.yaml) | best_practices |
|
||||||
| Require an image tag | [policy_validate_image_tag_notspecified_deny.yaml](policy_validate_image_tag_notspecified_deny.yaml) |
|
| Require an image tag | [policy_validate_image_tag_notspecified_deny.yaml](policy_validate_image_tag_notspecified_deny.yaml) |
|
||||||
| Disallow latest tag and pull IfNotPresent | [policy_validate_image_latest_ifnotpresent_deny.yaml](policy_validate_image_latest_ifnotpresent_deny.yaml) |
|
| Disallow latest tag and pull IfNotPresent | [policy_validate_image_latest_ifnotpresent_deny.yaml](policy_validate_image_latest_ifnotpresent_deny.yaml) |
|
||||||
| Require a namespace (disallow default) | [policy_validate_default_namespace.yaml](policy_validate_default_namespace.yaml) |
|
| Require a namespace (disallow default) | [policy_validate_default_namespace.yaml](policy_validate_default_namespace.yaml) |
|
||||||
|
|
|
@ -143,3 +143,7 @@ func Test_validate_whitelist_image_registries(t *testing.T) {
|
||||||
func Test_require_pod_requests_limits(t *testing.T) {
|
func Test_require_pod_requests_limits(t *testing.T) {
|
||||||
testScenario(t, "test/scenarios/test/scenario_validate_require_pod_requests_limits.yaml")
|
testScenario(t, "test/scenarios/test/scenario_validate_require_pod_requests_limits.yaml")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_require_probes(t *testing.T) {
|
||||||
|
testScenario(t, "test/scenarios/test/scenario_validate_probes.yaml")
|
||||||
|
}
|
||||||
|
|
21
samples/best_practices/require_probes.yaml
Normal file
21
samples/best_practices/require_probes.yaml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
apiVersion: kyverno.io/v1alpha1
|
||||||
|
kind: ClusterPolicy
|
||||||
|
metadata:
|
||||||
|
name: validate-probes
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- name: check-probes
|
||||||
|
match:
|
||||||
|
resources:
|
||||||
|
kinds:
|
||||||
|
- Pod
|
||||||
|
validate:
|
||||||
|
message: "Liveness and readiness probes are required"
|
||||||
|
pattern:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- livenessProbe:
|
||||||
|
periodSeconds: ">0"
|
||||||
|
readinessProbe:
|
||||||
|
periodSeconds: ">0"
|
||||||
|
|
12
test/manifest/require_probes.yaml
Normal file
12
test/manifest/require_probes.yaml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: myapp-pod
|
||||||
|
labels:
|
||||||
|
app: myapp
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: nginx
|
||||||
|
image: nginx
|
||||||
|
readinessProbe:
|
||||||
|
periodSeconds: 5
|
18
test/scenarios/test/scenario_validate_probes.yaml
Normal file
18
test/scenarios/test/scenario_validate_probes.yaml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# file path relative to project root
|
||||||
|
input:
|
||||||
|
policy: samples/best_practices/require_probes.yaml
|
||||||
|
resource: test/manifest/require_probes.yaml
|
||||||
|
expected:
|
||||||
|
validation:
|
||||||
|
policyresponse:
|
||||||
|
policy: validate-probes
|
||||||
|
resource:
|
||||||
|
kind: Pod
|
||||||
|
apiVersion: v1
|
||||||
|
namespace: ''
|
||||||
|
name: myapp-pod
|
||||||
|
rules:
|
||||||
|
- name: check-probes
|
||||||
|
type: Validation
|
||||||
|
message: Validation rule 'check-probes' failed at '/spec/containers/0/livenessProbe/' for resource Pod//myapp-pod. Liveness and readiness probes are required
|
||||||
|
success: false
|
Loading…
Add table
Reference in a new issue