From b0cdc77f387c3616ff6b7bf0c92d5def17ddb926 Mon Sep 17 00:00:00 2001 From: Qi Ni Date: Thu, 14 Oct 2021 10:11:23 +0800 Subject: [PATCH] fix: skip instance not found when decoupling vmss from lb --- .../azure/azure_vmss.go | 9 ++++++-- .../azure/azure_vmss_test.go | 23 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go index 89ef88dc846..5ce18a0e8dd 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go @@ -1492,11 +1492,11 @@ func (ss *scaleSet) ensureBackendPoolDeletedFromVMSS(service *v1.Service, backen // When vmss is being deleted, CreateOrUpdate API would report "the vmss is being deleted" error. // Since it is being deleted, we shouldn't send more CreateOrUpdate requests for it. if vmss.ProvisioningState != nil && strings.EqualFold(*vmss.ProvisioningState, virtualMachineScaleSetsDeallocating) { - klog.V(3).Infof("ensureVMSSInPool: found vmss %s being deleted, skipping", vmssName) + klog.V(3).Infof("ensureBackendPoolDeletedFromVMSS: found vmss %s being deleted, skipping", vmssName) continue } if vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations == nil { - klog.V(4).Infof("EnsureHostInPool: cannot obtain the primary network interface configuration, of vmss %s", vmssName) + klog.V(4).Infof("ensureBackendPoolDeletedFromVMSS: cannot obtain the primary network interface configuration, of vmss %s", vmssName) continue } vmssNIC := *vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations @@ -1615,6 +1615,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/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go index a756cc52eea..97239bcbf4f 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go @@ -2433,6 +2433,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 { @@ -2487,7 +2507,6 @@ func TestEnsureBackendPoolDeletedConcurrently(t *testing.T) { }, }, { - // this would fail ID: to.StringPtr(testLBBackendpoolID2), BackendAddressPoolPropertiesFormat: &network.BackendAddressPoolPropertiesFormat{ BackendIPConfigurations: &[]network.InterfaceIPConfiguration{ @@ -2526,7 +2545,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