|
| 1 | +# GitOps capacity contract |
| 2 | + |
| 3 | +Available starting with **Understudy v0.4.4**, Helm chart **0.4.4**, and its |
| 4 | +`apps.understudy.sh/v1alpha1` CRD. Upgrade the CRD and operator together; |
| 5 | +v0.4.3 does not support the field. |
| 6 | + |
| 7 | +Git supplies the **desired baseline**. Understudy owns **effective replicas**: |
| 8 | +the normal baseline plus temporary capacity while handing over departing pods. |
| 9 | +This applies equally to Kubernetes Deployments and Argo Rollouts. |
| 10 | + |
| 11 | +## Configure the two owners |
| 12 | + |
| 13 | +Enable capacity management on the Understudy resource: |
| 14 | + |
| 15 | +```yaml |
| 16 | +apiVersion: apps.understudy.sh/v1alpha1 |
| 17 | +kind: Understudy |
| 18 | +metadata: |
| 19 | + name: worker |
| 20 | + namespace: workers |
| 21 | +spec: |
| 22 | + targetRef: |
| 23 | + kind: Deployment # or Rollout |
| 24 | + name: worker |
| 25 | + baselineReplicas: 1 |
| 26 | +``` |
| 27 | +
|
| 28 | +In the Argo CD Application, delegate the effective field and handover markers |
| 29 | +for that specific target: |
| 30 | +
|
| 31 | +```yaml |
| 32 | +spec: |
| 33 | + ignoreDifferences: |
| 34 | + - group: apps # argoproj.io for a Rollout |
| 35 | + kind: Deployment # Rollout for an Argo Rollout |
| 36 | + name: worker |
| 37 | + namespace: workers |
| 38 | + jsonPointers: |
| 39 | + - /spec/replicas |
| 40 | + - /metadata/annotations/understudy.sh~1base-replicas |
| 41 | + - /metadata/annotations/understudy.sh~1target-revision |
| 42 | + syncPolicy: |
| 43 | + automated: |
| 44 | + prune: true |
| 45 | + selfHeal: true |
| 46 | + syncOptions: |
| 47 | + - RespectIgnoreDifferences=true |
| 48 | +``` |
| 49 | +
|
| 50 | +Do not ignore `Understudy.spec.baselineReplicas`. Argo continues to synchronize |
| 51 | +that input, application releases, and unrelated settings normally. The ignore |
| 52 | +rules are static and scoped to the protected target: no conditional JQ, |
| 53 | +managed-field ownership inference, or manual sync pause is needed. |
| 54 | + |
| 55 | +Consumer charts should render the workload's initial `spec.replicas` and the |
| 56 | +Understudy's `spec.baselineReplicas` from **one service capacity value**. On first |
| 57 | +creation, Argo applies the workload as rendered; `RespectIgnoreDifferences` |
| 58 | +only preserves ignored fields on resources that already exist. Understudy then |
| 59 | +corrects any mismatch once both resources exist. A CR created before its target |
| 60 | +waits for the target to appear. |
| 61 | + |
| 62 | +## Lifecycle |
| 63 | + |
| 64 | +| Situation | Effective replicas and protection | |
| 65 | +|---|---| |
| 66 | +| No handover | Understudy reconciles effective replicas to the desired baseline, including live drift. | |
| 67 | +| Handover starts | Captures the currently applied capacity as the handover baseline and adds `surgeReplicas`. | |
| 68 | +| Baseline changes during handover | Keeps the captured baseline and surge; the latest requested value waits in the CR spec. Intermediate requests are superseded. | |
| 69 | +| Replacement becomes ready | The readiness threshold remains the captured baseline, not a pending larger or smaller request. | |
| 70 | +| Departing pods leave, or the disruption clears | Removes handover markers and applies the latest desired baseline. | |
| 71 | +| Readiness deadline expires | Relaxes the eviction hold; keeps surge capacity until departing pods leave or the disruption clears, then applies the latest baseline. | |
| 72 | +| Application release starts during handover | Ends the disruption surge, clears deletion-cost hints, admits evictions, and applies the latest baseline. | |
| 73 | +| Application release is updating, paused, or aborted | Disruption protection stands down; ordinary baseline reconciliation continues. Argo Rollouts still owns promotion and traffic routing. | |
| 74 | +| Desired baseline is zero | Scales to zero. A zero requested during handover waits like any other change; an already-zero workload does not start a disruption surge. | |
| 75 | + |
| 76 | +The baseline and revision captured for handover live in annotations on the |
| 77 | +target. The pending request lives in `Understudy.spec.baselineReplicas`, so a |
| 78 | +lost status update cannot discard it. On restart the operator reconstructs |
| 79 | +disruption signals and resumes reconciliation. Webhook availability still has |
| 80 | +the existing fail-open behavior while the operator is unavailable. |
| 81 | + |
| 82 | +## Observe the result |
| 83 | + |
| 84 | +- `spec.baselineReplicas`: latest Git request. |
| 85 | +- `status.baselineReplicas`: applied baseline, frozen during handover. |
| 86 | +- `BaselineApplied=False`, reason `HandoverInProgress`: desired baseline is pending. |
| 87 | +- `BaselineApplied=True`: baseline has been applied to the workload's replica |
| 88 | + request. This does **not** claim that every requested pod is Ready. |
| 89 | +- `SurgeReady` and `Protected`: replacement readiness and eviction-hold behavior. |
| 90 | +- Target `spec.replicas`: effective replicas, including a possible surge. |
| 91 | + |
| 92 | +Conditions include `observedGeneration`, so a client can distinguish the latest |
| 93 | +request from an older status observation. |
| 94 | + |
| 95 | +## Enable and retire ownership |
| 96 | + |
| 97 | +Use one Understudy resource per target and one capacity writer. An HPA, KEDA, |
| 98 | +another Understudy resource, or another GitOps application must not concurrently |
| 99 | +write that target's effective replicas. Workloads must still tolerate temporary |
| 100 | +overlap; baseline management does not make overlap-unsafe singletons safe. |
| 101 | + |
| 102 | +Omitting `baselineReplicas` keeps reactive-only protection. Removing it stops |
| 103 | +continuous baseline reconciliation; an active handover finishes at its captured |
| 104 | +baseline. Deleting the CR does not restore replicas: it removes the controller's |
| 105 | +input. To retire protection, finish or cancel the handover first, align the Git |
| 106 | +replica count with the intended capacity, then remove the CR and its Argo ignore |
| 107 | +rules together. Keep a target reference fixed through handover; retargeting a CR |
| 108 | +does not clean up the old target. |
| 109 | + |
| 110 | +The documented Argo configuration uses its ordinary apply synchronization path. |
| 111 | +Force/replace synchronization is outside this contract because it can recreate |
| 112 | +resources and discard the runtime state. Argo's native documentation explains |
| 113 | +[RespectIgnoreDifferences](https://argo-cd.readthedocs.io/en/stable/user-guide/sync-options/#respect-ignore-differences-configs). |
| 114 | + |
| 115 | +For Helm upgrades, update the CRD explicitly before using the new field: Helm |
| 116 | +does not upgrade CRDs in a chart's `crds/` directory. See [upgrade notes](../UPGRADING.md). |
| 117 | + |
| 118 | +## Verified integration |
| 119 | + |
| 120 | +Validated with Argo CD **3.5.5**, Argo Rollouts **1.10.1**, and Kubernetes |
| 121 | +**1.36.4** in isolated Kind clusters, with automatic sync and self-heal enabled. |
| 122 | +Deployment, canary, and blue/green targets passed initial installation, |
| 123 | +unrelated sync during surge, repeated pending baseline updates, cold operator |
| 124 | +restart and leadership recovery, eviction hold/release, final convergence, |
| 125 | +steady scaling, HTTP serving, and release takeover. Blue/green also converged a |
| 126 | +pending scale-to-zero request and subsequently scaled up from Git. |
| 127 | + |
| 128 | +The test used the ordinary Argo apply path and the scoped ignore rules above. |
| 129 | +Server-side apply and force/replace sync were not part of this verification. |
0 commit comments