Skip to content

Commit b030bb2

Browse files
committed
feat(cluster): Adding topologySpreadConstraints support to the cluster
This adds support for specifying [`topologySpreadConstraints`](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/) for the cloudnative-pg cluster. Resolves [#817](#817) Signed-off-by: Miquel Puig Mena <miquel@cala.ai>
1 parent b32ac3d commit b030bb2

4 files changed

Lines changed: 74 additions & 0 deletions

File tree

charts/cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat
151151
| backups.wal.maxParallel | int | `1` | Number of WAL files to be archived or restored in parallel. |
152152
| cluster.additionalLabels | object | `{}` | |
153153
| cluster.affinity | object | `{"topologyKey":"topology.kubernetes.io/zone"}` | Affinity/Anti-affinity rules for Pods. See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-AffinityConfiguration |
154+
| cluster.topologySpreadConstraints | list | `[]` | TopologySpreadConstraints rules for the cluster. See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#ClusterSpec |
154155
| cluster.annotations | object | `{}` | |
155156
| cluster.certificates | object | `{}` | The configuration for the CA and related certificates. See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-CertificatesConfiguration |
156157
| cluster.console.enabled | bool | `false` | Deploys a console StatefulSet to run long-running commands against the cluster (e.g. `CREATE INDEX`). |

charts/cluster/templates/cluster.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ spec:
4242
affinity:
4343
{{- toYaml . | nindent 4 }}
4444
{{- end }}
45+
{{- with .Values.cluster.topologySpreadConstraints }}
46+
topologySpreadConstraints:
47+
{{- toYaml . | nindent 4 }}
48+
{{- end }}
4549
{{- with .Values.cluster.env }}
4650
env:
4751
{{- toYaml . | nindent 4 }}

charts/cluster/values.schema.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,65 @@
181181
}
182182
}
183183
},
184+
"topologySpreadConstraints": {
185+
"type": "array",
186+
"items": {
187+
"type": "object",
188+
"properties": {
189+
"maxSkew": {
190+
"type": "integer"
191+
},
192+
"minDomains": {
193+
"type": "integer"
194+
},
195+
"topologyKey": {
196+
"type": "string"
197+
},
198+
"whenUnsatisfiable": {
199+
"type": "string"
200+
},
201+
"labelSelector": {
202+
"type": "object",
203+
"properties": {
204+
"matchLabels": {
205+
"type": "object"
206+
},
207+
"matchExpressions": {
208+
"type": "array",
209+
"items": {
210+
"type": "object",
211+
"properties": {
212+
"key": {
213+
"type": "string"
214+
}
215+
}
216+
}
217+
}
218+
}
219+
},
220+
"matchLabelKeys": {
221+
"type": "array",
222+
"items": {
223+
"type": "string"
224+
}
225+
},
226+
"nodeAffinityPolicy": {
227+
"type": "string",
228+
"enum": [
229+
"Honor",
230+
"Ignore"
231+
]
232+
},
233+
"nodeTaintsPolicy": {
234+
"type": "string",
235+
"enum": [
236+
"Honor",
237+
"Ignore"
238+
]
239+
}
240+
}
241+
}
242+
},
184243
"annotations": {
185244
"type": "object"
186245
},

charts/cluster/values.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ cluster:
249249
affinity:
250250
topologyKey: topology.kubernetes.io/zone
251251

252+
# -- TopologySpreadConstraints for cluster.
253+
# See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#ClusterSpec
254+
topologySpreadConstraints: []
255+
# - maxSkew: 1
256+
# topologyKey: topology.kubernetes.io/zone
257+
# whenUnsatisfiable: DoNotSchedule
258+
# labelSelector:
259+
# matchLabels:
260+
# cnpg.io/cluster: my-cluster
261+
252262
# -- Env follows the Env format to pass environment variables to the pods created in the cluster
253263
env: []
254264
# - name: MY_CUSTOM_FLAG

0 commit comments

Comments
 (0)