Skip to content

Commit 60a130e

Browse files
fix: prevent MachineSetStatus from going into create/destroy loop
The `MachineSetStatus` resource getting modified in the finalizer removal function was causing it to go into a create/delete loop, filling up etcd. This issue is only observable when the `MachineSet` had the `MachineProvisionController` finalizer (when an infra provider is used). Change the modify function to effectively be an update, never create the resource. The fix is tested in a staging environment and confirmed to be resolving the issue. Co-authored-by: Artem Chernyshev <[email protected]> Signed-off-by: Utku Ozdemir <[email protected]>
1 parent e38b3b9 commit 60a130e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal/backend/runtime/omni/controllers/omni/machine_set_status.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package omni
77

88
import (
99
"context"
10+
"errors"
1011
"time"
1112

1213
"github.com/cosi-project/runtime/pkg/controller"
@@ -213,7 +214,14 @@ func (handler *machineSetStatusHandler) reconcileTearingDown(ctx context.Context
213214
}
214215

215216
updateStatus := func(clusterMachinesCount uint32) error {
216-
return safe.WriterModify(ctx, r, omni.NewMachineSetStatus(resources.DefaultNamespace, machineSet.Metadata().ID()), func(status *omni.MachineSetStatus) error {
217+
mss := omni.NewMachineSetStatus(resources.DefaultNamespace, machineSet.Metadata().ID())
218+
notFoundErr := errors.New("not found")
219+
220+
modifyErr := safe.WriterModify(ctx, r, mss, func(status *omni.MachineSetStatus) error {
221+
if status.Metadata().Version().Value() == 0 {
222+
return notFoundErr
223+
}
224+
217225
status.TypedSpec().Value.Phase = specs.MachineSetPhase_Destroying
218226
status.TypedSpec().Value.Ready = false
219227
status.TypedSpec().Value.Machines = &specs.Machines{
@@ -223,6 +231,11 @@ func (handler *machineSetStatusHandler) reconcileTearingDown(ctx context.Context
223231

224232
return nil
225233
}, controller.WithExpectedPhaseAny())
234+
if modifyErr != nil && !errors.Is(modifyErr, notFoundErr) {
235+
return modifyErr
236+
}
237+
238+
return nil
226239
}
227240

228241
clusterMachinesCount := uint32(len(rc.GetClusterMachines()))

0 commit comments

Comments
 (0)