Skip to content

Commit

Permalink
fix: remove MaintenanceConfigPatchController finalizers
Browse files Browse the repository at this point in the history
It looks like they weren't removed for Talos < 1.5.0, due to absence of
the maintenance config patches for these machines.

Signed-off-by: Artem Chernyshev <[email protected]>
  • Loading branch information
Unix4ever committed Oct 25, 2024
1 parent 21455d9 commit 8da2328
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/backend/runtime/omni/migration/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ func NewManager(state state.State, logger *zap.Logger) *Manager {
callback: deleteAllResources(resource.NewMetadata(resources.DefaultNamespace, MachineClassStatusType, "", resource.VersionUndefined)),
name: "deleteMachineClassStatuses",
},
{
callback: removeMaintenanceConfigPatchFinalizers,
name: "removeMaintenanceConfigPatchFinalizers",
},
},
}
}
Expand Down
33 changes: 33 additions & 0 deletions internal/backend/runtime/omni/migration/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,39 @@ func (suite *MigrationSuite) TestDeleteMachineClassStatuses() {
}, "deleteMachineClassStatuses")
}

func (suite *MigrationSuite) TestRemoveMaintenanceConfigPatchFinalizers() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

deprecatedControllerName := "MaintenanceConfigPatchController"

m1Status := omni.NewMachineStatus(resources.DefaultNamespace, "machine1")
m1Status.Metadata().Finalizers().Add(deprecatedControllerName)

m2Status := omni.NewMachineStatus(resources.DefaultNamespace, "machine2")
m2Status.Metadata().Finalizers().Add(deprecatedControllerName)
m2Status.Metadata().SetPhase(resource.PhaseTearingDown)

m3Status := omni.NewMachineStatus(resources.DefaultNamespace, "machine3")
m3Status.Metadata().Finalizers().Add(deprecatedControllerName)

suite.Require().NoError(suite.state.Create(ctx, m1Status, state.WithCreateOwner("MachineStatusController")))
suite.Require().NoError(suite.state.Create(ctx, m2Status, state.WithCreateOwner("MachineStatusController")))
suite.Require().NoError(suite.state.Create(ctx, m3Status, state.WithCreateOwner("MachineStatusController")))

suite.Require().NoError(suite.manager.Run(ctx), migration.WithFilter(
func(name string) bool {
return name == "removeMaintenanceConfigPatchFinalizers"
},
))

rtestutils.AssertAll(ctx, suite.T(), suite.state, func(
res *omni.MachineStatus, assert *assert.Assertions,
) {
assert.True(res.Metadata().Finalizers().Empty())
})
}

func TestMigrationSuite(t *testing.T) {
t.Parallel()

Expand Down
14 changes: 14 additions & 0 deletions internal/backend/runtime/omni/migration/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,3 +1319,17 @@ func deleteAllResources(md resource.Metadata) func(context.Context, state.State,
return nil
}
}

func removeMaintenanceConfigPatchFinalizers(ctx context.Context, st state.State, _ *zap.Logger) error {
items, err := safe.ReaderListAll[*omni.MachineStatus](
ctx,
st,
)
if err != nil {
return err
}

return items.ForEachErr(func(item *omni.MachineStatus) error {
return st.RemoveFinalizer(ctx, item.Metadata(), "MaintenanceConfigPatchController")
})
}

0 comments on commit 8da2328

Please sign in to comment.