-
Notifications
You must be signed in to change notification settings - Fork 314
/
query.rego
66 lines (52 loc) · 2.48 KB
/
query.rego
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package Cx
import data.generic.k8s as k8sLib
import data.generic.common as common_lib
types := {"initContainers", "containers"}
CxPolicy[result] {
document := input.document[i]
specInfo := k8sLib.getSpecInfo(document)
metadata := document.metadata
containers := specInfo.spec[types[x]]
not common_lib.valid_key(containers[index].resources.requests, "cpu")
result := {
"documentId": input.document[i].id,
"resourceType": document.kind,
"resourceName": metadata.name,
"issueType": "MissingAttribute",
"searchKey": sprintf("metadata.name={{%s}}.%s.%s.name={{%s}}.resources.requests", [metadata.name, specInfo.path, types[x], containers[index].name]),
"keyExpectedValue": sprintf("%s.%s.name={{%s}}.resources.requests should have CPU requests", [specInfo.path, types[x], containers[index].name]),
"keyActualValue": sprintf("%s.%s.name={{%s}}.resources.requests doesn't have CPU requests", [specInfo.path, types[x], containers[index].name]),
}
}
CxPolicy[result] {
document := input.document[i]
specInfo := k8sLib.getSpecInfo(document)
metadata := document.metadata
containers := specInfo.spec[types[x]]
not common_lib.valid_key(containers[index].resources, "requests")
result := {
"documentId": input.document[i].id,
"resourceType": document.kind,
"resourceName": metadata.name,
"issueType": "MissingAttribute",
"searchKey": sprintf("metadata.name={{%s}}.%s.%s.name={{%s}}.resources", [metadata.name, specInfo.path, types[x], containers[index].name]),
"keyExpectedValue": sprintf("%s.%s.name=%s.resources should have requests defined", [specInfo.path, types[x], containers[index].name]),
"keyActualValue": sprintf("%s.%s.name=%s.resources doesn't have requests defined", [specInfo.path, types[x], containers[index].name]),
}
}
CxPolicy[result] {
document := input.document[i]
specInfo := k8sLib.getSpecInfo(document)
metadata := document.metadata
containers := specInfo.spec[types[x]]
not common_lib.valid_key(containers[index], "resources")
result := {
"documentId": input.document[i].id,
"resourceType": document.kind,
"resourceName": metadata.name,
"issueType": "MissingAttribute",
"searchKey": sprintf("metadata.name={{%s}}.%s.%s.name=%s", [metadata.name, specInfo.path, types[x], containers[index].name]),
"keyExpectedValue": sprintf("%s.%s.name=%s should have resources defined", [specInfo.path, types[x], containers[index].name]),
"keyActualValue": sprintf("%s.%s.name=%s doesn't have resources defined", [specInfo.path, types[x], containers[index].name]),
}
}