fix(monitoring): spread monitoring replicas over nodes

The VMCluster, VLCluster, VTCluster and VMAlertmanager the chart renders
carry no affinity and no topology spread, and vm-operator copies both
fields onto the pods as written without adding any of its own. Nothing in
those specs kept two replicas of one tier off the same node. With
replicationFactor 2 both copies of a series can then sit on one node, and
on a node-local class the volumes keep them there, so losing that node
loses both copies. A StatefulSet pod on a lost node is not replaced
elsewhere until its Pod or Node object is deleted, which holds for the
Alertmanager replicas without a volume as well.

The tiers that run as StatefulSets, vmstorage, vmselect, vlstorage,
vtstorage and the Alertmanager, now get a per-node spread with
whenUnsatisfiable DoNotSchedule and nodeTaintsPolicy Ignore. The tiers
that run as Deployments, vminsert, vlinsert, vlselect, vtinsert and
vtselect, get the same spread with ScheduleAnyway, since their pods are
replaced on another node without help. A platform that sets
scheduling.globalAppTopologySpreadConstraints gets that policy for every
tier instead, with the tier's own selector added to each constraint that
has none.

vm-operator rolls a changed StatefulSet one pod at a time. A replica on a
node-local volume whose peer shares its node cannot be placed again under
the new rule, so its new pod stays Pending and the rollout of that
cluster stops there until the replica is moved.

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 13:24:49 +03:00
1 parent aed7fa896e
commit a4cb00e6dd
6 files changed
+382

No files matched your search

@@ -0,0 +1,22 @@
{{- define "monitoring.topologySpreadConstraints" -}}
{{- $root := index . 0 -}}
{{- $selector := dict "matchLabels" (dict "app.kubernetes.io/name" (index . 1) "app.kubernetes.io/instance" (index . 2)) -}}
{{- $global := list -}}
{{- with ($root.Values._cluster | default dict).scheduling -}}
{{- with get . "globalAppTopologySpreadConstraints" -}}
{{- $global = dig "topologySpreadConstraints" (list) (fromYaml .) -}}
{{- end -}}
{{- end -}}
{{- $constraints := list -}}
{{- range $global -}}
{{- $constraints = append $constraints (ternary . (merge (dict "labelSelector" $selector) .) (hasKey . "labelSelector")) -}}
{{- end -}}
{{- if not $constraints -}}
{{- $default := dict "maxSkew" 1 "topologyKey" "kubernetes.io/hostname" "whenUnsatisfiable" (index . 3) "labelSelector" $selector -}}
{{- if eq (index . 3) "DoNotSchedule" -}}
{{- $_ := set $default "nodeTaintsPolicy" "Ignore" -}}
{{- end -}}
{{- $constraints = list $default -}}
{{- end -}}
{{- toYaml (dict "topologySpreadConstraints" $constraints) -}}
{{- end -}}
@@ -421,6 +421,7 @@ spec:
apps.cozystack.io/application.name: {{ $.Release.Name }}
replicaCount: {{ include "monitoring.alertmanager.replicas" $ }}
configSecret: alertmanager
{{- include "monitoring.topologySpreadConstraints" (list $ "vmalertmanager" "alertmanager" "DoNotSchedule") | nindent 2 }}
{{- if and $emailEnabled $email.authUsername }}
secrets:
- {{ $emailPasswordSecret | quote }}
@@ -22,13 +22,16 @@ spec:
apps.cozystack.io/application.name: {{ $.Release.Name }}
vlinsert:
replicaCount: 2
{{- include "monitoring.topologySpreadConstraints" (list $ "vlinsert" .name "ScheduleAnyway") | nindent 4 }}
resources: {}
vlselect:
replicaCount: 2
{{- include "monitoring.topologySpreadConstraints" (list $ "vlselect" .name "ScheduleAnyway") | nindent 4 }}
resources: {}
vlstorage:
retentionPeriod: {{ .retentionPeriod | quote }}
replicaCount: 2
{{- include "monitoring.topologySpreadConstraints" (list $ "vlstorage" .name "DoNotSchedule") | nindent 4 }}
resources: {}
storage:
volumeClaimTemplate:
@@ -18,9 +18,11 @@ spec:
# it's usually more than default 30
maxLabelsPerTimeseries: "60"
replicaCount: 2
{{- include "monitoring.topologySpreadConstraints" (list $ "vminsert" .name "ScheduleAnyway") | nindent 4 }}
resources: {}
vmselect:
replicaCount: 2
{{- include "monitoring.topologySpreadConstraints" (list $ "vmselect" .name "DoNotSchedule") | nindent 4 }}
resources: {}
extraArgs:
search.maxUniqueTimeseries: "600000"
@@ -46,6 +48,7 @@ spec:
storage: 2Gi
vmstorage:
replicaCount: 2
{{- include "monitoring.topologySpreadConstraints" (list $ "vmstorage" .name "DoNotSchedule") | nindent 4 }}
resources: {}
storage:
volumeClaimTemplate:
@@ -71,9 +71,11 @@ spec:
apps.cozystack.io/application.name: {{ $.Release.Name }}
insert:
replicaCount: 2
{{- include "monitoring.topologySpreadConstraints" (list $ "vtinsert" .name "ScheduleAnyway") | nindent 4 }}
resources: {}
select:
replicaCount: 2
{{- include "monitoring.topologySpreadConstraints" (list $ "vtselect" .name "ScheduleAnyway") | nindent 4 }}
resources: {}
storage:
retentionPeriod: {{ .retentionPeriod | quote }}
@@ -84,6 +86,7 @@ spec:
retention.maxDiskUsagePercent: "80"
{{- end }}
replicaCount: 2
{{- include "monitoring.topologySpreadConstraints" (list $ "vtstorage" .name "DoNotSchedule") | nindent 4 }}
resources: {}
storage:
volumeClaimTemplate:
@@ -0,0 +1,350 @@
suite: monitoring replicas spread over nodes
templates:
- templates/vm/vmcluster.yaml
- templates/vlogs/vlogs.yaml
- templates/vtraces/vtraces.yaml
- templates/alerta/alerta.yaml
release:
name: monitoring-system
namespace: tenant-root
set:
_cluster:
root-host: example.org
_namespace:
host: tenant-root.example.org
ingress: tenant-root
tracingStorages:
- name: generic
mode: cluster
retentionPeriod: "14d"
storage: 10Gi
tests:
- it: requires separate nodes for vmstorage and vmselect and prefers them for vminsert
template: templates/vm/vmcluster.yaml
documentSelector:
path: metadata.name
value: shortterm
asserts:
- equal:
path: spec.vmstorage.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
nodeTaintsPolicy: Ignore
labelSelector:
matchLabels:
app.kubernetes.io/name: vmstorage
app.kubernetes.io/instance: shortterm
- equal:
path: spec.vmselect.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
nodeTaintsPolicy: Ignore
labelSelector:
matchLabels:
app.kubernetes.io/name: vmselect
app.kubernetes.io/instance: shortterm
- equal:
path: spec.vminsert.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vminsert
app.kubernetes.io/instance: shortterm
- it: keys each VMCluster's constraints to its own name
template: templates/vm/vmcluster.yaml
documentSelector:
path: metadata.name
value: longterm
asserts:
- equal:
path: spec.vmstorage.topologySpreadConstraints[0].labelSelector.matchLabels
value:
app.kubernetes.io/name: vmstorage
app.kubernetes.io/instance: longterm
- equal:
path: spec.vmselect.topologySpreadConstraints[0].labelSelector.matchLabels
value:
app.kubernetes.io/name: vmselect
app.kubernetes.io/instance: longterm
- equal:
path: spec.vminsert.topologySpreadConstraints[0].labelSelector.matchLabels
value:
app.kubernetes.io/name: vminsert
app.kubernetes.io/instance: longterm
- it: requires separate nodes for vlstorage and prefers them for vlselect and vlinsert
template: templates/vlogs/vlogs.yaml
documentSelector:
path: metadata.name
value: generic
asserts:
- equal:
path: spec.vlstorage.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
nodeTaintsPolicy: Ignore
labelSelector:
matchLabels:
app.kubernetes.io/name: vlstorage
app.kubernetes.io/instance: generic
- equal:
path: spec.vlselect.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vlselect
app.kubernetes.io/instance: generic
- equal:
path: spec.vlinsert.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vlinsert
app.kubernetes.io/instance: generic
- it: requires separate nodes for vtstorage and prefers them for vtselect and vtinsert
template: templates/vtraces/vtraces.yaml
documentSelector:
path: kind
value: VTCluster
asserts:
- equal:
path: spec.storage.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
nodeTaintsPolicy: Ignore
labelSelector:
matchLabels:
app.kubernetes.io/name: vtstorage
app.kubernetes.io/instance: generic
- equal:
path: spec.select.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vtselect
app.kubernetes.io/instance: generic
- equal:
path: spec.insert.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vtinsert
app.kubernetes.io/instance: generic
- it: requires separate nodes for the Alertmanager replicas
template: templates/alerta/alerta.yaml
documentSelector:
path: kind
value: VMAlertmanager
asserts:
- equal:
path: spec.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
nodeTaintsPolicy: Ignore
labelSelector:
matchLabels:
app.kubernetes.io/name: vmalertmanager
app.kubernetes.io/instance: alertmanager
- it: keeps the default when the platform policy is empty
template: templates/vm/vmcluster.yaml
set:
_cluster:
scheduling:
globalAppTopologySpreadConstraints: ""
documentSelector:
path: metadata.name
value: shortterm
asserts:
- equal:
path: spec.vmstorage.topologySpreadConstraints[0].whenUnsatisfiable
value: DoNotSchedule
- equal:
path: spec.vminsert.topologySpreadConstraints[0].whenUnsatisfiable
value: ScheduleAnyway
- it: renders the platform policy in place of the default for a VMCluster
template: templates/vm/vmcluster.yaml
set:
_cluster:
scheduling:
globalAppTopologySpreadConstraints: |
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
documentSelector:
path: metadata.name
value: shortterm
asserts:
- equal:
path: spec.vmstorage.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vmstorage
app.kubernetes.io/instance: shortterm
- equal:
path: spec.vmselect.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vmselect
app.kubernetes.io/instance: shortterm
- equal:
path: spec.vminsert.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vminsert
app.kubernetes.io/instance: shortterm
- it: renders the platform policy in place of the default for the logs store
template: templates/vlogs/vlogs.yaml
set:
_cluster:
scheduling:
globalAppTopologySpreadConstraints: |
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
documentSelector:
path: metadata.name
value: generic
asserts:
- equal:
path: spec.vlstorage.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vlstorage
app.kubernetes.io/instance: generic
- it: renders the platform policy in place of the default for the traces store
template: templates/vtraces/vtraces.yaml
set:
_cluster:
scheduling:
globalAppTopologySpreadConstraints: |
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
documentSelector:
path: kind
value: VTCluster
asserts:
- equal:
path: spec.storage.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vtstorage
app.kubernetes.io/instance: generic
- it: renders the platform policy in place of the default for the Alertmanager
template: templates/alerta/alerta.yaml
set:
_cluster:
scheduling:
globalAppTopologySpreadConstraints: |
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
documentSelector:
path: kind
value: VMAlertmanager
asserts:
- equal:
path: spec.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vmalertmanager
app.kubernetes.io/instance: alertmanager
- it: gives every constraint of the platform policy the component's selector
template: templates/vm/vmcluster.yaml
set:
_cluster:
scheduling:
globalAppTopologySpreadConstraints: |
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
documentSelector:
path: metadata.name
value: shortterm
asserts:
- equal:
path: spec.vmstorage.topologySpreadConstraints
value:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app.kubernetes.io/name: vmstorage
app.kubernetes.io/instance: shortterm
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app.kubernetes.io/name: vmstorage
app.kubernetes.io/instance: shortterm