Skip to content

Commit 216e970

Browse files
Merge pull request #8544 from hamzy/PowerVS-Destroy-DHCP-in-ERROR-state
OCPBUGS-35039: PowerVS: Destroy DHCP in ERROR state
2 parents 03780e0 + 4b83607 commit 216e970

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

pkg/destroy/powervs/dhcp.go

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,34 @@ func (o *ClusterUninstaller) listDHCPNetworks() (cloudResources, error) {
4545
continue
4646
}
4747
if dhcpServer.Network.Name == nil {
48+
// https://github.com/IBM-Cloud/power-go-client/blob/master/power/models/p_vm_instance.go#L22
49+
var instance *models.PVMInstance
50+
4851
o.Logger.Debugf("listDHCPNetworks: DHCP has empty Network.Name: %s", *dhcpServer.ID)
52+
53+
instance, err = o.instanceClient.Get(*dhcpServer.ID)
54+
o.Logger.Debugf("listDHCPNetworks: Getting instance %s %v", *dhcpServer.ID, err)
55+
if err != nil {
56+
continue
57+
}
58+
59+
if instance.Status == nil {
60+
continue
61+
}
62+
// If there is a backing DHCP VM and it has a status, then check for an ERROR state
63+
o.Logger.Debugf("listDHCPNetworks: instance.Status: %s", *instance.Status)
64+
if *instance.Status != "ERROR" {
65+
continue
66+
}
67+
68+
foundOne = true
69+
result = append(result, cloudResource{
70+
key: *dhcpServer.ID,
71+
name: *dhcpServer.ID,
72+
status: "VM",
73+
typeName: dhcpTypeName,
74+
id: *dhcpServer.ID,
75+
})
4976
continue
5077
}
5178

@@ -55,7 +82,7 @@ func (o *ClusterUninstaller) listDHCPNetworks() (cloudResources, error) {
5582
result = append(result, cloudResource{
5683
key: *dhcpServer.ID,
5784
name: *dhcpServer.Network.Name,
58-
status: "",
85+
status: "DHCP",
5986
typeName: dhcpTypeName,
6087
id: *dhcpServer.ID,
6188
})
@@ -101,6 +128,30 @@ func (o *ClusterUninstaller) destroyDHCPNetwork(item cloudResource) error {
101128
return nil
102129
}
103130

131+
func (o *ClusterUninstaller) destroyDHCPVM(item cloudResource) error {
132+
var err error
133+
134+
_, err = o.instanceClient.Get(item.id)
135+
if err != nil {
136+
o.deletePendingItems(item.typeName, []cloudResource{item})
137+
o.Logger.Infof("Deleted DHCP VM %q", item.name)
138+
return nil
139+
}
140+
141+
o.Logger.Debugf("Deleting DHCP VM %q", item.name)
142+
143+
err = o.instanceClient.Delete(item.id)
144+
if err != nil {
145+
o.Logger.Infof("Error: DHCP o.instanceClient.Delete: %q", err)
146+
return err
147+
}
148+
149+
o.deletePendingItems(item.typeName, []cloudResource{item})
150+
o.Logger.Infof("Deleted DHCP VM %q", item.name)
151+
152+
return nil
153+
}
154+
104155
// destroyDHCPNetworks searches for DHCP networks that are in a previous list
105156
// the cluster's infra ID.
106157
func (o *ClusterUninstaller) destroyDHCPNetworks() error {
@@ -132,7 +183,17 @@ func (o *ClusterUninstaller) destroyDHCPNetworks() error {
132183
Cap: leftInContext(ctx),
133184
Steps: math.MaxInt32}
134185
err = wait.ExponentialBackoffWithContext(ctx, backoff, func(context.Context) (bool, error) {
135-
err2 := o.destroyDHCPNetwork(item)
186+
var err2 error
187+
188+
switch item.status {
189+
case "DHCP":
190+
err2 = o.destroyDHCPNetwork(item)
191+
case "VM":
192+
err2 = o.destroyDHCPVM(item)
193+
default:
194+
err2 = fmt.Errorf("unknown DHCP item status %s", item.status)
195+
return true, err2
196+
}
136197
if err2 == nil {
137198
return true, err2
138199
}

0 commit comments

Comments
 (0)