|
| 1 | +# Helm migration: API Deployment selector now carries `component: api` unconditionally |
| 2 | + |
| 3 | +## Applies to |
| 4 | + |
| 5 | +Operators upgrading an **existing** AgentFlow Helm release that was installed |
| 6 | +with a chart **before** this one, where `worker.enabled=false` (the default). |
| 7 | +Fresh installs and releases already running `worker.enabled=true` are **not** |
| 8 | +affected. |
| 9 | + |
| 10 | +## What changed and why |
| 11 | + |
| 12 | +The API Deployment (`templates/deployment.yaml`) now adds |
| 13 | +`app.kubernetes.io/component: api` to its pod template labels **and** its |
| 14 | +`spec.selector.matchLabels` **unconditionally**. Previously that label was added |
| 15 | +only when `worker.enabled=true`. |
| 16 | + |
| 17 | +This fixes two audit findings: |
| 18 | + |
| 19 | +- **#7 — immutable selector toggle-break.** `spec.selector` is immutable in |
| 20 | + Kubernetes. When the label was gated on `worker.enabled`, flipping that value |
| 21 | + on a live release changed the selector, so `helm upgrade` aborted with |
| 22 | + `spec.selector is immutable`. Making the label unconditional keeps the selector |
| 23 | + **constant** across the `worker.enabled` toggle, so the split can be enabled or |
| 24 | + disabled in place. |
| 25 | +- **#6 — component-scoped PodDisruptionBudget.** The PDB now selects |
| 26 | + `component: api`, guaranteeing at least one *API* pod survives a voluntary |
| 27 | + disruption. That guarantee only holds if API pods **always** carry the label, |
| 28 | + which is why the pod-template label had to become unconditional too. |
| 29 | + |
| 30 | +It also keeps API and worker pods in disjoint selector sets, so the two |
| 31 | +Deployments can never adopt each other's pods. |
| 32 | + |
| 33 | +## The one-time breaking upgrade |
| 34 | + |
| 35 | +Because `spec.selector` is immutable, the **first** upgrade of a pre-existing |
| 36 | +`worker.enabled=false` release onto this chart changes the selector from |
| 37 | +`{name, instance}` to `{name, instance, component=api}`. The API server rejects |
| 38 | +the in-place change: |
| 39 | + |
| 40 | +``` |
| 41 | +Deployment.apps "<release>-agentflow" is invalid: spec.selector: Invalid value: |
| 42 | +v1.LabelSelector{...}: field is immutable |
| 43 | +``` |
| 44 | + |
| 45 | +`helm upgrade` fails and rolls back; nothing is left half-applied. Recreate the |
| 46 | +API Deployment **once** to move past it. This is a one-time step — subsequent |
| 47 | +upgrades are normal. |
| 48 | + |
| 49 | +### Option A — zero-downtime (recommended for multi-replica / production) |
| 50 | + |
| 51 | +Orphan the existing pods so they keep serving, let the recreated Deployment |
| 52 | +stand up new pods, then reap the orphans: |
| 53 | + |
| 54 | +```bash |
| 55 | +kubectl delete deployment <release>-agentflow -n <namespace> --cascade=orphan |
| 56 | +helm upgrade <release> <chart> [same flags as before] |
| 57 | +# wait for the new (component=api) pods to become Ready, then remove the |
| 58 | +# orphaned old pods — they lack component=api so the new Deployment won't adopt |
| 59 | +# them and they will not be cleaned up automatically: |
| 60 | +kubectl get pods -n <namespace> -l app.kubernetes.io/name=agentflow \ |
| 61 | + -L app.kubernetes.io/component |
| 62 | +kubectl delete pod <old-pod-names> -n <namespace> |
| 63 | +``` |
| 64 | + |
| 65 | +### Option B — simplest (brief serving gap) |
| 66 | + |
| 67 | +For a single-replica default install where a short gap is acceptable: |
| 68 | + |
| 69 | +```bash |
| 70 | +kubectl delete deployment <release>-agentflow -n <namespace> |
| 71 | +helm upgrade <release> <chart> [same flags as before] |
| 72 | +``` |
| 73 | + |
| 74 | +## Notes |
| 75 | + |
| 76 | +- The chart does **not** ship a `pre-upgrade` hook to automate the delete. A hook |
| 77 | + that deletes the primary API Deployment would fire on **every** upgrade (helm |
| 78 | + hooks are not conditional on "did the selector change"), turning a one-time |
| 79 | + migration into a recurring outage. The manual step above runs exactly once, by |
| 80 | + operator decision. |
| 81 | +- The Service selector is unaffected (Service selectors are mutable): it already |
| 82 | + narrows to `component: api` when `worker.enabled=true` and otherwise selects on |
| 83 | + `{name, instance}`, which still matches the API pods. |
| 84 | +- Related NetworkPolicy change in the same release: a PostgreSQL `:5432` egress |
| 85 | + rule is now rendered when `controlPlane.store=postgres`. No migration action — |
| 86 | + it only adds an allowed egress. |
0 commit comments