Skip to content

Commit

Permalink
fix: Resolve errors for resource not found (#633)
Browse files Browse the repository at this point in the history
Co-authored-by: yl5722 <[email protected]>
Co-authored-by: Alex Leites <[email protected]>
  • Loading branch information
3 people committed Jan 23, 2025
1 parent ff53ecc commit 5a4e5d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/providers/instance/armutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func deleteNicIfExists(ctx context.Context, client NetworkInterfacesAPI, rg, nic
func deleteVirtualMachineIfExists(ctx context.Context, client VirtualMachinesAPI, rg, vmName string) error {
_, err := client.Get(ctx, rg, vmName, nil)
if err != nil {
if sdkerrors.IsNotFoundErr(err) {
azErr := sdkerrors.IsResponseError(err)
if azErr != nil && (azErr.ErrorCode == "NotFound" || azErr.ErrorCode == "ResourceNotFound") {
return nil
}
return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func (p *Provider) Get(ctx context.Context, vmName string) (*armcompute.VirtualM
var err error

if vm, err = p.AZClient.virtualMachinesClient.Get(ctx, p.resourceGroup, vmName, nil); err != nil {
if sdkerrors.IsNotFoundErr(err) {
azErr := sdkerrors.IsResponseError(err)
if azErr != nil && (azErr.ErrorCode == "NotFound" || azErr.ErrorCode == "ResourceNotFound") {
return nil, corecloudprovider.NewNodeClaimNotFoundError(err)
}
return nil, fmt.Errorf("failed to get VM instance, %w", err)
Expand Down

0 comments on commit 5a4e5d6

Please sign in to comment.