Skip to content

Commit eb10bb3

Browse files
committed
address most comments
Signed-off-by: Britania Rodriguez Reyes <britaniar@microsoft.com>
1 parent 77a73ab commit eb10bb3

File tree

3 files changed

+305
-38
lines changed

3 files changed

+305
-38
lines changed

pkg/controllers/updaterun/stop.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,12 @@ func (r *Reconciler) stopDeleteStage(
156156
}
157157
// In validation, we already check the binding must exist in the status.
158158
delete(existingDeleteStageClusterMap, bindingSpec.TargetCluster)
159+
// Make sure the cluster is not marked as deleted as the binding is still there.
159160
if condition.IsConditionStatusTrue(meta.FindStatusCondition(curCluster.Conditions, string(placementv1beta1.ClusterUpdatingConditionSucceeded)), updateRun.GetGeneration()) {
160161
// The cluster status is marked as deleted.
161-
continue
162+
unexpectedErr := controller.NewUnexpectedBehaviorError(fmt.Errorf("the deleted cluster `%s` in the deleting stage still has a binding", bindingSpec.TargetCluster))
163+
klog.ErrorS(unexpectedErr, "The cluster in the deleting stage is not removed yet but marked as deleted", "cluster", curCluster.ClusterName, "updateRun", updateRunRef)
164+
return false, fmt.Errorf("%w: %s", errStagedUpdatedAborted, unexpectedErr.Error())
162165
}
163166
if condition.IsConditionStatusTrue(meta.FindStatusCondition(curCluster.Conditions, string(placementv1beta1.ClusterUpdatingConditionStarted)), updateRun.GetGeneration()) {
164167
// The cluster status is marked as being deleted.
@@ -182,7 +185,19 @@ func (r *Reconciler) stopDeleteStage(
182185
}
183186

184187
klog.V(2).InfoS("The delete stage is stopping", "numberOfDeletingClusters", len(toBeDeletedBindings), "updateRun", updateRunRef)
185-
if len(toBeDeletedBindings) == 0 {
188+
allDeletingClustersDeleted := true
189+
for _, clusterStatus := range updateRunStatus.DeletionStageStatus.Clusters {
190+
klog.InfoS("Checking deletion status of cluster in delete stage", "cluster", clusterStatus.ClusterName, "conditions", clusterStatus.Conditions, "updateRun", updateRunRef)
191+
if condition.IsConditionStatusTrue(meta.FindStatusCondition(clusterStatus.Conditions,
192+
string(placementv1beta1.ClusterUpdatingConditionStarted)), updateRun.GetGeneration()) && !condition.IsConditionStatusTrue(
193+
meta.FindStatusCondition(clusterStatus.Conditions, string(placementv1beta1.ClusterUpdatingConditionSucceeded)),
194+
updateRun.GetGeneration()) {
195+
allDeletingClustersDeleted = false
196+
break
197+
}
198+
}
199+
200+
if allDeletingClustersDeleted || len(toBeDeletedBindings) == 0 {
186201
markStageUpdatingStopped(updateRunStatus.DeletionStageStatus, updateRun.GetGeneration())
187202
}
188203
return len(toBeDeletedBindings) == 0, nil
@@ -224,13 +239,13 @@ func markStageUpdatingStopped(stageUpdatingStatus *placementv1beta1.StageUpdatin
224239
}
225240

226241
func checkIfErrorStagedUpdateAborted(err error, updateRun placementv1beta1.UpdateRunObj, updatingStageStatus *placementv1beta1.StageUpdatingStatus) {
227-
updateRunStatus := updateRun.GetUpdateRunStatus()
228242
if errors.Is(err, errStagedUpdatedAborted) {
229243
if updatingStageStatus != nil {
230244
klog.InfoS("The update run is aborted due to unrecoverable behavior in updating stage, marking the stage as failed", "stage", updatingStageStatus.StageName, "updateRun", klog.KObj(updateRun))
231245
markStageUpdatingFailed(updatingStageStatus, updateRun.GetGeneration(), err.Error())
232246
} else {
233247
// Handle deletion stage case.
248+
updateRunStatus := updateRun.GetUpdateRunStatus()
234249
markStageUpdatingFailed(updateRunStatus.DeletionStageStatus, updateRun.GetGeneration(), err.Error())
235250
}
236251
}

pkg/controllers/updaterun/stop_integration_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ var _ = Describe("UpdateRun stop tests", func() {
231231
validateUpdateRunMetricsEmitted(wantMetrics...)
232232
})
233233

234-
It("Should be stopping the in middle of cluster updating when update run state is Stop", func() {
234+
It("Should be stopping in the middle of cluster updating when update run state is Stop", func() {
235235
By("Updating updateRun state to Stop")
236236
updateRun = updateClusterStagedUpdateRunState(updateRun.Name, placementv1beta1.StateStop)
237237
// Update the test's want status to match the new generation.
@@ -251,7 +251,7 @@ var _ = Describe("UpdateRun stop tests", func() {
251251
})
252252

253253
It("Should wait for cluster to finish updating before update run is completely stopped", func() {
254-
By("Validating the 2nd clusterResourceBinding is updated to Bound")
254+
By("Validating the 2nd clusterResourceBinding is updated to Bound")
255255
binding := resourceBindings[numTargetClusters-3] // cluster-7
256256
validateBindingState(ctx, binding, resourceSnapshot.Name, updateRun, 0)
257257

@@ -812,6 +812,10 @@ var _ = Describe("UpdateRun stop tests", func() {
812812
if !apierrors.IsNotFound(err) {
813813
return fmt.Errorf("get binding %s does not return a not-found error: %w", binding.Name, err)
814814
}
815+
816+
if !binding.DeletionTimestamp.IsZero() {
817+
return fmt.Errorf("binding %s is not deleted yet", binding.Name)
818+
}
815819
}
816820
return nil
817821
}, timeout, interval).Should(Succeed(), "failed to validate the deletion of the to-be-deleted bindings")

0 commit comments

Comments
 (0)