Skip to content

Commit 574f53e

Browse files
authored
PLT-1575:Fixed VMO Delete crash issue. (#564)
1 parent 82e3056 commit 574f53e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

spectrocloud/cluster_common_virtual_machine.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ package spectrocloud
33
import (
44
"context"
55
"fmt"
6+
"github.com/spectrocloud/palette-sdk-go/api/apiutil/transport"
7+
"github.com/spectrocloud/palette-sdk-go/api/models"
68
"strings"
79
"time"
810

9-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
10-
"github.com/spectrocloud/hapi/apiutil/transport"
11-
"github.com/spectrocloud/palette-sdk-go/api/models"
12-
1311
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1413
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1514
"github.com/spectrocloud/palette-sdk-go/client"
1615
)
@@ -68,17 +67,22 @@ func resourceVirtualMachineStateRefreshFunc(c *client.V1Client, clusterUid, vmNa
6867
return func() (interface{}, string, error) {
6968
vm, err := c.GetVirtualMachine(clusterUid, vmNamespace, vmName)
7069
if err != nil {
71-
if err.(*transport.TransportError).HttpCode == 500 && strings.Contains(err.(*transport.TransportError).Payload.Message, fmt.Sprintf("Failed to get virtual machine '%s'", vmName)) {
72-
emptyVM := &models.V1ClusterVirtualMachine{}
73-
return emptyVM, "Deleted", nil
74-
} else {
75-
return nil, "", err
70+
if transportErr, ok := err.(*transport.TransportError); ok {
71+
if transportErr.HttpCode == 500 && strings.Contains(transportErr.Payload.Message, fmt.Sprintf("Failed to get virtual machine '%s'", vmName)) {
72+
emptyVM := &models.V1ClusterVirtualMachine{}
73+
return emptyVM, "Deleted", nil
74+
} else {
75+
return nil, "", err
76+
}
7677
}
78+
return nil, "", err
7779
}
80+
7881
if vm == nil {
7982
emptyVM := &models.V1ClusterVirtualMachine{}
8083
return emptyVM, "", nil
8184
}
85+
8286
return vm, vm.Status.PrintableStatus, nil
8387
}
8488
}

0 commit comments

Comments
 (0)