Skip to content

Commit

Permalink
Fix getVMManagementTypeByIPConfigurationID()
Browse files Browse the repository at this point in the history
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 <zhechengli@microsoft.com>
  • Loading branch information
lzhecheng authored and MartinForReal committed Apr 22, 2024
1 parent dc90e30 commit cd68bff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
10 changes: 10 additions & 0 deletions pkg/provider/azure_vmss_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/provider/azure_vmssflex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions pkg/provider/azure_vmssflex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit cd68bff

Please sign in to comment.