From afeefafb15c4bc40f290ee6fc66e8a71df5ed9eb Mon Sep 17 00:00:00 2001 From: Qi Ni Date: Wed, 13 Oct 2021 20:40:17 +0800 Subject: [PATCH] fix: skip instance not found when decoupling vmss from lb (cherry picked from commit 0b7ba30b1b734172f5005185d09fb641e105405b) --- pkg/provider/azure_vmss.go | 5 +++++ pkg/provider/azure_vmss_test.go | 23 +++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/provider/azure_vmss.go b/pkg/provider/azure_vmss.go index f275873e5a..49432d0b4f 100644 --- a/pkg/provider/azure_vmss.go +++ b/pkg/provider/azure_vmss.go @@ -1517,6 +1517,11 @@ func (ss *ScaleSet) EnsureBackendPoolDeleted(service *v1.Service, backendPoolID, continue } + if errors.Is(err, cloudprovider.InstanceNotFound) { + klog.Infof("EnsureBackendPoolDeleted(%s): skipping ip config %s because the corresponding vmss vm is not found", getServiceName(service), ipConfigurationID) + continue + } + klog.Errorf("Failed to GetNodeNameByIPConfigurationID(%s): %v", ipConfigurationID, err) allErrs = append(allErrs, err) continue diff --git a/pkg/provider/azure_vmss_test.go b/pkg/provider/azure_vmss_test.go index d7343587c6..f7206c57b4 100644 --- a/pkg/provider/azure_vmss_test.go +++ b/pkg/provider/azure_vmss_test.go @@ -2424,6 +2424,26 @@ func TestEnsureBackendPoolDeleted(t *testing.T) { expectedErr: true, vmClientErr: &retry.Error{RawError: fmt.Errorf("error")}, }, + { + description: "EnsureBackendPoolDeleted should skip the node that doesn't exist", + backendpoolID: testLBBackendpoolID0, + backendAddressPools: &[]network.BackendAddressPool{ + { + ID: to.StringPtr(testLBBackendpoolID0), + BackendAddressPoolPropertiesFormat: &network.BackendAddressPoolPropertiesFormat{ + BackendIPConfigurations: &[]network.InterfaceIPConfiguration{ + { + Name: to.StringPtr("ip-1"), + ID: to.StringPtr("/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/vmss/virtualMachines/6/networkInterfaces/nic"), + }, + }, + }, + }, + { + ID: to.StringPtr(testLBBackendpoolID1), + }, + }, + }, } for _, test := range testCases { @@ -2477,7 +2497,6 @@ func TestEnsureBackendPoolDeletedConcurrently(t *testing.T) { }, }, { - // this would fail ID: to.StringPtr(testLBBackendpoolID2), BackendAddressPoolPropertiesFormat: &network.BackendAddressPoolPropertiesFormat{ BackendIPConfigurations: &[]network.InterfaceIPConfiguration{ @@ -2516,7 +2535,7 @@ func TestEnsureBackendPoolDeletedConcurrently(t *testing.T) { mockVMSSVMClient.EXPECT().UpdateVMs(gomock.Any(), ss.ResourceGroup, gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2) backendpoolAddressIDs := []string{testLBBackendpoolID0, testLBBackendpoolID1, testLBBackendpoolID2} - testVMSSNames := []string{"vmss-0", "vmss-1", "vmss-0"} + testVMSSNames := []string{"vmss-0", "vmss-1", "vmss-2"} testFunc := make([]func() error, 0) for i, id := range backendpoolAddressIDs { i := i