Azure: support non-VMSS instances removal

When called by Controller Manager lifecycle controller for a node missing
heartbeats (via `InstanceShutdownByProviderID()`), Azure cloud provider
ensures the instance backing that node is shut down or otherwise removed from
its containing VMSS before allowing the node to be reaped from the cluster.

But it won't test the same for VMAS or standalone instances (not part of a
VMSS), which are otherwise well supported: they can register, for instance.
So deleted non-VMSS instances will leave `NotReady` nodes behind, and,
depending on their name, might cause regular VMSS List / full re-scans.
This commit is contained in:
Benjamin Pineau 2020-05-15 20:17:57 +02:00
parent 71277de4d6
commit 75912f63ed
2 changed files with 13 additions and 0 deletions

View File

@ -189,6 +189,16 @@ func (ss *scaleSet) getVmssVM(nodeName string, crt azcache.AzureCacheReadType) (
// GetPowerStatusByNodeName returns the power state of the specified node.
func (ss *scaleSet) GetPowerStatusByNodeName(name string) (powerState string, err error) {
managedByAS, err := ss.isNodeManagedByAvailabilitySet(name, azcache.CacheReadTypeUnsafe)
if err != nil {
klog.Errorf("Failed to check isNodeManagedByAvailabilitySet: %v", err)
return "", err
}
if managedByAS {
// vm is managed by availability set.
return ss.availabilitySet.GetPowerStatusByNodeName(name)
}
_, _, vm, err := ss.getVmssVM(name, azcache.CacheReadTypeDefault)
if err != nil {
return powerState, err

View File

@ -688,6 +688,9 @@ func TestGetPowerStatusByNodeName(t *testing.T) {
}
mockVMSSVMClient.EXPECT().List(gomock.Any(), ss.ResourceGroup, testVMSSName, gomock.Any()).Return(expectedVMSSVMs, nil).AnyTimes()
mockVMsClient := ss.cloud.VirtualMachinesClient.(*mockvmclient.MockInterface)
mockVMsClient.EXPECT().List(gomock.Any(), gomock.Any()).Return([]compute.VirtualMachine{}, nil).AnyTimes()
powerState, err := ss.GetPowerStatusByNodeName("vmss-vm-000001")
assert.Equal(t, test.expectedErr, err, test.description+", but an error occurs")
assert.Equal(t, test.expectedPowerState, powerState, test.description)