Skip to content

Commit

Permalink
feat: deleting nics on CloudProvider.Delete()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce-Soghigian committed Dec 29, 2023
1 parent bacdac7 commit a9c9447
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package instance
import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"sort"
Expand Down Expand Up @@ -125,7 +126,7 @@ func (p *Provider) Create(ctx context.Context, nodeClass *v1alpha2.AKSNodeClass,
instanceTypes = orderInstanceTypesByPrice(instanceTypes, scheduling.NewNodeSelectorRequirements(nodeClaim.Spec.Requirements...))
vm, instanceType, err := p.launchInstance(ctx, nodeClass, nodeClaim, instanceTypes)
if err != nil {
p.cleanUpResourcesFromFailedLaunch(ctx, GenerateResourceName(nodeClaim.Name))
p.cleanAzureResources(ctx, GenerateResourceName(nodeClaim.Name))

Check failure on line 129 in pkg/providers/instance/instance.go

View workflow job for this annotation

GitHub Actions / ci

Error return value of `p.cleanAzureResources` is not checked (errcheck)
return nil, err
}
zone, err := GetZoneID(vm)
Expand Down Expand Up @@ -194,9 +195,9 @@ func (p *Provider) List(ctx context.Context) ([]*armcompute.VirtualMachine, erro
return vmList, nil
}

func (p *Provider) Delete(ctx context.Context, vmName string) error {
logging.FromContext(ctx).Debugf("Deleting virtual machine %s", vmName)
return deleteVirtualMachine(ctx, p.azClient.virtualMachinesClient, p.resourceGroup, vmName)
func (p *Provider) Delete(ctx context.Context, resourceName string) error {
logging.FromContext(ctx).Debugf("Deleting virtual machine %s and associated resources", )
return p.cleanAzureResources(ctx, resourceName)
}

// createAKSIdentifyingExtension attaches a VM extension to identify that this VM participates in an AKS cluster
Expand Down Expand Up @@ -570,15 +571,17 @@ func (p *Provider) pickSkuSizePriorityAndZone(ctx context.Context, nodeClaim *co
return nil, "", ""
}

func (p *Provider) cleanUpResourcesFromFailedLaunch(ctx context.Context, resourceName string) {
nicErr := deleteNicIfExists(ctx, p.azClient.networkInterfacesClient, p.resourceGroup, resourceName)
if nicErr != nil {
logging.FromContext(ctx).Errorf("networkInterface.Delete for %s failed: %v", resourceName, nicErr)
}
func (p *Provider) cleanAzureResources(ctx context.Context, resourceName string)(err error){
vmErr := deleteVirtualMachineIfExists(ctx, p.azClient.virtualMachinesClient, p.resourceGroup, resourceName)
if vmErr != nil {
logging.FromContext(ctx).Errorf("virtualMachine.Delete for %s failed: %v", resourceName, vmErr)
}
nicErr := deleteNicIfExists(ctx, p.azClient.networkInterfacesClient, p.resourceGroup, resourceName)
if nicErr != nil {
logging.FromContext(ctx).Errorf("networkInterface.Delete for %s failed: %v", resourceName, nicErr)
}

return errors.Join(vmErr, nicErr)
}

// getPriorityForInstanceType selects spot if both constraints are flexible and there is an available offering.
Expand Down

0 comments on commit a9c9447

Please sign in to comment.