From 3ef1f85f58edf346204e076e25b057ce14eeffed Mon Sep 17 00:00:00 2001 From: Artem Chernyshev Date: Mon, 16 Sep 2024 23:57:20 +0300 Subject: [PATCH] fix: call deprovision only after the machine request status is deleted Otherwise the infra provider stops the machine before Omni can run the reset and everything gets stuck when the machine is allocated into a cluster. Also fix labels not being reset on the machine status. Signed-off-by: Artem Chernyshev --- client/pkg/infra/controllers/provision.go | 12 +++++++----- .../runtime/omni/controllers/omni/machine_status.go | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/pkg/infra/controllers/provision.go b/client/pkg/infra/controllers/provision.go index fac4fd36..2cd5d8a9 100644 --- a/client/pkg/infra/controllers/provision.go +++ b/client/pkg/infra/controllers/provision.go @@ -277,17 +277,15 @@ func (ctrl *ProvisionController[T]) reconcileTearingDown(ctx context.Context, r return err } - if err = ctrl.provisioner.Deprovision(ctx, logger, t, machineRequest); err != nil { - return err - } - resources := []resource.Metadata{ resource.NewMetadata(t.ResourceDefinition().DefaultNamespace, t.ResourceDefinition().Type, machineRequest.Metadata().ID(), resource.VersionUndefined), *infra.NewMachineRequestStatus(machineRequest.Metadata().ID()).Metadata(), } for _, md := range resources { - ready, err := r.Teardown(ctx, md) + var ready bool + + ready, err = r.Teardown(ctx, md) if err != nil { if state.IsNotFoundError(err) { continue @@ -310,6 +308,10 @@ func (ctrl *ProvisionController[T]) reconcileTearingDown(ctx context.Context, r } } + if err = ctrl.provisioner.Deprovision(ctx, logger, t, machineRequest); err != nil { + return err + } + logger.Info("machine deprovisioned", zap.String("request_id", machineRequest.Metadata().ID())) return r.RemoveFinalizer(ctx, machineRequest.Metadata(), ctrl.Name()) diff --git a/internal/backend/runtime/omni/controllers/omni/machine_status.go b/internal/backend/runtime/omni/controllers/omni/machine_status.go index 9ed75617..e9a40d5d 100644 --- a/internal/backend/runtime/omni/controllers/omni/machine_status.go +++ b/internal/backend/runtime/omni/controllers/omni/machine_status.go @@ -536,6 +536,8 @@ func (ctrl *MachineStatusController) setClusterRelation(in inputs, machineStatus machineStatus.Metadata().Labels().Set(omni.MachineStatusLabelAvailable, "") machineStatus.Metadata().Labels().Delete(omni.LabelCluster) + machineStatus.Metadata().Labels().Delete(omni.LabelControlPlaneRole) + machineStatus.Metadata().Labels().Delete(omni.LabelWorkerRole) return nil }