Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/controllers/updaterun/controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ func generateTestClusterStagedUpdateStrategy() *placementv1beta1.ClusterStagedUp
Duration: time.Second * 4,
},
},
{
Type: placementv1beta1.AfterStageTaskTypeApproval,
},
},
},
{
Expand All @@ -350,6 +353,12 @@ func generateTestClusterStagedUpdateStrategy() *placementv1beta1.ClusterStagedUp
{
Type: placementv1beta1.AfterStageTaskTypeApproval,
},
{
Type: placementv1beta1.AfterStageTaskTypeTimedWait,
WaitTime: metav1.Duration{
Duration: time.Second * 4,
},
},
},
},
},
Expand Down
42 changes: 27 additions & 15 deletions pkg/controllers/updaterun/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ func (r *Reconciler) checkAfterStageTasksStatus(ctx context.Context, updatingSta
klog.V(2).InfoS("There is no after stage task for this stage", "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
return true, 0, nil
}
passed := true
afterStageWaitTime := time.Duration(-1)
for i, task := range updatingStage.AfterStageTasks {
switch task.Type {
case placementv1beta1.AfterStageTaskTypeTimedWait:
Expand All @@ -275,10 +277,12 @@ func (r *Reconciler) checkAfterStageTasksStatus(ctx context.Context, updatingSta
waitTime := time.Until(waitStartTime.Add(task.WaitTime.Duration))
if waitTime > 0 {
klog.V(2).InfoS("The after stage task still need to wait", "waitStartTime", waitStartTime, "waitTime", task.WaitTime, "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
return false, waitTime, nil
passed = false
afterStageWaitTime = waitTime
} else {
markAfterStageWaitTimeElapsed(&updatingStageStatus.AfterStageTaskStatus[i], updateRun.Generation)
klog.V(2).InfoS("The after stage wait task has completed", "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
}
markAfterStageWaitTimeElapsed(&updatingStageStatus.AfterStageTaskStatus[i], updateRun.Generation)
klog.V(2).InfoS("The after stage wait task has completed", "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
case placementv1beta1.AfterStageTaskTypeApproval:
// Check if the approval request has been created.
approvalRequest := placementv1beta1.ClusterApprovalRequest{
Expand Down Expand Up @@ -310,18 +314,24 @@ func (r *Reconciler) checkAfterStageTasksStatus(ctx context.Context, updatingSta
return false, -1, fmt.Errorf("%w: %s", errStagedUpdatedAborted, unexpectedErr.Error())
}
approvalAccepted := condition.IsConditionStatusTrue(meta.FindStatusCondition(approvalRequest.Status.Conditions, string(placementv1beta1.ApprovalRequestConditionApprovalAccepted)), approvalRequest.Generation)
// Approved state should not change once the approval is accepted.
if !approvalAccepted && !condition.IsConditionStatusTrue(meta.FindStatusCondition(approvalRequest.Status.Conditions, string(placementv1beta1.ApprovalRequestConditionApproved)), approvalRequest.Generation) {
approved := condition.IsConditionStatusTrue(meta.FindStatusCondition(approvalRequest.Status.Conditions, string(placementv1beta1.ApprovalRequestConditionApproved)), approvalRequest.Generation)
if !approvalAccepted && !approved {
klog.V(2).InfoS("The approval request has not been approved yet", "approvalRequestTask", requestRef, "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
return false, -1, nil
passed = false
continue
}
klog.V(2).InfoS("The approval request has been approved", "approvalRequestTask", requestRef, "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
if !approvalAccepted {
if err = r.updateApprovalRequestAccepted(ctx, &approvalRequest); err != nil {
klog.ErrorS(err, "Failed to accept the approved approval request", "approvalRequest", requestRef, "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
// retriable err
return false, 0, err
if approved {
klog.V(2).InfoS("The approval request has been approved", "approvalRequestTask", requestRef, "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
if !approvalAccepted {
if err = r.updateApprovalRequestAccepted(ctx, &approvalRequest); err != nil {
klog.ErrorS(err, "Failed to accept the approved approval request", "approvalRequest", requestRef, "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
// retriable err
return false, -1, err
}
}
} else {
// Approved state should not change once the approval is accepted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Approved state should not change once the approval is accepted.
// We land here only if the approval is accepted. Approved state should not change once the approval is accepted.

klog.V(2).InfoS("The approval request has been approval-accepted, ignoring changing back to unapproved", "approvalRequestTask", requestRef, "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
}
markAfterStageRequestApproved(&updatingStageStatus.AfterStageTaskStatus[i], updateRun.Generation)
} else {
Expand All @@ -333,12 +343,14 @@ func (r *Reconciler) checkAfterStageTasksStatus(ctx context.Context, updatingSta
// The approval request has been created for the first time.
klog.V(2).InfoS("The approval request has been created", "approvalRequestTask", requestRef, "stage", updatingStage.Name, "clusterStagedUpdateRun", updateRunRef)
markAfterStageRequestCreated(&updatingStageStatus.AfterStageTaskStatus[i], updateRun.Generation)
return false, -1, nil
passed = false
}
}
}
// All the after stage tasks have been finished or the for loop will return before this line.
return true, 0, nil
if passed {
afterStageWaitTime = 0
}
return passed, afterStageWaitTime, nil
}

// updateBindingRolloutStarted updates the binding status to indicate the rollout has started.
Expand Down
Loading
Loading