Skip to content

Commit dd251bd

Browse files
authored
fix: rebuild instance ops always is running for sharding component when inplace = false (#10054)
1 parent 5104421 commit dd251bd

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pkg/operations/rebuild_instance.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ func (r rebuildInstanceOpsHandler) ActionStartedCondition(reqCtx intctrlutil.Req
7878

7979
func (r rebuildInstanceOpsHandler) Action(reqCtx intctrlutil.RequestCtx, cli client.Client, opsRes *OpsResource) error {
8080
for _, v := range opsRes.OpsRequest.Spec.RebuildFrom {
81-
compStatus, ok := opsRes.Cluster.Status.Components[v.ComponentName]
82-
if !ok {
81+
compPhase := r.getCompStatusFromCluster(opsRes, v.ComponentName)
82+
if compPhase == nil {
8383
continue
8484
}
8585
// check if the component has matched the `Phase` condition
86-
if !opsRes.OpsRequest.Spec.Force && !slices.Contains([]appsv1.ComponentPhase{appsv1.FailedComponentPhase, appsv1.UpdatingComponentPhase}, compStatus.Phase) {
87-
return intctrlutil.NewFatalError(fmt.Sprintf(`the phase of component "%s" can not be %s`, v.ComponentName, compStatus.Phase))
86+
if !opsRes.OpsRequest.Spec.Force && !slices.Contains([]appsv1.ComponentPhase{appsv1.FailedComponentPhase, appsv1.UpdatingComponentPhase}, *compPhase) {
87+
return intctrlutil.NewFatalError(fmt.Sprintf(`the phase of component "%s" can not be %s`, v.ComponentName, *compPhase))
8888
}
8989
var (
9090
synthesizedComp *component.SynthesizedComponent
@@ -119,6 +119,16 @@ func (r rebuildInstanceOpsHandler) Action(reqCtx intctrlutil.RequestCtx, cli cli
119119
return nil
120120
}
121121

122+
func (r rebuildInstanceOpsHandler) getCompStatusFromCluster(opsRes *OpsResource, compName string) *appsv1.ComponentPhase {
123+
if compStatus, exist := opsRes.Cluster.Status.Components[compName]; exist {
124+
return &compStatus.Phase
125+
}
126+
if shardStatus, exist := opsRes.Cluster.Status.Shardings[compName]; exist {
127+
return &shardStatus.Phase
128+
}
129+
return nil
130+
}
131+
122132
func (r rebuildInstanceOpsHandler) validateRebuildInstanceWithHScale(reqCtx intctrlutil.RequestCtx,
123133
cli client.Client,
124134
opsRes *OpsResource,

0 commit comments

Comments
 (0)