Skip to content

Commit 7bae5f8

Browse files
authored
Merge pull request #6 from mitis-cloud/gitops-baseline-capacity
Add GitOps baseline capacity and release 0.4.4
2 parents 672d1a2 + 514d898 commit 7bae5f8

15 files changed

Lines changed: 572 additions & 24 deletions

‎CONTEXT.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Understudy
2+
3+
Understudy prepares temporary replacement capacity for announced node disruptions.
4+
5+
## Language
6+
7+
**Desired baseline**: The capacity the service author requests outside a disruption.
8+
_Avoid_: Effective replicas, surge capacity
9+
10+
**Effective replicas**: The capacity currently requested from the workload controller,
11+
including any temporary surge.
12+
13+
**Handover baseline**: The baseline committed to an active disruption handover;
14+
later desired-baseline changes do not alter its readiness requirement.
15+
16+
**Handover**: The interval in which Understudy prepares replacement capacity and
17+
allows departing pods to leave, ending when the disruption clears or a release takes over.
18+
19+
**Pending baseline**: The latest desired baseline awaiting completion of a handover.
20+
Intermediate requests are superseded rather than queued.
21+
22+
**Release**: A change to the application's revision, managed by its workload controller.
23+
_Avoid_: Handover, node drain

‎README.md‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ someone runs them on GKE and AKS.
184184
|---|---|---|
185185
| `targetRef.kind` | `Deployment` | `Deployment` (`apps/v1`) or `Rollout` (`argoproj.io/v1alpha1`) |
186186
| `targetRef.name` | required | The workload to protect, in the same namespace |
187+
| `baselineReplicas` | unset | Opt into capacity management: desired steady-state replicas; changes wait during handover. Supports zero. See [GitOps capacity](docs/gitops-capacity.md) |
187188
| `surgeReplicas` | 1 | How many stand-ins to add |
188189
| `minSurgeTimeSeconds` | 60 | How long this workload realistically takes to start serving. If a termination deadline is nearer than this, the eviction is released immediately instead of being held |
189190
| `readinessDeadlineSeconds` | 600 | How long to hold an eviction with no progress before giving up and letting it through |
@@ -236,14 +237,28 @@ revision (or the blue/green active revision) count as stand-ins. Ready preview
236237
pods and old revisions cannot release a production pod's eviction hold.
237238

238239
During an update, pause, or abort, Understudy stands down and admits evictions.
239-
If a release begins during an Understudy surge, it restores the original replica
240-
count and relinquishes the hold. Progressive delivery remains Argo's responsibility.
240+
If a release begins during an Understudy surge, it removes the surge and
241+
relinquishes the hold. With `baselineReplicas`, it applies the latest requested
242+
baseline; otherwise it restores the original replica count. Progressive delivery
243+
remains Argo's responsibility.
241244

242245
Argo Rollouts must already be installed. Its API is detected at operator startup;
243246
restart Understudy if you install the Rollout CRD later. Clusters without Argo
244247
Rollouts continue to support Deployments. As with Deployments, another reconciler
245248
(such as an HPA or GitOps tool) must not overwrite the temporary replica increase.
246249

250+
### GitOps capacity
251+
252+
Argo CD keeps Kubernetes aligned with Git; Argo Rollouts manages application
253+
releases. These are separate jobs. For either a Deployment or a Rollout managed
254+
by Argo CD, set `spec.baselineReplicas` on the Understudy resource and delegate
255+
the workload's effective `spec.replicas` to Understudy.
256+
257+
Git capacity changes then converge automatically. During a drain handover,
258+
Understudy preserves its captured baseline plus surge and applies the latest
259+
requested baseline afterward. `BaselineApplied=False` reports a pending change.
260+
See [the complete ownership configuration and lifecycle](docs/gitops-capacity.md).
261+
247262
## How it works
248263

249264
Briefly: answer the eviction at the door with HTTP 429, surge when its node is

‎UPGRADING.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
Version-to-version notes. Anything not mentioned here needs no action.
44

5+
## 0.4.3 to 0.4.4
6+
7+
`spec.baselineReplicas` opts into continuous capacity management. Existing
8+
resources without it retain reactive-only protection. Install the updated
9+
operator and CRD together before enabling it; v0.4.3 does not implement this
10+
contract. [GitOps capacity](docs/gitops-capacity.md) documents the exact Argo
11+
ownership settings and lifecycle for Deployments and Rollouts.
12+
13+
Helm does not upgrade files in `crds/`. Apply the v0.4.4 schema first, then
14+
upgrade the chart and operator:
15+
16+
```sh
17+
kubectl apply --server-side -f \
18+
https://raw.githubusercontent.com/mitis-cloud/understudy/v0.4.4/charts/understudy/crds/apps.understudy.sh_understudies.yaml
19+
20+
helm upgrade understudy oci://ghcr.io/kylan11/charts/understudy \
21+
--namespace understudy-system --version 0.4.4
22+
```
23+
24+
Then configure the desired baseline and Argo ignore rules together. Do not
25+
enable only the ignore rules: without the new
26+
baseline input, intentional Git capacity changes would still be ignored.
27+
528
## 0.4.2 to 0.4.3
629

730
Argo Rollouts are now supported with `targetRef.kind: Rollout`. Both canary and

‎api/v1alpha1/understudy_types.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
ConditionProtected = "Protected"
4646
ConditionSurgeReady = "SurgeReady"
4747
ConditionZeroDowntimeStrategy = "ZeroDowntimeUpdateStrategy"
48+
ConditionBaselineApplied = "BaselineApplied"
4849
)
4950

5051
type TargetReference struct {
@@ -62,6 +63,11 @@ type UnderstudySpec struct {
6263
// +required
6364
TargetRef TargetReference `json:"targetRef"`
6465

66+
// BaselineReplicas opts into capacity management; changes wait during handover.
67+
// +kubebuilder:validation:Minimum=0
68+
// +optional
69+
BaselineReplicas *int32 `json:"baselineReplicas,omitempty"`
70+
6571
// +kubebuilder:default=1
6672
// +kubebuilder:validation:Minimum=1
6773
// +optional
@@ -85,6 +91,10 @@ type UnderstudySpec struct {
8591
}
8692

8793
type UnderstudyStatus struct {
94+
// BaselineReplicas is the applied baseline, frozen while a handover is active.
95+
// +optional
96+
BaselineReplicas *int32 `json:"baselineReplicas,omitempty"`
97+
8898
// +optional
8999
Phase Phase `json:"phase,omitempty"`
90100

‎api/v1alpha1/zz_generated.deepcopy.go‎

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎charts/understudy/Chart.yaml‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ description: >-
55
downtime from announced node disruptions (drains, upgrades, consolidation,
66
spot reclaims) without a standing second replica.
77
type: application
8-
version: 0.4.3
9-
appVersion: "0.4.3"
8+
version: 0.4.4
9+
appVersion: "0.4.4"
1010
kubeVersion: ">=1.34.0-0"
1111
keywords:
1212
- availability
@@ -17,6 +17,7 @@ keywords:
1717
- karpenter
1818
- cluster-autoscaler
1919
- argo-rollouts
20+
- gitops
2021
home: https://github.com/kylan11/understudy
2122
sources:
2223
- https://github.com/kylan11/understudy
@@ -41,7 +42,7 @@ annotations:
4142
url: https://github.com/kylan11/understudy/issues
4243
artifacthub.io/images: |
4344
- name: understudy
44-
image: ghcr.io/kylan11/understudy:0.4.3
45+
image: ghcr.io/kylan11/understudy:0.4.4
4546
artifacthub.io/crds: |
4647
- kind: Understudy
4748
version: v1alpha1
@@ -65,6 +66,8 @@ annotations:
6566
readinessDeadlineSeconds: 600
6667
artifacthub.io/changes: |
6768
- kind: added
68-
description: Protect fully promoted Argo Rollouts with canary and blue/green strategies using targetRef.kind Rollout
69+
description: Optional baselineReplicas separates Git-owned desired capacity from effective Deployment and Rollout replicas, deferring capacity changes until handover completes
70+
- kind: added
71+
description: BaselineApplied status and documented Argo CD field delegation expose and preserve pending capacity changes
6972
- kind: fixed
70-
description: Admit evictions while standing down for progressive delivery and exclude preview revisions from Rollout replacement readiness
73+
description: Detect Deployment releases during an active surge and apply the latest baseline when application releases take over

‎charts/understudy/crds/apps.understudy.sh_understudies.yaml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ spec:
5353
type: object
5454
spec:
5555
properties:
56+
baselineReplicas:
57+
description: BaselineReplicas opts into capacity management; changes
58+
wait during handover.
59+
format: int32
60+
minimum: 0
61+
type: integer
5662
holdMode:
5763
enum:
5864
- always
@@ -97,6 +103,11 @@ spec:
97103
type: object
98104
status:
99105
properties:
106+
baselineReplicas:
107+
description: BaselineReplicas is the applied baseline, frozen while
108+
a handover is active.
109+
format: int32
110+
type: integer
100111
blockedSince:
101112
format: date-time
102113
type: string

‎config/crd/bases/apps.understudy.sh_understudies.yaml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ spec:
5353
type: object
5454
spec:
5555
properties:
56+
baselineReplicas:
57+
description: BaselineReplicas opts into capacity management; changes
58+
wait during handover.
59+
format: int32
60+
minimum: 0
61+
type: integer
5662
holdMode:
5763
enum:
5864
- always
@@ -97,6 +103,11 @@ spec:
97103
type: object
98104
status:
99105
properties:
106+
baselineReplicas:
107+
description: BaselineReplicas is the applied baseline, frozen while
108+
a handover is active.
109+
format: int32
110+
type: integer
100111
blockedSince:
101112
format: date-time
102113
type: string
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
status: accepted
3+
---
4+
5+
# Separate desired baseline from effective replicas
6+
7+
GitOps synchronization and Understudy's temporary surge both write workload
8+
replicas. Permanently ignoring replicas prevents Git capacity changes, while
9+
conditional ignores do not preserve the surge through Argo CD 3.5.5's sync
10+
preprocessing. We therefore add opt-in `spec.baselineReplicas`: Git owns the
11+
desired baseline, and Understudy continuously reconciles effective replicas.
12+
13+
During handover, the captured baseline remains the readiness threshold and the
14+
latest desired baseline waits in the resource's spec. Completion, cancellation,
15+
or release takeover applies that latest value. Application release stand-down
16+
disables disruption surging and holding, not ordinary baseline reconciliation.
17+
18+
Argo delegates the effective replica field and Understudy's handover annotations
19+
using its native, statically scoped `ignoreDifferences` and
20+
`RespectIgnoreDifferences=true`. No synchronization wrapper or additional
21+
controller is introduced. Omitting the baseline retains reactive-only
22+
protection; the opt-in contract requires a single capacity writer.
23+
24+
This boundary expansion was approved in Q38, originating from DBRID-2851's
25+
service-chart integration requirement. The operator owns its implementation;
26+
consumer charts derive the desired baseline and first-install replica count
27+
from the same service capacity value.

‎docs/gitops-capacity.md‎

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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

Comments
 (0)