mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-11-20 03:10:34 +00:00
fix(helm): drop rollingUpdate when a Deployment strategy is Recreate (#8336)
* fix(helm): drop rollingUpdate when a Deployment strategy is Recreate
The gateway and provisioner default to RollingUpdate with a rollingUpdate
block. Setting only `strategy.type: Recreate` renders both, which the API
server rejects ("may not be specified when strategy type is 'Recreate'").
A direct install can null the block, but a parent chart that depends on
this chart can't: Helm keeps the subchart's default. A single gateway on a
ReadWriteOnce home PVC needs Recreate, since the new Pod can't attach the
volume on another node while the old one holds it.
A `deer-flow.strategy` helper renders the strategy and drops rollingUpdate
for Recreate; both Deployments use it. Defaults render unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(helm): note the Helm 4 server-side apply case when switching to Recreate
A release whose manifest omitted strategy leaves the API-server-defaulted
rollingUpdate unowned; server-side apply then can't remove it and the
switch to Recreate is rejected. Document running that upgrade with
--server-side=false.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
25a744a99a
commit
c9ecf577c4
53
backend/tests/test_helm_deployment_strategy.py
Normal file
53
backend/tests/test_helm_deployment_strategy.py
Normal file
@ -0,0 +1,53 @@
|
||||
"""``strategy.type: Recreate`` must render without ``rollingUpdate``.
|
||||
|
||||
The gateway and provisioner default to ``RollingUpdate`` with a
|
||||
``rollingUpdate`` block. Kubernetes rejects ``rollingUpdate`` next to
|
||||
``type: Recreate``, and a parent chart that uses this chart as a dependency
|
||||
cannot null the default block (Helm keeps subchart defaults), so a single
|
||||
gateway on a ReadWriteOnce home PVC could not switch to ``Recreate``.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
CHART = REPO_ROOT / "deploy" / "helm" / "deer-flow"
|
||||
|
||||
|
||||
def _strategies(chart: Path, *settings: str) -> dict[str, dict]:
|
||||
helm = shutil.which("helm")
|
||||
if helm is None:
|
||||
pytest.skip("helm is unavailable")
|
||||
command = [helm, "template", "deer-flow", str(chart)]
|
||||
for setting in settings:
|
||||
command.extend(["--set", setting])
|
||||
rendered = subprocess.run(command, check=True, capture_output=True, text=True, encoding="utf-8").stdout
|
||||
deployments = [document for document in yaml.safe_load_all(rendered) if isinstance(document, dict) and document.get("kind") == "Deployment"]
|
||||
return {name: d["spec"].get("strategy") for d in deployments for name in ("gateway", "provisioner") if d["metadata"]["name"].endswith(f"-{name}")}
|
||||
|
||||
|
||||
def test_default_strategy_is_surge_then_drain() -> None:
|
||||
strategies = _strategies(CHART)
|
||||
assert set(strategies) == {"gateway", "provisioner"}
|
||||
for strategy in strategies.values():
|
||||
assert strategy == {"type": "RollingUpdate", "rollingUpdate": {"maxSurge": 1, "maxUnavailable": 0}}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("component", ["gateway", "provisioner"])
|
||||
def test_recreate_drops_rolling_update(component: str) -> None:
|
||||
strategies = _strategies(CHART, f"{component}.strategy.type=Recreate")
|
||||
assert strategies[component] == {"type": "Recreate"}
|
||||
|
||||
|
||||
def test_recreate_from_a_parent_chart(tmp_path: Path) -> None:
|
||||
parent = tmp_path / "parent"
|
||||
shutil.copytree(CHART, parent / "charts" / "deer-flow")
|
||||
(parent / "Chart.yaml").write_text('apiVersion: v2\nname: parent\nversion: 0.0.1\ndependencies:\n - name: deer-flow\n version: "*"\n')
|
||||
(parent / "values.yaml").write_text("deer-flow:\n gateway:\n strategy:\n type: Recreate\n rollingUpdate: null\n")
|
||||
assert _strategies(parent)["gateway"] == {"type": "Recreate"}
|
||||
@ -141,7 +141,8 @@ def test_deployment_template_takes_replicas_and_strategy_from_values() -> None:
|
||||
template = DEPLOYMENT_TEMPLATE.read_text(encoding="utf-8")
|
||||
assert "replicas: {{ .Values.provisioner.replicas }}" in template
|
||||
assert re.search(r"^\s*replicas:\s*\d+\s*$", template, flags=re.MULTILINE) is None, "a literal replica count ignores provisioner.replicas"
|
||||
assert re.search(r"\{\{- with \.Values\.provisioner\.strategy \}\}\n\s+strategy:\n\s+\{\{- toYaml \. \| nindent 4 \}\}\n\s+\{\{- end \}\}", template), "the rollout strategy must come from values like the gateway's"
|
||||
strategy_block = r'\{\{- with \.Values\.provisioner\.strategy \}\}\n\s+strategy:\n\s+\{\{- include "deer-flow\.strategy" \. \| nindent 4 \}\}\n\s+\{\{- end \}\}'
|
||||
assert re.search(strategy_block, template), "the rollout strategy must come from values like the gateway's"
|
||||
assert SELECTOR_BLOCK.search(template), "the Deployment selector is what the budget has to match"
|
||||
|
||||
|
||||
|
||||
@ -347,7 +347,17 @@ kubectl -n deer-flow exec deploy/deer-flow-provisioner -- curl -s localhost:8002
|
||||
string such as `"50%"`, while `0` fails the render -- disable the budget
|
||||
instead) is rendered automatically for a multi-instance gateway (same rule),
|
||||
and the rollout strategy is surge-then-drain (`maxSurge: 1`,
|
||||
`maxUnavailable: 0`). The sandbox
|
||||
`maxUnavailable: 0`). A single gateway whose ReadWriteOnce home PVC can't
|
||||
attach on two nodes at once needs `gateway.strategy.type: Recreate`; the
|
||||
chart then drops `rollingUpdate`, so the type alone is enough, also when
|
||||
this chart is a dependency of yours. Switching an installed release from
|
||||
the default to `Recreate` with Helm 4's server-side apply fails with
|
||||
`spec.strategy.rollingUpdate: Forbidden` when the previous release's
|
||||
manifest had no `strategy` (e.g. `gateway.strategy: null`): the API server
|
||||
defaulted `rollingUpdate`, no field manager owns it, so the apply can't
|
||||
remove it. Run that one upgrade with `--server-side=false`; its three-way
|
||||
merge patch drops `rollingUpdate`, and later upgrades can use server-side
|
||||
apply again. The sandbox
|
||||
provisioner is not on the single-instance list: it scales independently
|
||||
(next item).
|
||||
- **Provisioner replicas.** `provisioner.replicas` (default 1) scales the
|
||||
|
||||
@ -64,6 +64,13 @@ imagePullSecrets:
|
||||
{{- printf "%s:%s" .Values.gateway.initContainers.image.repository .Values.gateway.initContainers.image.tag -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* A Deployment strategy. With `type: Recreate`, `rollingUpdate` is dropped:
|
||||
Kubernetes rejects the pair, and a parent chart cannot null the default
|
||||
`rollingUpdate` of this chart's values (Helm keeps subchart defaults). */}}
|
||||
{{- define "deer-flow.strategy" -}}
|
||||
{{- if eq (.type | default "") "Recreate" -}}{{- toYaml (omit . "rollingUpdate") -}}{{- else -}}{{- toYaml . -}}{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* PVC name for the .deer-flow home directory. */}}
|
||||
{{- define "deer-flow.homePVC" -}}
|
||||
{{- printf "%s-home" (include "deer-flow.fullname" .) -}}
|
||||
|
||||
@ -10,7 +10,7 @@ spec:
|
||||
replicas: {{ .Values.gateway.replicas }}
|
||||
{{- with .Values.gateway.strategy }}
|
||||
strategy:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- include "deer-flow.strategy" . | nindent 4 }}
|
||||
{{- end }}
|
||||
selector:
|
||||
matchLabels:
|
||||
|
||||
@ -11,7 +11,7 @@ spec:
|
||||
replicas: {{ .Values.provisioner.replicas }}
|
||||
{{- with .Values.provisioner.strategy }}
|
||||
strategy:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- include "deer-flow.strategy" . | nindent 4 }}
|
||||
{{- end }}
|
||||
selector:
|
||||
matchLabels:
|
||||
|
||||
@ -61,6 +61,9 @@ gateway:
|
||||
# Rollout strategy. Surge-then-drain keeps one Pod serving while a peer
|
||||
# starts; with run-ownership heartbeats the new Pod leaves the old Pod's live
|
||||
# runs alone (their leases keep renewing) while the old Pod drains them.
|
||||
# `type: Recreate` (e.g. a single gateway on a ReadWriteOnce home PVC that
|
||||
# can't attach to two nodes) drops `rollingUpdate`, so setting the type alone
|
||||
# is enough, also from a parent chart.
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
@ -181,6 +184,7 @@ provisioner:
|
||||
# Rollout strategy. Surge-then-drain keeps one Pod answering sandbox calls
|
||||
# while a peer starts; a replica has nothing to hand over beyond its
|
||||
# in-flight requests, so the default termination grace period is enough.
|
||||
# `type: Recreate` drops `rollingUpdate`, as for the gateway.
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user