Skip to content

Commit 9336fc7

Browse files
author
Arvind Thirumurugan
committed
interface: start/stop API for updateRun
Signed-off-by: Arvind Thirumurugan <[email protected]>
1 parent 11a7637 commit 9336fc7

File tree

5 files changed

+150
-6
lines changed

5 files changed

+150
-6
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Start/Stop UpdateRun API Implementation
2+
3+
## Date: 2025-10-29-1500
4+
5+
## Requirements
6+
7+
**Primary Objective**: Implement the ability to start and stop an UpdateRun. Currently when we create an updateRun it immediately initializes and executes. Instead when an updateRun is created we initialize but won't execute until user starts the updateRun. And we want the ability to stop the updateRun and if resources are being propagated to a particular cluster when stopped it will complete propagation for the cluster and stop propagation for all other cluster in that stage. And when updateRun is started again it will continue where it left off.
8+
9+
## Understanding Current Implementation
10+
11+
From the codebase analysis:
12+
13+
1. **Current Flow**: CreateUpdateRun → Initialize → Execute immediately
14+
2. **Controller Logic**: Located in `/pkg/controllers/updaterun/controller.go`
15+
3. **Main Reconcile Loop**: Calls `initialize()` then immediately `execute()`
16+
4. **Conditions**: Uses "Initialized", "Progressing", "Succeeded" conditions
17+
5. **Stage Execution**: Tracks per-stage and per-cluster status in `StageUpdatingStatus`
18+
19+
## Implementation Plan
20+
21+
### Phase 1: API Design - Add Start/Stop Controls
22+
- [x] Task 1.1: Add `Started` field to UpdateRunSpec to control execution start
23+
- [x] Task 1.2: Add new condition type `StagedUpdateRunConditionStarted`
24+
- [x] Task 1.3: Update UpdateRunSpec validation to handle new field
25+
- [x] Task 1.4: Update kubebuilder comments and validation tags
26+
27+
### Phase 2: Controller Logic Updates
28+
- [ ] Task 2.1: Modify controller.go reconcile loop to check Started field
29+
- [ ] Task 2.2: Separate initialization from execution in controller flow
30+
- [ ] Task 2.3: Add logic to mark UpdateRun as ready but not started after initialization
31+
- [ ] Task 2.4: Handle start transition - when Started changes from false/nil to true
32+
- [ ] Task 2.5: Implement stop transition - when Started changes from true to false
33+
34+
### Phase 3: Graceful Stop Implementation
35+
- [ ] Task 3.1: Track in-progress cluster updates during stop
36+
- [ ] Task 3.2: Complete current cluster propagation before stopping
37+
- [ ] Task 3.3: Mark stopped stage/clusters appropriately in status
38+
- [ ] Task 3.4: Ensure resume from correct point when restarted
39+
40+
### Phase 4: Status and Condition Management
41+
- [ ] Task 4.1: Add Started condition management functions
42+
- [ ] Task 4.2: Update condition progression: Initialize → Started → Progressing → Succeeded
43+
- [ ] Task 4.3: Handle stop scenarios in condition updates
44+
- [ ] Task 4.4: Update metrics to track start/stop events
45+
46+
### Phase 5: Testing
47+
- [ ] Task 5.1: Write unit tests for new spec field and conditions
48+
- [ ] Task 5.2: Write integration tests for start/stop workflow
49+
- [ ] Task 5.3: Write e2e tests for graceful stop and resume scenarios
50+
- [ ] Task 5.4: Test edge cases (stop during cluster propagation, restart scenarios)
51+
52+
### Phase 6: Documentation and Examples
53+
- [ ] Task 6.1: Update API documentation
54+
- [ ] Task 6.2: Add example YAML files showing start/stop usage
55+
- [ ] Task 6.3: Update user guide with start/stop procedures
56+
57+
## API Design
58+
59+
### UpdateRunSpec Changes
60+
```go
61+
type UpdateRunSpec struct {
62+
// ... existing fields ...
63+
64+
// Started indicates whether the update run should be started.
65+
// When false or nil, the update run will initialize but not execute.
66+
// When true, the update run will begin execution.
67+
// Changing from true to false will gracefully stop the update run.
68+
// +kubebuilder:validation:Optional
69+
Started *bool `json:"started,omitempty"`
70+
}
71+
```
72+
73+
### New Condition Type
74+
```go
75+
const (
76+
// ... existing conditions ...
77+
78+
// StagedUpdateRunConditionStarted indicates whether the staged update run has been started.
79+
// Its condition status can be one of the following:
80+
// - "True": The staged update run has been started and is ready to progress.
81+
// - "False": The staged update run is stopped or not yet started.
82+
StagedUpdateRunConditionStarted StagedUpdateRunConditionType = "Started"
83+
)
84+
```
85+
86+
## Success Criteria
87+
88+
1. **✅ Initialize Without Execute**: UpdateRun initializes successfully but waits for start signal
89+
2. **✅ Start Control**: Setting `Started: true` begins execution from correct stage
90+
3. **✅ Graceful Stop**: Setting `Started: false` completes current cluster and stops
91+
4. **✅ Resume Capability**: Restarting continues from exact stopping point
92+
5. **✅ Proper Conditions**: All condition transitions work correctly
93+
6. **✅ Backward Compatibility**: Existing UpdateRuns continue to work (default to started)
94+
95+
## Current Status: Phase 1 Complete ✅
96+
97+
**Completed**:
98+
- Added `Started *bool` field to UpdateRunSpec with proper kubebuilder validation
99+
- Added `StagedUpdateRunConditionStarted` condition type with proper documentation
100+
- Updated kubebuilder printcolumn annotations to include Started condition in kubectl output
101+
- Updated condition documentation to include "Started" in known conditions list
102+
- Generated CRDs successfully with new API changes
103+
104+
**Next**: Ready to proceed with Phase 2 - Controller Logic Updates

apis/placement/v1beta1/stageupdate_types.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type UpdateRunObjList interface {
9191
// +kubebuilder:printcolumn:JSONPath=`.spec.resourceSnapshotIndex`,name="Resource-Snapshot-Index",type=string
9292
// +kubebuilder:printcolumn:JSONPath=`.status.policySnapshotIndexUsed`,name="Policy-Snapshot-Index",type=string
9393
// +kubebuilder:printcolumn:JSONPath=`.status.conditions[?(@.type=="Initialized")].status`,name="Initialized",type=string
94+
// +kubebuilder:printcolumn:JSONPath=`.status.conditions[?(@.type=="Started")].status`,name="Started",type=string
9495
// +kubebuilder:printcolumn:JSONPath=`.status.conditions[?(@.type=="Succeeded")].status`,name="Succeeded",type=string
9596
// +kubebuilder:printcolumn:JSONPath=`.metadata.creationTimestamp`,name="Age",type=date
9697
// +kubebuilder:printcolumn:JSONPath=`.spec.stagedRolloutStrategyName`,name="Strategy",priority=1,type=string
@@ -167,6 +168,13 @@ type UpdateRunSpec struct {
167168
// and recorded in the status field.
168169
// +kubebuilder:validation:Required
169170
StagedUpdateStrategyName string `json:"stagedRolloutStrategyName"`
171+
172+
// Started indicates whether the update run should be started.
173+
// When false or nil, the update run will initialize but not execute.
174+
// When true, the update run will begin execution.
175+
// Changing from true to false will gracefully stop the update run.
176+
// +kubebuilder:validation:Optional
177+
Started *bool `json:"started,omitempty"`
170178
}
171179

172180
// UpdateStrategySpecGetterSetter offers the functionality to work with UpdateStrategySpec.
@@ -346,7 +354,7 @@ type UpdateRunStatus struct {
346354
// +listMapKey=type
347355
//
348356
// Conditions is an array of current observed conditions for StagedUpdateRun.
349-
// Known conditions are "Initialized", "Progressing", "Succeeded".
357+
// Known conditions are "Initialized", "Started", "Progressing", "Succeeded".
350358
// +kubebuilder:validation:Optional
351359
Conditions []metav1.Condition `json:"conditions,omitempty"`
352360
}
@@ -364,6 +372,12 @@ const (
364372
// - "Unknown": The staged update run initialization has started.
365373
StagedUpdateRunConditionInitialized StagedUpdateRunConditionType = "Initialized"
366374

375+
// StagedUpdateRunConditionStarted indicates whether the staged update run has been started.
376+
// Its condition status can be one of the following:
377+
// - "True": The staged update run has been started and is ready to progress.
378+
// - "False": The staged update run is stopped or not yet started.
379+
StagedUpdateRunConditionStarted StagedUpdateRunConditionType = "Started"
380+
367381
// StagedUpdateRunConditionProgressing indicates whether the staged update run is making progress.
368382
// Its condition status can be one of the following:
369383
// - "True": The staged update run is making progress.
@@ -721,6 +735,7 @@ func (c *ClusterApprovalRequestList) GetApprovalRequestObjs() []ApprovalRequestO
721735
// +kubebuilder:printcolumn:JSONPath=`.spec.resourceSnapshotIndex`,name="Resource-Snapshot-Index",type=string
722736
// +kubebuilder:printcolumn:JSONPath=`.status.policySnapshotIndexUsed`,name="Policy-Snapshot-Index",type=string
723737
// +kubebuilder:printcolumn:JSONPath=`.status.conditions[?(@.type=="Initialized")].status`,name="Initialized",type=string
738+
// +kubebuilder:printcolumn:JSONPath=`.status.conditions[?(@.type=="Started")].status`,name="Started",type=string
724739
// +kubebuilder:printcolumn:JSONPath=`.status.conditions[?(@.type=="Succeeded")].status`,name="Succeeded",type=string
725740
// +kubebuilder:printcolumn:JSONPath=`.metadata.creationTimestamp`,name="Age",type=date
726741
// +kubebuilder:printcolumn:JSONPath=`.spec.stagedRolloutStrategyName`,name="Strategy",priority=1,type=string

apis/placement/v1beta1/zz_generated.deepcopy.go

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

config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,9 @@ spec:
11121112
- jsonPath: .status.conditions[?(@.type=="Initialized")].status
11131113
name: Initialized
11141114
type: string
1115+
- jsonPath: .status.conditions[?(@.type=="Started")].status
1116+
name: Started
1117+
type: string
11151118
- jsonPath: .status.conditions[?(@.type=="Succeeded")].status
11161119
name: Succeeded
11171120
type: string
@@ -1173,6 +1176,13 @@ spec:
11731176
are computed according to the referenced strategy when the update run starts
11741177
and recorded in the status field.
11751178
type: string
1179+
started:
1180+
description: |-
1181+
Started indicates whether the update run should be started.
1182+
When false or nil, the update run will initialize but not execute.
1183+
When true, the update run will begin execution.
1184+
Changing from true to false will gracefully stop the update run.
1185+
type: boolean
11761186
required:
11771187
- placementName
11781188
- resourceSnapshotIndex
@@ -1416,7 +1426,7 @@ spec:
14161426
conditions:
14171427
description: |-
14181428
Conditions is an array of current observed conditions for StagedUpdateRun.
1419-
Known conditions are "Initialized", "Progressing", "Succeeded".
1429+
Known conditions are "Initialized", "Started", "Progressing", "Succeeded".
14201430
items:
14211431
description: Condition contains details for one aspect of the current
14221432
state of this API Resource.

config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ spec:
3232
- jsonPath: .status.conditions[?(@.type=="Initialized")].status
3333
name: Initialized
3434
type: string
35+
- jsonPath: .status.conditions[?(@.type=="Started")].status
36+
name: Started
37+
type: string
3538
- jsonPath: .status.conditions[?(@.type=="Succeeded")].status
3639
name: Succeeded
3740
type: string
@@ -92,6 +95,13 @@ spec:
9295
are computed according to the referenced strategy when the update run starts
9396
and recorded in the status field.
9497
type: string
98+
started:
99+
description: |-
100+
Started indicates whether the update run should be started.
101+
When false or nil, the update run will initialize but not execute.
102+
When true, the update run will begin execution.
103+
Changing from true to false will gracefully stop the update run.
104+
type: boolean
95105
required:
96106
- placementName
97107
- resourceSnapshotIndex
@@ -335,7 +345,7 @@ spec:
335345
conditions:
336346
description: |-
337347
Conditions is an array of current observed conditions for StagedUpdateRun.
338-
Known conditions are "Initialized", "Progressing", "Succeeded".
348+
Known conditions are "Initialized", "Started", "Progressing", "Succeeded".
339349
items:
340350
description: Condition contains details for one aspect of the current
341351
state of this API Resource.

0 commit comments

Comments
 (0)