-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathkubernetes.Rule.ps1
43 lines (37 loc) · 1.52 KB
/
kubernetes.Rule.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#
# Validation rules for Kubernetes resources
#
# Description: Must have the app.kubernetes.io/name label
Rule 'metadata.Name' -Type 'Deployment', 'Service' {
Exists "metadata.labels.'app.kubernetes.io/name'"
}
# Description: Must have the app.kubernetes.io/version label
Rule 'metadata.Version' -Type 'Deployment', 'Service' {
Exists 'metadata.labels.''app.kubernetes.io/version'''
}
# Description: Must have the app.kubernetes.io/component label
Rule 'metadata.Component' -Type 'Deployment', 'Service' {
Exists 'metadata.labels.''app.kubernetes.io/component'''
Within 'metadata.labels.''app.kubernetes.io/component''' 'web', 'api', 'database', 'gateway' -CaseSensitive
}
# Description: Deployments use a minimum of 2 replicas
Rule 'deployment.HasMinimumReplicas' -Type 'Deployment' {
Exists 'spec.replicas'
$TargetObject.spec.replicas -ge 2
}
# Description: Deployments use specific tags
Rule 'deployment.NotLatestImage' -Type 'Deployment' {
foreach ($container in $TargetObject.spec.template.spec.containers) {
$container.image -like '*:*' -and
$container.image -notlike '*:latest'
}
}
# Description: Resource requirements are set for each container
Rule 'deployment.ResourcesSet' -Type 'Deployment' {
foreach ($container in $TargetObject.spec.template.spec.containers) {
$container | Exists 'resources.requests.cpu'
$container | Exists 'resources.requests.memory'
$container | Exists 'resources.limits.cpu'
$container | Exists 'resources.limits.memory'
}
}