From 568eca2ee47229c4a4c457df1c48ece5a81e6695 Mon Sep 17 00:00:00 2001 From: Zhecheng Li Date: Thu, 18 Apr 2024 06:10:48 +0000 Subject: [PATCH] Fix getVMManagementTypeByIPConfigurationID() If VM not existing in cache, force cache refresh again. If the node is not in the cache, assume the node has joined after the last cache refresh and attempt to refresh the cache. Signed-off-by: Zhecheng Li --- pkg/provider/azure_vmss_cache.go | 10 ++++++++++ pkg/provider/azure_vmssflex.go | 4 ++-- pkg/provider/azure_vmssflex_test.go | 3 +-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/provider/azure_vmss_cache.go b/pkg/provider/azure_vmss_cache.go index e85068b9db..f25b7f1128 100644 --- a/pkg/provider/azure_vmss_cache.go +++ b/pkg/provider/azure_vmss_cache.go @@ -498,7 +498,17 @@ func (ss *ScaleSet) getVMManagementTypeByIPConfigurationID(ipConfigurationID str vmName := strings.Replace(nicName, "-nic", "", 1) cachedAvSetVMs := cached.(NonVmssUniformNodesEntry).AvSetVMNodeNames + if cachedAvSetVMs.Has(vmName) { + return ManagedByAvSet, nil + } + + // If the node is not in the cache, assume the node has joined after the last cache refresh and attempt to refresh the cache + cached, err = ss.nonVmssUniformNodesCache.Get(consts.NonVmssUniformNodesKey, azcache.CacheReadTypeForceRefresh) + if err != nil { + return ManagedByUnknownVMSet, err + } + cachedAvSetVMs = cached.(NonVmssUniformNodesEntry).AvSetVMNodeNames if cachedAvSetVMs.Has(vmName) { return ManagedByAvSet, nil } diff --git a/pkg/provider/azure_vmssflex.go b/pkg/provider/azure_vmssflex.go index ec8d0cf4f5..8e11a46108 100644 --- a/pkg/provider/azure_vmssflex.go +++ b/pkg/provider/azure_vmssflex.go @@ -388,12 +388,12 @@ func (fs *FlexScaleSet) getNodeInformationByIPConfigurationID(ipConfigurationID // get vmName by nic name vmName, err := fs.GetVMNameByIPConfigurationName(nicResourceGroup, nicName) if err != nil { - return "", "", "", fmt.Errorf("failed to get vm name of ip config ID %s", ipConfigurationID) + return "", "", "", fmt.Errorf("failed to get vm name of ip config ID %s: %w", ipConfigurationID, err) } nodeName, err := fs.getNodeNameByVMName(vmName) if err != nil { - return "", "", "", fmt.Errorf("failed to map VM Name to NodeName: VM Name %s", vmName) + return "", "", "", fmt.Errorf("failed to map VM Name to NodeName: VM Name %s: %w", vmName, err) } vmssFlexName, err := fs.getNodeVmssFlexName(nodeName) diff --git a/pkg/provider/azure_vmssflex_test.go b/pkg/provider/azure_vmssflex_test.go index 0b7cd97b5b..c5ee7c290b 100644 --- a/pkg/provider/azure_vmssflex_test.go +++ b/pkg/provider/azure_vmssflex_test.go @@ -799,7 +799,7 @@ func TestGetNodeNameByIPConfigurationIDVmssFlex(t *testing.T) { nic: generateTestNic("testvm1-nic", false, network.ProvisioningStateSucceeded, fmt.Sprintf("/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/%s", nonExistingNodeName)), expectedNodeName: "", expectedVMSetName: "", - expectedErr: fmt.Errorf("failed to map VM Name to NodeName: VM Name NonExistingNodeName"), + expectedErr: fmt.Errorf("failed to map VM Name to NodeName: VM Name NonExistingNodeName: %w", cloudprovider.InstanceNotFound), }, { description: "GetNodeNameByIPConfigurationID should return error if the ipConfigurationID is in wrong format", @@ -832,7 +832,6 @@ func TestGetNodeNameByIPConfigurationIDVmssFlex(t *testing.T) { assert.Equal(t, tc.expectedVMSetName, vmSetName) assert.Equal(t, tc.expectedErr, err) } - } func TestGetNodeCIDRMasksByProviderIDVmssFlex(t *testing.T) {