mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Fix: ignore not a VMSS error for VMAS nodes in reconcileBackendPools
This commit is contained in:
parent
fffaadc013
commit
c406f2edab
@ -1377,8 +1377,17 @@ func (ss *scaleSet) ensureBackendPoolDeletedFromNode(nodeName, backendPoolID str
|
|||||||
func (ss *scaleSet) GetNodeNameByIPConfigurationID(ipConfigurationID string) (string, string, error) {
|
func (ss *scaleSet) GetNodeNameByIPConfigurationID(ipConfigurationID string) (string, string, error) {
|
||||||
matches := vmssIPConfigurationRE.FindStringSubmatch(ipConfigurationID)
|
matches := vmssIPConfigurationRE.FindStringSubmatch(ipConfigurationID)
|
||||||
if len(matches) != 4 {
|
if len(matches) != 4 {
|
||||||
|
if ss.DisableAvailabilitySetNodes {
|
||||||
|
return "", "", ErrorNotVmssInstance
|
||||||
|
}
|
||||||
|
|
||||||
klog.V(4).Infof("Can not extract scale set name from ipConfigurationID (%s), assuming it is managed by availability set", ipConfigurationID)
|
klog.V(4).Infof("Can not extract scale set name from ipConfigurationID (%s), assuming it is managed by availability set", ipConfigurationID)
|
||||||
return "", "", ErrorNotVmssInstance
|
name, rg, err := ss.availabilitySet.GetNodeNameByIPConfigurationID(ipConfigurationID)
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("GetNodeNameByIPConfigurationID: failed to invoke availabilitySet.GetNodeNameByIPConfigurationID: %s", err.Error())
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
return name, rg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceGroup := matches[1]
|
resourceGroup := matches[1]
|
||||||
|
@ -577,9 +577,10 @@ func TestGetNodeNameByIPConfigurationID(t *testing.T) {
|
|||||||
scaleSet string
|
scaleSet string
|
||||||
vmList []string
|
vmList []string
|
||||||
ipConfigurationID string
|
ipConfigurationID string
|
||||||
|
disableVMAS bool
|
||||||
expectedNodeName string
|
expectedNodeName string
|
||||||
expectedScaleSetName string
|
expectedScaleSetName string
|
||||||
expectError bool
|
expectError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
description: "GetNodeNameByIPConfigurationID should get node's Name when the node is existing",
|
description: "GetNodeNameByIPConfigurationID should get node's Name when the node is existing",
|
||||||
@ -594,41 +595,50 @@ func TestGetNodeNameByIPConfigurationID(t *testing.T) {
|
|||||||
scaleSet: "scaleset2",
|
scaleSet: "scaleset2",
|
||||||
ipConfigurationID: fmt.Sprintf(ipConfigurationIDTemplate, "scaleset2", "3", "scaleset1"),
|
ipConfigurationID: fmt.Sprintf(ipConfigurationIDTemplate, "scaleset2", "3", "scaleset1"),
|
||||||
vmList: []string{"vmssee6c2000002", "vmssee6c2000003"},
|
vmList: []string{"vmssee6c2000002", "vmssee6c2000003"},
|
||||||
expectError: true,
|
expectError: fmt.Errorf("instance not found"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "GetNodeNameByIPConfigurationID should return error for wrong ipConfigurationID",
|
description: "GetNodeNameByIPConfigurationID should return error for wrong ipConfigurationID",
|
||||||
scaleSet: "scaleset3",
|
scaleSet: "scaleset3",
|
||||||
ipConfigurationID: "invalid-configuration-id",
|
ipConfigurationID: "invalid-configuration-id",
|
||||||
vmList: []string{"vmssee6c2000004", "vmssee6c2000005"},
|
vmList: []string{"vmssee6c2000004", "vmssee6c2000005"},
|
||||||
expectError: true,
|
expectError: fmt.Errorf("invalid ip config ID invalid-configuration-id"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "GetNodeNameByIPConfigurationID should return ErrorNotVmssInstance if the vmas is disabled",
|
||||||
|
scaleSet: "scaleset1",
|
||||||
|
ipConfigurationID: "invalid-configuration-id",
|
||||||
|
vmList: []string{"vmssee6c2000004", "vmssee6c2000005"},
|
||||||
|
disableVMAS: true,
|
||||||
|
expectError: ErrorNotVmssInstance,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
ss, err := newTestScaleSet(ctrl)
|
t.Run(test.description, func(t *testing.T) {
|
||||||
assert.NoError(t, err, test.description)
|
ss, err := newTestScaleSet(ctrl)
|
||||||
|
assert.NoError(t, err, test.description)
|
||||||
|
|
||||||
mockVMSSClient := mockvmssclient.NewMockInterface(ctrl)
|
if test.disableVMAS {
|
||||||
mockVMSSVMClient := mockvmssvmclient.NewMockInterface(ctrl)
|
ss.DisableAvailabilitySetNodes = true
|
||||||
ss.cloud.VirtualMachineScaleSetsClient = mockVMSSClient
|
}
|
||||||
ss.cloud.VirtualMachineScaleSetVMsClient = mockVMSSVMClient
|
|
||||||
|
|
||||||
expectedScaleSet := buildTestVMSS(test.scaleSet, "vmssee6c2")
|
mockVMSSClient := mockvmssclient.NewMockInterface(ctrl)
|
||||||
mockVMSSClient.EXPECT().List(gomock.Any(), gomock.Any()).Return([]compute.VirtualMachineScaleSet{expectedScaleSet}, nil).AnyTimes()
|
mockVMSSVMClient := mockvmssvmclient.NewMockInterface(ctrl)
|
||||||
|
ss.cloud.VirtualMachineScaleSetsClient = mockVMSSClient
|
||||||
|
ss.cloud.VirtualMachineScaleSetVMsClient = mockVMSSVMClient
|
||||||
|
|
||||||
expectedVMs, _, _ := buildTestVirtualMachineEnv(ss.cloud, test.scaleSet, "", 0, test.vmList, "", false)
|
expectedScaleSet := buildTestVMSS(test.scaleSet, "vmssee6c2")
|
||||||
mockVMSSVMClient.EXPECT().List(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(expectedVMs, nil).AnyTimes()
|
mockVMSSClient.EXPECT().List(gomock.Any(), gomock.Any()).Return([]compute.VirtualMachineScaleSet{expectedScaleSet}, nil).AnyTimes()
|
||||||
|
|
||||||
nodeName, scalesetName, err := ss.GetNodeNameByIPConfigurationID(test.ipConfigurationID)
|
expectedVMs, _, _ := buildTestVirtualMachineEnv(ss.cloud, test.scaleSet, "", 0, test.vmList, "", false)
|
||||||
if test.expectError {
|
mockVMSSVMClient.EXPECT().List(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(expectedVMs, nil).AnyTimes()
|
||||||
assert.Error(t, err, test.description)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.NoError(t, err, test.description)
|
nodeName, scalesetName, err := ss.GetNodeNameByIPConfigurationID(test.ipConfigurationID)
|
||||||
assert.Equal(t, test.expectedNodeName, nodeName, test.description)
|
assert.Equal(t, err, test.expectError)
|
||||||
assert.Equal(t, test.expectedScaleSetName, scalesetName, test.description)
|
assert.Equal(t, test.expectedNodeName, nodeName, test.description)
|
||||||
|
assert.Equal(t, test.expectedScaleSetName, scalesetName, test.description)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2377,6 +2387,7 @@ func TestEnsureBackendPoolDeleted(t *testing.T) {
|
|||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
ss, err := newTestScaleSet(ctrl)
|
ss, err := newTestScaleSet(ctrl)
|
||||||
assert.NoError(t, err, test.description)
|
assert.NoError(t, err, test.description)
|
||||||
|
ss.DisableAvailabilitySetNodes = true
|
||||||
|
|
||||||
expectedVMSS := buildTestVMSSWithLB(testVMSSName, "vmss-vm-", []string{testLBBackendpoolID0}, false)
|
expectedVMSS := buildTestVMSSWithLB(testVMSSName, "vmss-vm-", []string{testLBBackendpoolID0}, false)
|
||||||
mockVMSSClient := ss.cloud.VirtualMachineScaleSetsClient.(*mockvmssclient.MockInterface)
|
mockVMSSClient := ss.cloud.VirtualMachineScaleSetsClient.(*mockvmssclient.MockInterface)
|
||||||
|
Loading…
Reference in New Issue
Block a user