Skip to content

Commit 309f02d

Browse files
committed
fixup: match_lables only worked if both pdb and controller used matchLabels
1 parent ee59028 commit 309f02d

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,26 @@ not_valid_pdb_max_unavailable(pdb) {
115115

116116
# Check one podDisruptionBudget and pod(controller), returns true if it does not match
117117
mismatched_selector(pdb, obj) = res {
118-
r1 := match_labels(pdb, obj)
119-
r2 := match_expressions_exists(pdb, obj)
120-
r3 := match_expressions_does_not_exist(pdb, obj)
121-
r4 := any(match_expressions_in(pdb, obj))
122-
r5 := any(match_expressions_not_in(pdb, obj))
118+
r1 := matchLabelsMissingKeys(pdb, obj)
119+
r2 := any(matchLabelsValues(pdb, obj))
120+
r3 := match_expressions_exists(pdb, obj)
121+
r4 := match_expressions_does_not_exist(pdb, obj)
122+
r5 := any(match_expressions_in(pdb, obj))
123+
r6 := any(match_expressions_not_in(pdb, obj))
123124
# Return true if any part of the podDisruptionBudget and pod(controller) does not match
124-
res := any({r1, r2, r3, r4, r5})
125+
res := any({r1, r2, r3, r4, r5, r6})
125126
}
126127

127-
match_labels(pdb, obj) = res {
128-
pdb_match_labels := { [label, value] | some label; value := pdb.spec.selector.matchLabels[label] }
129-
obj_match_labels := { [label, value] | some label; value := obj.spec.selector.matchLabels[label] }
130-
res := count(pdb_match_labels - obj_match_labels) != 0
128+
matchLabelsMissingKeys(pdb, obj) = res {
129+
res3 := {key | pdb.spec.selector.matchLabels[key]}
130+
res4 := {key | get_labels(obj)[key]}
131+
res := count(res3 - res4) != 0
132+
}
133+
134+
matchLabelsValues(pdb, obj) = res {
135+
res := [x |
136+
get_labels(obj)[key1] != pdb.spec.selector.matchLabels[key3];
137+
x := key1 == key3]
131138
}
132139

133140
match_expressions_exists(pdb, obj) = res {

0 commit comments

Comments
 (0)