Skip to content

Commit ba884f5

Browse files
authored
fix: fix the update run states (#363)
1 parent 83bc664 commit ba884f5

File tree

9 files changed

+123
-214
lines changed

9 files changed

+123
-214
lines changed

apis/placement/v1beta1/stageupdate_types.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,30 +152,25 @@ func (c *ClusterStagedUpdateRun) SetUpdateRunStatus(status UpdateRunStatus) {
152152
type State string
153153

154154
const (
155-
// StateInitialized describes user intent to initialize but not execute the update run.
155+
// StateInitialize describes user intent to initialize but not run the update run.
156156
// This is the default state when an update run is created.
157-
// Users can subsequently set the state to Execute or Abandon.
158-
StateInitialized State = "Initialize"
157+
// Users can subsequently set the state to Run.
158+
StateInitialize State = "Initialize"
159159

160-
// StateExecuted describes user intent to execute (or resume execution if paused).
161-
// Users can subsequently set the state to Pause or Abandon.
162-
StateExecuted State = "Execute"
160+
// StateRun describes user intent to execute (or resume execution if stopped).
161+
// Users can subsequently set the state to Stop.
162+
StateRun State = "Run"
163163

164-
// StateStopped describes user intent to pause the update run.
165-
// Users can subsequently set the state to Execute or Abandon.
166-
StateStopped State = "Pause"
167-
168-
// StateAbandoned describes user intent to abandon the update run.
169-
// This is a terminal state; once set, it cannot be changed.
170-
StateAbandoned State = "Abandon"
164+
// StateStop describes user intent to stop the update run.
165+
// Users can subsequently set the state to Run.
166+
StateStop State = "Stop"
171167
)
172168

173169
// UpdateRunSpec defines the desired rollout strategy and the snapshot indices of the resources to be updated.
174170
// It specifies a stage-by-stage update process across selected clusters for the given ResourcePlacement object.
175-
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.state) && oldSelf.state == 'Initialize' && self.state == 'Pause')",message="invalid state transition: cannot transition from Initialize to Pause"
176-
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.state) && oldSelf.state == 'Execute' && self.state == 'Initialize')",message="invalid state transition: cannot transition from Execute to Initialize"
177-
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.state) && oldSelf.state == 'Pause' && self.state == 'Initialize')",message="invalid state transition: cannot transition from Pause to Initialize"
178-
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.state) || oldSelf.state != 'Abandon' || self.state == 'Abandon'",message="invalid state transition: Abandon is a terminal state and cannot transition to any other state"
171+
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.state) && oldSelf.state == 'Initialize' && self.state == 'Stop')",message="invalid state transition: cannot transition from Initialize to Stop"
172+
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.state) && oldSelf.state == 'Run' && self.state == 'Initialize')",message="invalid state transition: cannot transition from Run to Initialize"
173+
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.state) && oldSelf.state == 'Stop' && self.state == 'Initialize')",message="invalid state transition: cannot transition from Stop to Initialize"
179174
type UpdateRunSpec struct {
180175
// PlacementName is the name of placement that this update run is applied to.
181176
// There can be multiple active update runs for each placement, but
@@ -201,12 +196,11 @@ type UpdateRunSpec struct {
201196

202197
// State indicates the desired state of the update run.
203198
// Initialize: The update run should be initialized but execution should not start (default).
204-
// Execute: The update run should execute or resume execution.
205-
// Pause: The update run should pause execution.
206-
// Abandon: The update run should be abandoned and terminated.
199+
// Run: The update run should execute or resume execution.
200+
// Stop: The update run should stop execution.
207201
// +kubebuilder:validation:Optional
208202
// +kubebuilder:default=Initialize
209-
// +kubebuilder:validation:Enum=Initialize;Execute;Pause;Abandon
203+
// +kubebuilder:validation:Enum=Initialize;Run;Stop
210204
State State `json:"state,omitempty"`
211205
}
212206

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,36 +1189,28 @@ spec:
11891189
description: |-
11901190
State indicates the desired state of the update run.
11911191
Initialize: The update run should be initialized but execution should not start (default).
1192-
Execute: The update run should execute or resume execution.
1193-
Pause: The update run should pause execution.
1194-
Abandon: The update run should be abandoned and terminated.
1192+
Run: The update run should execute or resume execution.
1193+
Stop: The update run should stop execution.
11951194
enum:
11961195
- Initialize
1197-
- Execute
1198-
- Pause
1199-
- Abandon
1196+
- Run
1197+
- Stop
12001198
type: string
12011199
required:
12021200
- placementName
12031201
- stagedRolloutStrategyName
12041202
type: object
12051203
x-kubernetes-validations:
12061204
- message: 'invalid state transition: cannot transition from Initialize
1207-
to Pause'
1205+
to Stop'
12081206
rule: '!(has(oldSelf.state) && oldSelf.state == ''Initialize'' && self.state
1209-
== ''Pause'')'
1210-
- message: 'invalid state transition: cannot transition from Execute to
1211-
Initialize'
1212-
rule: '!(has(oldSelf.state) && oldSelf.state == ''Execute'' && self.state
1207+
== ''Stop'')'
1208+
- message: 'invalid state transition: cannot transition from Run to Initialize'
1209+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Run'' && self.state
12131210
== ''Initialize'')'
1214-
- message: 'invalid state transition: cannot transition from Pause to
1215-
Initialize'
1216-
rule: '!(has(oldSelf.state) && oldSelf.state == ''Pause'' && self.state
1211+
- message: 'invalid state transition: cannot transition from Stop to Initialize'
1212+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Stop'' && self.state
12171213
== ''Initialize'')'
1218-
- message: 'invalid state transition: Abandon is a terminal state and
1219-
cannot transition to any other state'
1220-
rule: '!has(oldSelf.state) || oldSelf.state != ''Abandon'' || self.state
1221-
== ''Abandon'''
12221214
status:
12231215
description: The observed status of ClusterStagedUpdateRun.
12241216
properties:

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,36 +109,28 @@ spec:
109109
description: |-
110110
State indicates the desired state of the update run.
111111
Initialize: The update run should be initialized but execution should not start (default).
112-
Execute: The update run should execute or resume execution.
113-
Pause: The update run should pause execution.
114-
Abandon: The update run should be abandoned and terminated.
112+
Run: The update run should execute or resume execution.
113+
Stop: The update run should stop execution.
115114
enum:
116115
- Initialize
117-
- Execute
118-
- Pause
119-
- Abandon
116+
- Run
117+
- Stop
120118
type: string
121119
required:
122120
- placementName
123121
- stagedRolloutStrategyName
124122
type: object
125123
x-kubernetes-validations:
126124
- message: 'invalid state transition: cannot transition from Initialize
127-
to Pause'
125+
to Stop'
128126
rule: '!(has(oldSelf.state) && oldSelf.state == ''Initialize'' && self.state
129-
== ''Pause'')'
130-
- message: 'invalid state transition: cannot transition from Execute to
131-
Initialize'
132-
rule: '!(has(oldSelf.state) && oldSelf.state == ''Execute'' && self.state
127+
== ''Stop'')'
128+
- message: 'invalid state transition: cannot transition from Run to Initialize'
129+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Run'' && self.state
133130
== ''Initialize'')'
134-
- message: 'invalid state transition: cannot transition from Pause to
135-
Initialize'
136-
rule: '!(has(oldSelf.state) && oldSelf.state == ''Pause'' && self.state
131+
- message: 'invalid state transition: cannot transition from Stop to Initialize'
132+
rule: '!(has(oldSelf.state) && oldSelf.state == ''Stop'' && self.state
137133
== ''Initialize'')'
138-
- message: 'invalid state transition: Abandon is a terminal state and
139-
cannot transition to any other state'
140-
rule: '!has(oldSelf.state) || oldSelf.state != ''Abandon'' || self.state
141-
== ''Abandon'''
142134
status:
143135
description: The observed status of StagedUpdateRun.
144136
properties:

pkg/controllers/updaterun/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req runtime.Request) (runtim
130130
}
131131
return runtime.Result{}, initErr
132132
}
133-
updatingStageIndex = 0 // start from the first stage (typically for Initialize or Execute states).
133+
updatingStageIndex = 0 // start from the first stage (typically for Initialize or Run states).
134134
klog.V(2).InfoS("Initialized the updateRun", "state", state, "updateRun", runObjRef)
135135
} else {
136136
klog.V(2).InfoS("The updateRun is initialized", "state", state, "updateRun", runObjRef)
@@ -159,7 +159,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req runtime.Request) (runtim
159159
}
160160

161161
// Execute the updateRun.
162-
if state == placementv1beta1.StateExecuted {
162+
if state == placementv1beta1.StateRun {
163163
klog.V(2).InfoS("Continue to execute the updateRun", "state", state, "updatingStageIndex", updatingStageIndex, "updateRun", runObjRef)
164164
finished, waitTime, execErr := r.execute(ctx, updateRun, updatingStageIndex, toBeUpdatedBindings, toBeDeletedBindings)
165165
if errors.Is(execErr, errStagedUpdatedAborted) {

pkg/controllers/updaterun/controller_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func generateTestClusterStagedUpdateRun() *placementv1beta1.ClusterStagedUpdateR
351351
PlacementName: testCRPName,
352352
ResourceSnapshotIndex: testResourceSnapshotIndex,
353353
StagedUpdateStrategyName: testUpdateStrategyName,
354-
State: placementv1beta1.StateExecuted,
354+
State: placementv1beta1.StateRun,
355355
},
356356
}
357357
}

pkg/controllers/updaterun/execution_integration_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,11 +1518,11 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
15181518
})
15191519
})
15201520

1521-
Context("Cluster staged update run should update clusters one by one - different states (Initialized -> Executed)", Ordered, func() {
1521+
Context("Cluster staged update run should update clusters one by one - different states (Initialize -> Run)", Ordered, func() {
15221522
var wantMetrics []*promclient.Metric
15231523
BeforeAll(func() {
15241524
By("Creating a new clusterStagedUpdateRun")
1525-
updateRun.Spec.State = placementv1beta1.StateInitialized
1525+
updateRun.Spec.State = placementv1beta1.StateInitialize
15261526
Expect(k8sClient.Create(ctx, updateRun)).To(Succeed())
15271527

15281528
By("Validating the initialization succeeded and but not execution started")
@@ -1550,9 +1550,9 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
15501550
validateNotBoundBindingState(ctx, binding)
15511551
})
15521552

1553-
It("Should start execution after changing the state to Execute", func() {
1554-
By("Updating the updateRun state to Execute")
1555-
updateRun.Spec.State = placementv1beta1.StateExecuted
1553+
It("Should start execution after changing the state to Run", func() {
1554+
By("Updating the updateRun state to Run")
1555+
updateRun.Spec.State = placementv1beta1.StateRun
15561556
Expect(k8sClient.Update(ctx, updateRun)).Should(Succeed(), "failed to update the updateRun state")
15571557

15581558
By("Validating the execution has started")

0 commit comments

Comments
 (0)