Skip to content

Commit 040bf28

Browse files
committed
fixes
Signed-off-by: Britania Rodriguez Reyes <britaniar@microsoft.com>
1 parent 9333350 commit 040bf28

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

pkg/controllers/updaterun/execution.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,24 @@ func (r *Reconciler) execute(
6161
updateRun placementv1beta1.UpdateRunObj,
6262
updatingStageIndex int,
6363
toBeUpdatedBindings, toBeDeletedBindings []placementv1beta1.BindingObj,
64-
) (finished bool, waitTime time.Duration, err error) {
64+
) (finished bool, waitTime time.Duration, execErr error) {
6565
updateRunStatus := updateRun.GetUpdateRunStatus()
6666
var updatingStageStatus *placementv1beta1.StageUpdatingStatus
6767

6868
// Set up defer function to handle errStagedUpdatedAborted.
69-
defer checkIfErrorStagedUpdateAborted(err, updateRun, updatingStageStatus)
69+
defer func() {
70+
checkIfErrorStagedUpdateAborted(execErr, updateRun, updatingStageStatus)
71+
}()
7072

7173
// Mark updateRun as progressing if it's not already marked as waiting or stuck.
7274
// This avoids triggering an unnecessary in-memory transition from stuck (waiting) -> progressing -> stuck (waiting),
7375
// which would update the lastTransitionTime even though the status hasn't effectively changed.
7476
markUpdateRunProgressingIfNotWaitingOrStuck(updateRun)
7577
if updatingStageIndex < len(updateRunStatus.StagesStatus) {
7678
updatingStageStatus = &updateRunStatus.StagesStatus[updatingStageIndex]
77-
approved, err := r.checkBeforeStageTasksStatus(ctx, updatingStageIndex, updateRun)
78-
if err != nil {
79-
return false, 0, err
79+
approved, execErr := r.checkBeforeStageTasksStatus(ctx, updatingStageIndex, updateRun)
80+
if execErr != nil {
81+
return false, 0, execErr
8082
}
8183
if !approved {
8284
markStageUpdatingWaiting(updatingStageStatus, updateRun.GetGeneration(), "Not all before-stage tasks are completed, waiting for approval")
@@ -87,13 +89,13 @@ func (r *Reconciler) execute(
8789
if err != nil {
8890
return false, 0, err
8991
}
90-
waitTime, err = r.executeUpdatingStage(ctx, updateRun, updatingStageIndex, toBeUpdatedBindings, maxConcurrency)
92+
waitTime, execErr = r.executeUpdatingStage(ctx, updateRun, updatingStageIndex, toBeUpdatedBindings, maxConcurrency)
9193
// The execution has not finished yet.
92-
return false, waitTime, err
94+
return false, waitTime, execErr
9395
}
9496
// All the stages have finished, now start the delete stage.
95-
finished, err = r.executeDeleteStage(ctx, updateRun, toBeDeletedBindings)
96-
return finished, clusterUpdatingWaitTime, err
97+
finished, execErr = r.executeDeleteStage(ctx, updateRun, toBeDeletedBindings)
98+
return finished, clusterUpdatingWaitTime, execErr
9799
}
98100

99101
// checkBeforeStageTasksStatus checks if the before stage tasks have finished.

pkg/controllers/updaterun/stop.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ func (r *Reconciler) stop(
2525
var updatingStageStatus *placementv1beta1.StageUpdatingStatus
2626

2727
// Set up defer function to handle errStagedUpdatedAborted.
28-
defer checkIfErrorStagedUpdateAborted(stopErr, updateRun, updatingStageStatus)
28+
defer func() {
29+
checkIfErrorStagedUpdateAborted(stopErr, updateRun, updatingStageStatus)
30+
}()
2931

3032
markUpdateRunStopping(updateRun)
3133

@@ -197,6 +199,7 @@ func checkIfErrorStagedUpdateAborted(err error, updateRun placementv1beta1.Updat
197199
updateRunStatus := updateRun.GetUpdateRunStatus()
198200
if errors.Is(err, errStagedUpdatedAborted) {
199201
if updatingStageStatus != nil {
202+
klog.InfoS("The update run is aborted due to unexpected behavior in updating stage, marking the stage as failed", "stage", updatingStageStatus.StageName, "updateRun", klog.KObj(updateRun))
200203
markStageUpdatingFailed(updatingStageStatus, updateRun.GetGeneration(), err.Error())
201204
} else {
202205
// Handle deletion stage case.

test/e2e/actuals_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,16 +2068,12 @@ func updateRunStageTaskSucceedConditions(generation int64, taskType placementv1b
20682068
}
20692069

20702070
func updateRunSucceedConditions(generation int64) []metav1.Condition {
2071-
initializeCondGeneration := generation
2072-
if generation > 1 {
2073-
initializeCondGeneration = 1
2074-
}
20752071
return []metav1.Condition{
20762072
{
20772073
Type: string(placementv1beta1.StagedUpdateRunConditionInitialized),
20782074
Status: metav1.ConditionTrue,
20792075
Reason: condition.UpdateRunInitializeSucceededReason,
2080-
ObservedGeneration: initializeCondGeneration,
2076+
ObservedGeneration: generation,
20812077
},
20822078
{
20832079
Type: string(placementv1beta1.StagedUpdateRunConditionProgressing),

test/e2e/cluster_staged_updaterun_test.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ var _ = Describe("test CRP rollout with staged update run", func() {
16681668
})
16691669
})
16701670

1671-
Context("Test resource rollout with staged update run by update run states - (Initialize -> Run)", Ordered, func() {
1671+
FContext("Test resource rollout with staged update run by update run states - (Initialize -> Run -> Stop -> Run)", Ordered, func() {
16721672
updateRunNames := []string{}
16731673
var strategy *placementv1beta1.ClusterStagedUpdateStrategy
16741674

@@ -1758,9 +1758,43 @@ var _ = Describe("test CRP rollout with staged update run", func() {
17581758
validateAndApproveClusterApprovalRequests(updateRunNames[0], envCanary, placementv1beta1.AfterStageApprovalTaskNameFmt, placementv1beta1.AfterStageTaskLabelValue)
17591759
})
17601760

1761-
It("Should rollout resources to all the members and complete the cluster staged update run successfully", func() {
1761+
It("Should not rollout to all member clusters while waiting for beforeStageTask approval for prod stage", func() {
1762+
By("Validating not rolled out to member-cluster-1 and member-cluster-3 yet")
1763+
checkIfRemovedWorkResourcesFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[0], allMemberClusters[2]})
1764+
checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[1]})
1765+
1766+
By("Validating crp status as member-cluster-2 updated only")
1767+
crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(nil, "", false, allMemberClusterNames, []string{"", resourceSnapshotIndex1st, ""}, []bool{false, true, false}, nil, nil)
1768+
Eventually(crpStatusUpdatedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update CRP %s status as expected", crpName)
1769+
})
1770+
1771+
It("Should not rollout to all member clusters after stopping update run", func() {
1772+
By("Updating update run state to Stop")
1773+
updateClusterStagedUpdateRunState(updateRunNames[0], placementv1beta1.StateStop)
1774+
1775+
By("Validating not rolled out to member-cluster-1 and member-cluster-3 yet")
1776+
checkIfRemovedWorkResourcesFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[0], allMemberClusters[2]})
1777+
checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[1]})
1778+
1779+
By("Validating crp status as member-cluster-2 updated")
1780+
crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(nil, "", false, allMemberClusterNames, []string{"", resourceSnapshotIndex1st, ""}, []bool{false, true, false}, nil, nil)
1781+
Eventually(crpStatusUpdatedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update CRP %s status as expected", crpName)
1782+
})
1783+
1784+
It("Should complete rollout to all member after update run state is Run and beforeStageTask approval", func() {
1785+
By("Validating not rolled out to member-cluster-1 and member-cluster-3 yet")
1786+
checkIfRemovedWorkResourcesFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[0], allMemberClusters[2]})
1787+
1788+
// Update the update run state back to Run.
1789+
By("Updating the update run state back to Run")
1790+
updateClusterStagedUpdateRunState(updateRunNames[0], placementv1beta1.StateRun)
1791+
17621792
validateAndApproveClusterApprovalRequests(updateRunNames[0], envProd, placementv1beta1.BeforeStageApprovalTaskNameFmt, placementv1beta1.BeforeStageTaskLabelValue)
17631793

1794+
By("All member clusters should have work resources placed")
1795+
checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1], allMemberClusters[2]})
1796+
1797+
By("Validating update run has succeeded after resuming")
17641798
csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil, true)
17651799
Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0])
17661800
checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters)

0 commit comments

Comments
 (0)