fix: deallocating should be regarded as shut down

This commit is contained in:
andyzhangx 2020-06-18 13:34:56 +00:00
parent cf36d9b8e9
commit 3970904ea8
2 changed files with 7 additions and 5 deletions

View File

@ -32,9 +32,10 @@ import (
)
const (
vmPowerStatePrefix = "PowerState/"
vmPowerStateStopped = "stopped"
vmPowerStateDeallocated = "deallocated"
vmPowerStatePrefix = "PowerState/"
vmPowerStateStopped = "stopped"
vmPowerStateDeallocated = "deallocated"
vmPowerStateDeallocating = "deallocating"
)
var (
@ -230,7 +231,8 @@ func (az *Cloud) InstanceShutdownByProviderID(ctx context.Context, providerID st
}
klog.V(5).Infof("InstanceShutdownByProviderID gets power status %q for node %q", powerStatus, nodeName)
return strings.ToLower(powerStatus) == vmPowerStateStopped || strings.ToLower(powerStatus) == vmPowerStateDeallocated, nil
status := strings.ToLower(powerStatus)
return status == vmPowerStateStopped || status == vmPowerStateDeallocated || status == vmPowerStateDeallocating, nil
}
// InstanceMetadataByProviderID returns metadata of the specified instance.

View File

@ -284,7 +284,7 @@ func TestInstanceShutdownByProviderID(t *testing.T) {
vmList: map[string]string{"vm3": "PowerState/Deallocating"},
nodeName: "vm3",
providerID: "azure:///subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm3",
expected: false,
expected: true,
},
{
name: "InstanceShutdownByProviderID should return false if the vm is in PowerState/Starting status",