fix(etcd): require an even spread of members over nodes by default

The default spread of the etcd members was ScheduleAnyway, which only
adds to the score of a node, and other scores can outweigh it. A new
etcd on a three-node cluster got its first two members on one node.
On a node-local StorageClass a member cannot leave its node, so losing
that node takes two of the three members and the quorum.

DoNotSchedule with maxSkew 1 still lets an etcd with more members than
nodes start, because the skew is counted between the nodes that exist.
One node takes all three members and two nodes take two and one.
nodeTaintsPolicy is Ignore, so a cordoned node still counts and a
member waits for it instead of landing next to another member.

The operator copies the constraints into an EtcdMember when it creates
it and builds the Pod from that copy, so members that exist keep the
old setting and only members created later get the new one.

Assisted-by: LLM
Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
This commit is contained in:
Yan Bondarenko committed 2026-10-20 12:05:51 +03:00
1 parent aed7fa896e
commit f1f30b3071
2 files changed
+37 -12

No files matched your search

@@ -69,7 +69,8 @@ spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: "kubernetes.io/hostname"
whenUnsatisfiable: ScheduleAnyway
whenUnsatisfiable: DoNotSchedule
nodeTaintsPolicy: Ignore
labelSelector:
matchLabels:
app.kubernetes.io/instance: etcd
@@ -8,7 +8,7 @@ templates:
- templates/etcd-cluster.yaml
tests:
- it: uses a soft per-host spread by default
- it: uses a strict per-host spread by default
set:
_cluster: {}
documentSelector:
@@ -16,17 +16,41 @@ tests:
value: EtcdCluster
asserts:
- equal:
path: spec.topologySpreadConstraints[0].maxSkew
value: 1
path: spec.topologySpreadConstraints[0]
value:
maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
nodeTaintsPolicy: Ignore
labelSelector:
matchLabels:
app.kubernetes.io/instance: etcd
- lengthEqual:
path: spec.topologySpreadConstraints
count: 1
- it: renders a soft cluster-wide spread policy as written
set:
_cluster:
scheduling:
globalAppTopologySpreadConstraints: |
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
documentSelector:
path: kind
value: EtcdCluster
asserts:
- equal:
path: spec.topologySpreadConstraints[0].topologyKey
value: kubernetes.io/hostname
- equal:
path: spec.topologySpreadConstraints[0].whenUnsatisfiable
value: ScheduleAnyway
- equal:
path: spec.topologySpreadConstraints[0].labelSelector.matchLabels["app.kubernetes.io/instance"]
value: etcd
path: spec.topologySpreadConstraints[0]
value:
maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/instance: etcd
- lengthEqual:
path: spec.topologySpreadConstraints
count: 1