Skip to content

Commit

Permalink
Postpone machine cleanup when instance is still being created (#1603)
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Schäfer <mschaefer@anexia-it.com>
Co-authored-by: Mario Schäfer <mschaefer@anexia-it.com>
  • Loading branch information
kubermatic-bot and Mario Schäfer authored Mar 28, 2023
1 parent dfd74ea commit 9487516
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/cloudprovider/provider/anexia/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

type anexiaInstance struct {
isCreating bool
isDeleting bool
info *info.Info
reservedAddresses []string
}
Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 13 additions & 4 deletions pkg/cloudprovider/provider/anexia/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,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 {
Expand Down Expand Up @@ -508,6 +513,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() {
Expand All @@ -525,11 +537,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()
Expand Down

0 comments on commit 9487516

Please sign in to comment.