Skip to content

Commit

Permalink
chore: fix the phase of the upgrade ops is incorrect (#8189)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Sep 24, 2024
1 parent bdfc359 commit baea51d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
18 changes: 8 additions & 10 deletions controllers/apps/operations/ops_comp_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,14 @@ func (c componentOpsHelper) reconcileActionWithComponentOps(reqCtx intctrlutil.R
componentPhase = compObj.Status.Phase
}
// conditions whether ops is running:
// 1. completedProgressCount is not equal to expectProgressCount when the ops do not need to wait component phase to a terminal phase.
// 2. the component phase is not a terminal phase and no completed progress.
if pgResource.noWaitComponentCompleted {
if expectCount != completedCount {
opsIsCompleted = false
}
} else {
if !slices.Contains(appsv1alpha1.GetComponentTerminalPhases(), componentPhase) || completedCount == 0 {
opsIsCompleted = false
}
// 1. completedProgressCount is not equal to expectProgressCount.
// 2. the component phase is not a terminal phase or no completed progress if the ops
// needs to wait for the component phase to reach a terminal state.
if expectCount != completedCount {
opsIsCompleted = false
} else if !pgResource.noWaitComponentCompleted &&
(!slices.Contains(appsv1alpha1.GetComponentTerminalPhases(), componentPhase) || completedCount == 0) {
opsIsCompleted = false
}
opsRequest.Status.Components[pgResource.compOps.GetComponentName()] = opsCompStatus
}
Expand Down
9 changes: 9 additions & 0 deletions controllers/apps/operations/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ var _ = Describe("Upgrade OpsRequest", func() {
Expect(err).ShouldNot(HaveOccurred())
mockComponentIsOperating(opsRes.Cluster, appsv1alpha1.UpdatingClusterCompPhase,
consensusComp, statelessComp, statefulComp)
Expect(testapps.ChangeObjStatus(&testCtx, opsRes.OpsRequest, func() {
opsRes.OpsRequest.Status.Phase = appsv1alpha1.OpsRunningPhase
})).Should(Succeed())
}

mockClusterRunning := func(clusterObject *appsv1alpha1.Cluster) {
Expand Down Expand Up @@ -254,6 +257,12 @@ var _ = Describe("Upgrade OpsRequest", func() {
By("mock upgrade OpsRequest phase is Running")
makeUpgradeOpsIsRunning(reqCtx, opsRes)

By("the ops is expected to be Running when the component phase is in a terminal state but progress is not completed")
mockComponentIsOperating(opsRes.Cluster, appsv1alpha1.RunningClusterCompPhase, consensusComp)
_, err := GetOpsManager().Reconcile(reqCtx, k8sClient, opsRes)
Expect(err).ShouldNot(HaveOccurred())
Eventually(testapps.GetOpsRequestPhase(&testCtx, client.ObjectKeyFromObject(opsRes.OpsRequest))).Should(Equal(appsv1alpha1.OpsRunningPhase))

By("expect upgrade successfully")
_ = testapps.MockInstanceSetPod(&testCtx, nil, clusterName, statelessComp, fmt.Sprintf(clusterName+"-"+statelessComp+"-0"), "", "")
_ = testapps.MockInstanceSetPods(&testCtx, nil, clusterObject, statefulComp)
Expand Down

0 comments on commit baea51d

Please sign in to comment.