Skip to content

Commit 5ed280a

Browse files
committed
feat: support topologySpreadConstraints in helm chart
- adding support for topologySpreadConstraints to allow configuring different topology strategies in OPA deployments
1 parent 69e3d09 commit 5ed280a

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed

charts/opa-kube-mgmt/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,5 @@ spec:
292292
{{ toYaml .Values.nodeSelector | indent 8 }}
293293
tolerations:
294294
{{ toYaml .Values.tolerations | indent 8 }}
295+
topologySpreadConstraints:
296+
{{ toYaml .Values.topologySpreadConstraints | indent 8 }}

charts/opa-kube-mgmt/values.schema.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,65 @@
4646
"default": null
4747
}
4848
}
49+
},
50+
"topologySpreadConstraints": {
51+
"type": "array",
52+
"items": {
53+
"type": "object",
54+
"required": ["maxSkew", "topologyKey", "whenUnsatisfiable"],
55+
"properties": {
56+
"maxSkew": {
57+
"type": "integer",
58+
"minimum": 1
59+
},
60+
"topologyKey": {
61+
"type": "string",
62+
"minLength": 1
63+
},
64+
"whenUnsatisfiable": {
65+
"type": "string",
66+
"enum": ["DoNotSchedule", "ScheduleAnyway"]
67+
},
68+
"labelSelector": {
69+
"type": "object",
70+
"properties": {
71+
"matchLabels": {
72+
"type": "object",
73+
"additionalProperties": {"type": "string"}
74+
},
75+
"matchExpressions": {
76+
"type": "array",
77+
"items": {
78+
"type": "object",
79+
"required": ["key", "operator"],
80+
"properties": {
81+
"key": {"type": "string"},
82+
"operator": {"type": "string", "enum": ["In", "NotIn", "Exists", "DoesNotExist"]},
83+
"values": {"type": "array", "items": {"type": "string"}}
84+
}
85+
}
86+
}
87+
}
88+
},
89+
"matchLabelKeys": {
90+
"type": "array",
91+
"items": {"type": "string"}
92+
},
93+
"minDomains": {
94+
"type": "integer",
95+
"minimum": 1
96+
},
97+
"nodeAffinityPolicy": {
98+
"type": "string",
99+
"enum": ["Honor", "Ignore"]
100+
},
101+
"nodeTaintsPolicy": {
102+
"type": "string",
103+
"enum": ["Honor", "Ignore"]
104+
}
105+
}
106+
},
107+
"default": []
49108
}
50109
}
51110
}

charts/opa-kube-mgmt/values.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ affinity: {}
219219
tolerations: []
220220
nodeSelector: {}
221221

222+
# To control pod distribution across topology domains, set topologySpreadConstraints
223+
# below.
224+
#
225+
# topologySpreadConstraints:
226+
# - maxSkew: 1
227+
# topologyKey: topology.kubernetes.io/zone
228+
# whenUnsatisfiable: DoNotSchedule
229+
# labelSelector:
230+
# matchLabels:
231+
# app: opa
232+
topologySpreadConstraints: []
233+
222234
# To control the CPU and memory resource limits and requests for OPA, set the
223235
# field below.
224236
resources: {}

test/lint/tsc.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
suite: lint topologySpreadConstraints
2+
templates:
3+
- tsc.yaml
4+
tests:
5+
- it: topologySpreadConstraints missing required fields
6+
set:
7+
pod:
8+
topologySpreadConstraints:
9+
- maxSkew: null # Invalid value
10+
asserts:
11+
- failedTemplate:
12+
errorPattern: "topologySpreadConstraints.maxSkew is required and must be a valid integer"
13+
14+
- it: topologySpreadConstraints invalid values
15+
set:
16+
pod:
17+
topologySpreadConstraints:
18+
- maxSkew: 1
19+
topologyKey: ""
20+
whenUnsatisfiable: "InvalidOption"
21+
asserts:
22+
- failedTemplate:
23+
errorMessage: |
24+
values don't meet the specifications of the schema(s):
25+
- topologySpreadConstraints.topologyKey: topologyKey cannot be empty
26+
- topologySpreadConstraints.whenUnsatisfiable: whenUnsatisfiable must be one of the following: "DoNotSchedule", "ScheduleAnyway"
27+
28+
- it: valid topologySpreadConstraints
29+
set:
30+
pod:
31+
topologySpreadConstraints:
32+
- maxSkew: 1
33+
topologyKey: "topology.kubernetes.io/zone"
34+
whenUnsatisfiable: "DoNotSchedule"
35+
labelSelector:
36+
matchLabels:
37+
app: "opa"
38+
asserts:
39+
- renderedTemplateContains:
40+
text: |
41+
topologySpreadConstraints:
42+
- maxSkew: 1
43+
topologyKey: topology.kubernetes.io/zone
44+
whenUnsatisfiable: DoNotSchedule
45+
labelSelector:
46+
matchLabels:
47+
app: "opa"

test/unit/tsc.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
suite: test topologySpreadConstraints
2+
templates:
3+
- tsc.yaml
4+
tests:
5+
- it: should omit topologySpreadConstraints by default
6+
asserts:
7+
- notExists:
8+
path: spec.template.spec.topologySpreadConstraints
9+
- it: should omit topologySpreadConstraints when null
10+
set:
11+
service.topologySpreadConstraints: null
12+
asserts:
13+
- notExists:
14+
path: spec.template.spec.topologySpreadConstraints
15+
- it: should set topologySpreadConstraints
16+
set:
17+
service.topologySpreadConstraints:
18+
- maxSkew: 1
19+
topologyKey: topology.kubernetes.io/zone
20+
whenUnsatisfiable: DoNotSchedule
21+
labelSelector:
22+
matchLabels:
23+
app: opa
24+
asserts:
25+
- exists:
26+
path: spec.template.spec.topologySpreadConstraints[0]
27+
- equal:
28+
path: spec.template.spec.topologySpreadConstraints[0].maxSkew
29+
value: 1
30+
- equal:
31+
path: spec.template.spec.topologySpreadConstraints[0].topologyKey
32+
value: topology.kubernetes.io/zone
33+
- equal:
34+
path: spec.template.spec.topologySpreadConstraints[0].whenUnsatisfiable
35+
value: DoNotSchedule
36+
- exists:
37+
path: spec.template.spec.topologySpreadConstraints[0].labelSelector.matchLabels.app
38+
- equal:
39+
path: spec.template.spec.topologySpreadConstraints[0].labelSelector.matchLabels.app
40+
value: opa

0 commit comments

Comments
 (0)