From f5d8753076ff7b886c6ece8d51031435cdabe3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Sch=C3=A4fer?= Date: Wed, 22 Feb 2023 12:01:32 +0100 Subject: [PATCH] Postpone machine cleanup when instance is still being created MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mario Schäfer --- pkg/cloudprovider/provider/anexia/instance.go | 4 ++++ pkg/cloudprovider/provider/anexia/provider.go | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/cloudprovider/provider/anexia/instance.go b/pkg/cloudprovider/provider/anexia/instance.go index cd67d80c5..d84d90f7c 100644 --- a/pkg/cloudprovider/provider/anexia/instance.go +++ b/pkg/cloudprovider/provider/anexia/instance.go @@ -29,6 +29,7 @@ import ( type anexiaInstance struct { isCreating bool + isDeleting bool info *info.Info reservedAddresses []string } @@ -86,6 +87,9 @@ func (ai *anexiaInstance) Addresses() map[string]v1.NodeAddressType { } func (ai *anexiaInstance) Status() instance.Status { + if ai.isDeleting { + return instance.StatusDeleting + } if ai.isCreating { return instance.StatusCreating } diff --git a/pkg/cloudprovider/provider/anexia/provider.go b/pkg/cloudprovider/provider/anexia/provider.go index fa70d13fc..04f9e16b9 100644 --- a/pkg/cloudprovider/provider/anexia/provider.go +++ b/pkg/cloudprovider/provider/anexia/provider.go @@ -465,6 +465,11 @@ func (p *provider) Get(ctx context.Context, machine *clusterv1alpha1.Machine, pd return nil, cloudprovidererrors.ErrInstanceNotFound } + if status.DeprovisioningID != "" { + // info endpoint no longer available for vm -> stop here + return &anexiaInstance{isDeleting: true}, nil + } + if status.InstanceID == "" { progress, err := vsphereAPI.Provisioning().Progress().Get(ctx, status.ProvisioningID) if err != nil { @@ -507,6 +512,13 @@ func (p *provider) GetCloudConfig(_ clusterv1alpha1.MachineSpec) (string, string } func (p *provider) Cleanup(ctx context.Context, machine *clusterv1alpha1.Machine, data *cloudprovidertypes.ProviderData) (isDeleted bool, retErr error) { + if inst, err := p.Get(ctx, machine, data); err != nil { + return false, err + } else if inst.Status() == instance.StatusCreating { + klog.Warningf("Unable to cleanup machine %q. Instance is still creating", machine.Name) + return false, nil + } + status := getProviderStatus(machine) // make sure status is reflected in Machine Object defer func() { @@ -524,11 +536,8 @@ func (p *provider) Cleanup(ctx context.Context, machine *clusterv1alpha1.Machine if err != nil { return false, newError(common.InvalidConfigurationMachineError, "failed to create Anexia client: %v", err) } - vsphereAPI := vsphere.NewAPI(cli) - if err != nil { - return false, newError(common.InvalidConfigurationMachineError, "failed to get machine status: %v", err) - } + vsphereAPI := vsphere.NewAPI(cli) deleteCtx, cancel := context.WithTimeout(ctx, anxtypes.DeleteRequestTimeout) defer cancel()