Nan Gao 7ff13bad45
fix(helm): let the sandbox provisioner run with several replicas (#6543)
* fix(helm): let the sandbox provisioner run with several replicas

The chart hard-coded replicas: 1 into the provisioner Deployment, gave it
no rollout strategy and no PodDisruptionBudget, and values.yaml had no
provisioner.replicas key, so a multi-replica gateway deployment still sent
every sandbox create/discover/destroy call through one Pod: while that Pod
restarted or its node drained no sandbox could be created anywhere.

- values.yaml provisioner gains replicas (default 1, unchanged), the
  gateway's surge-then-drain RollingUpdate strategy and
  podDisruptionBudget {enabled: true, minAvailable: 1}.
- provisioner-deployment.yaml renders replicas and strategy from values; at
  1 replica the result equals the Kubernetes default strategy.
- New provisioner-pdb.yaml, rendered only while the provisioner is enabled,
  the budget is enabled and replicas > 1, selecting on the Deployment's
  labels and named <fullname>-provisioner so it never collides with the
  gateway budget. No multiInstance override: nothing else in the chart
  renders differently per provisioner replica count.
- docker/provisioner/app.py is unchanged. It keeps no state between
  requests: the labelled sandbox Pods and Services are the only registry,
  create tolerates the 409 a concurrent creator produces, destroy tolerates
  404, NodePorts come from the API server and there is no background loop.
  The chart README and docker/provisioner/README.md record this, and
  tests/test_helm_provisioner_replicas.py pins it at source level next to
  the values, template and helm-render assertions.

* docs(changelog): link the provisioner replicas entry to #6543

* fix(helm): preserve percentage PodDisruptionBudget values instead of casting them to 0

Review of #6543: both PDB templates rendered minAvailable through
`| default 1 | int`, and sprig's int turns a percentage string such as
"50%" -- a value Kubernetes accepts -- into 0, a budget that permits every
Pod to be evicted. The gateway budget had the same pre-existing cast.

- New shared helper deer-flow.pdbMinAvailable in _helpers.tpl: a YAML or
  --set number renders as an integer, a digit string from --set-string
  becomes that integer, a percentage is preserved quoted, and 0, "0%",
  more than 100%, a non-integer or anything else fails the render with a
  message naming the values key and the enabled switch to use instead.
  Unset still falls back to 1.
- gateway-pdb.yaml and provisioner-pdb.yaml render minAvailable through it.
- values.yaml comments, the chart README multi-replica note and the
  CHANGELOG entry say integer-or-percentage and that zero is rejected.
- tests/test_helm_provisioner_replicas.py pins the helper and the two
  templates at text level and adds render cases for both budgets: "50%"
  with three replicas renders "50%", 2 via --set and --set-string renders
  2, and abc / 0 / 0% / 150% fail naming the key.

* fix(helm): normalize json.Number before the minAvailable string branches

Review of #6543: Helm 3.18.0 loads YAML numbers as json.Number, whose
kind is "string" but which regexMatch and the other string-typed sprig
functions reject at argument validation ("expected string; got
json.Number"). deer-flow.pdbMinAvailable gated its string branch on
kindIs "string", so the unoverridden chart default minAvailable: 1 made
every gateway.replicas=2 / provisioner.replicas=2 render fail on that
release, inside the README's documented 3.8+ support window.

- The helper keeps the explicit float64/int64/int branch and now converts
  everything else with toString into $text before the digit, percentage
  and fail branches; regexMatch, atoi, trimSuffix and quote only ever see
  that plain string. A json.Number 1 renders 1, a json.Number 1.5 still
  fails (the digit regex rejects it) and the hint still prints the raw
  value; bools and other kinds still fail. The helper comment records the
  Helm 3.18.0 reason.
- tests/test_helm_provisioner_replicas.py pins that the string branch
  runs on the toString-normalized variable, that no string-typed function
  is applied to $raw and that kindIs "string" is gone, and adds an
  explicit render case for both budgets with only the replica count set
  (the unoverridden default must render minAvailable: 1), marked as the
  Helm 3.18.0 json.Number regression guard.

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-09 18:26:23 +08:00
..