Skip to content

Commit ee59028

Browse files
committed
fixup: some cleanup while testing and one more todo
1 parent e0b87d9 commit ee59028

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

helmfile.d/charts/gatekeeper/templates/policies/restrict-pod-disruption-budgets.rego

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package k8srestrictpoddisruptionbudgets
22

33
# Reject PDB if maxUnavailable does not allow at least 1 pod disruption
44
violation[{"msg": msg}] {
5-
input.review.kind.kind == "PodDisruptionBudget"
5+
input.review.object.kind == "PodDisruptionBudget"
66
pdb := input.review.object
77

88
pdb.spec.maxUnavailable
@@ -17,11 +17,12 @@ violation[{"msg": msg}] {
1717

1818
# Reject PDB if minAvailable does not allow at least 1 pod disruption
1919
violation[{"msg": msg}] {
20-
input.review.kind.kind == "PodDisruptionBudget"
20+
input.review.object.kind == "PodDisruptionBudget"
2121
pdb := input.review.object
2222

2323
pdb.spec.minAvailable
2424

25+
# TODO add support for replicationcontroller group "v1" and restrict to just the four kinds
2526
objs := [controllers | controllers := data.inventory.namespace[pdb.metadata.namespace]["apps/v1"][_]]
2627
obj := objs[_][_]
2728

@@ -30,7 +31,6 @@ violation[{"msg": msg}] {
3031
not_valid_pdb_min_available(obj, pdb)
3132
not replica_set_under_deployment(obj)
3233

33-
keys := [key | data.inventory.namespace[pdb.metadata.namespace]["apps/v1"][key]]
3434
msg := sprintf(
3535
"PodDisruptionBudget rejected: %v <%v> has %v replica(s) but PodDisruptionBudget <%v> has minAvailable of %v, minAvailable should always be lower than replica(s), and not used when replica(s) is set to 1.",
3636
[obj.kind, obj.metadata.name, obj.spec.replicas, pdb.metadata.name, pdb.spec.minAvailable],
@@ -39,7 +39,7 @@ violation[{"msg": msg}] {
3939

4040
# Reject pod controller if connected PDBs maxUnavailable does not allow at least 1 pod disruption
4141
violation[{"msg": msg}] {
42-
input.review.kind.kind == podControllerKinds[_]
42+
input.review.object.kind == podControllerKinds[_]
4343
obj := input.review.object
4444
not replica_set_under_deployment(obj)
4545

@@ -58,7 +58,7 @@ violation[{"msg": msg}] {
5858

5959
# Reject pod controller if connected PDBs minAvailable does not allow at least 1 pod disruption
6060
violation[{"msg": msg}] {
61-
input.review.kind.kind == podControllerKinds[_]
61+
input.review.object.kind == podControllerKinds[_]
6262
obj := input.review.object
6363
not replica_set_under_deployment(obj)
6464

0 commit comments

Comments
 (0)