Skip to content
Clone

fix(chart): stop claiming spec.replicas when the HPA is enabled

Writing `replicas: minReplicas` for an HPA-managed Deployment breaks the
upgrade as soon as the autoscaler has actually resized it: the HPA writes
through the /scale subresource, so kube-controller-manager becomes a field
manager for .spec.replicas, and helm's server-side apply is then rejected
with

  conflict with "kube-controller-manager" with subresource "scale":
  .spec.replicas

which is exactly how revision 36 failed (and its automatic rollback failed
the same way, leaving revision 37 failed). Even when it does apply, it
drags an autoscaled fleet back to minReplicas on every release.

Omitting the field is safe under SSA - helm releases its claim, the value
stays with the scale subresource - and both apihost and im already carry a
kube-controller-manager entry for f:spec.replicas in their managedFields, so
nothing can prune the field to the API default of 1 either.

This reverts the replicas line added in 7b1d4756 / aaafc30a, whose
three-way-merge reasoning does not hold for helm 4's server-side apply.
ZhenYi committed
parent 6d1afbc commit 6113ee6 Browse files

2 files changed

+12 −8

File tree 2
Modified chart/templates/apihost.yaml View chart/templates/apihost.yaml
@@ -8,11 +8,12 @@
88 app.kubernetes.io/component: apihost
99spec:
1010 {{- if .Values.apihost.autoscaling.enabled }}
11 # 开着 HPA 时也要写 replicas,且写 minReplicas:省略该字段会让 helm 的
12 # three-way merge 把它 patch 成 null,API server 随即按默认值收成 1,
13 # 升级瞬间主 API 少一个副本。写 minReplicas 则升级前后副本数不变,
14 # 之后完全由 HPA 接管(超出 min 的扩容不会被这张清单拉回)。
15 replicas: {{ .Values.apihost.autoscaling.minReplicas }}
11 # 开着 HPA 时不要声明 replicas:HPA 通过 /scale 子资源写这个字段,
12 # kube-controller-manager 于是成为它的 manager;helm 的 server-side apply
13 # 再写一次就会报 conflict with "kube-controller-manager" with subresource
14 # "scale": .spec.replicas —— 升级直接失败;而且就算写进去,也会把已经扩上
15 # 去的副本数硬拉回 minReplicas。省略即让出所有权:SSA 不会因此把字段清成
16 # 默认值,副本数继续由 scale 子资源持有。
1617 {{- else }}
1718 replicas: {{ .Values.apihost.replicaCount }}
1819 {{- end }}
Modified chart/templates/im.yaml View chart/templates/im.yaml
@@ -8,9 +8,12 @@
88 app.kubernetes.io/component: im
99spec:
1010 {{- if .Values.im.autoscaling.enabled }}
11 # 见 apihost.yaml 同名注释:省略 replicas 会被 three-way merge patch 成 null,
12 # API server 按默认值收成 1,升级瞬间 WS 只剩一个网关。
13 replicas: {{ .Values.im.autoscaling.minReplicas }}
11 # 开着 HPA 时不要声明 replicas:HPA 通过 /scale 子资源写这个字段,
12 # kube-controller-manager 于是成为它的 manager;helm 的 server-side apply
13 # 再写一次就会报 conflict with "kube-controller-manager" with subresource
14 # "scale": .spec.replicas —— 升级直接失败;而且就算写进去,也会把已经扩上
15 # 去的副本数硬拉回 minReplicas。省略即让出所有权:SSA 不会因此把字段清成
16 # 默认值,副本数继续由 scale 子资源持有。
1417 {{- else }}
1518 replicas: {{ .Values.im.replicaCount }}
1619 {{- end }}