Skip to content

Commit 75912f6

Browse files
committed
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.
1 parent 71277de commit 75912f6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ func (ss *scaleSet) getVmssVM(nodeName string, crt azcache.AzureCacheReadType) (
189189

190190
// GetPowerStatusByNodeName returns the power state of the specified node.
191191
func (ss *scaleSet) GetPowerStatusByNodeName(name string) (powerState string, err error) {
192+
managedByAS, err := ss.isNodeManagedByAvailabilitySet(name, azcache.CacheReadTypeUnsafe)
193+
if err != nil {
194+
klog.Errorf("Failed to check isNodeManagedByAvailabilitySet: %v", err)
195+
return "", err
196+
}
197+
if managedByAS {
198+
// vm is managed by availability set.
199+
return ss.availabilitySet.GetPowerStatusByNodeName(name)
200+
}
201+
192202
_, _, vm, err := ss.getVmssVM(name, azcache.CacheReadTypeDefault)
193203
if err != nil {
194204
return powerState, err

staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@ func TestGetPowerStatusByNodeName(t *testing.T) {
688688
}
689689
mockVMSSVMClient.EXPECT().List(gomock.Any(), ss.ResourceGroup, testVMSSName, gomock.Any()).Return(expectedVMSSVMs, nil).AnyTimes()
690690

691+
mockVMsClient := ss.cloud.VirtualMachinesClient.(*mockvmclient.MockInterface)
692+
mockVMsClient.EXPECT().List(gomock.Any(), gomock.Any()).Return([]compute.VirtualMachine{}, nil).AnyTimes()
693+
691694
powerState, err := ss.GetPowerStatusByNodeName("vmss-vm-000001")
692695
assert.Equal(t, test.expectedErr, err, test.description+", but an error occurs")
693696
assert.Equal(t, test.expectedPowerState, powerState, test.description)

0 commit comments

Comments
 (0)