Skip to content

Commit

Permalink
Postpone machine cleanup when instance is still being created
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Schäfer <[email protected]>
  • Loading branch information
Mario Schäfer authored and kubermatic-bot committed Mar 2, 2023
1 parent f387c0e commit f5d8753
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 @@ -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 {
Expand Down Expand Up @@ -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() {
Expand All @@ -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()
Expand Down

0 comments on commit f5d8753

Please sign in to comment.