Skip to content

Commit

Permalink
Merge pull request kubernetes#104029 from nilo19/automated-cherry-pic…
Browse files Browse the repository at this point in the history
…k-of-#103997-upstream-release-1.21

Automated cherry pick of kubernetes#103997: Fix: ignore not a VMSS error for VMAS nodes in
  • Loading branch information
k8s-ci-robot authored Aug 2, 2021
2 parents 1a8c1a4 + 0ac9e77 commit 8f9e096
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
11 changes: 10 additions & 1 deletion staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -1377,8 +1377,17 @@ func (ss *scaleSet) ensureBackendPoolDeletedFromNode(nodeName, backendPoolID str
func (ss *scaleSet) GetNodeNameByIPConfigurationID(ipConfigurationID string) (string, string, error) {
matches := vmssIPConfigurationRE.FindStringSubmatch(ipConfigurationID)
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)
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]
Expand Down
53 changes: 32 additions & 21 deletions staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,10 @@ func TestGetNodeNameByIPConfigurationID(t *testing.T) {
scaleSet string
vmList []string
ipConfigurationID string
disableVMAS bool
expectedNodeName string
expectedScaleSetName string
expectError bool
expectError error
}{
{
description: "GetNodeNameByIPConfigurationID should get node's Name when the node is existing",
Expand All @@ -594,41 +595,50 @@ func TestGetNodeNameByIPConfigurationID(t *testing.T) {
scaleSet: "scaleset2",
ipConfigurationID: fmt.Sprintf(ipConfigurationIDTemplate, "scaleset2", "3", "scaleset1"),
vmList: []string{"vmssee6c2000002", "vmssee6c2000003"},
expectError: true,
expectError: fmt.Errorf("instance not found"),
},
{
description: "GetNodeNameByIPConfigurationID should return error for wrong ipConfigurationID",
scaleSet: "scaleset3",
ipConfigurationID: "invalid-configuration-id",
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 {
ss, err := newTestScaleSet(ctrl)
assert.NoError(t, err, test.description)
t.Run(test.description, func(t *testing.T) {
ss, err := newTestScaleSet(ctrl)
assert.NoError(t, err, test.description)

mockVMSSClient := mockvmssclient.NewMockInterface(ctrl)
mockVMSSVMClient := mockvmssvmclient.NewMockInterface(ctrl)
ss.cloud.VirtualMachineScaleSetsClient = mockVMSSClient
ss.cloud.VirtualMachineScaleSetVMsClient = mockVMSSVMClient
if test.disableVMAS {
ss.DisableAvailabilitySetNodes = true
}

expectedScaleSet := buildTestVMSS(test.scaleSet, "vmssee6c2")
mockVMSSClient.EXPECT().List(gomock.Any(), gomock.Any()).Return([]compute.VirtualMachineScaleSet{expectedScaleSet}, nil).AnyTimes()
mockVMSSClient := mockvmssclient.NewMockInterface(ctrl)
mockVMSSVMClient := mockvmssvmclient.NewMockInterface(ctrl)
ss.cloud.VirtualMachineScaleSetsClient = mockVMSSClient
ss.cloud.VirtualMachineScaleSetVMsClient = mockVMSSVMClient

expectedVMs, _, _ := buildTestVirtualMachineEnv(ss.cloud, test.scaleSet, "", 0, test.vmList, "", false)
mockVMSSVMClient.EXPECT().List(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(expectedVMs, nil).AnyTimes()
expectedScaleSet := buildTestVMSS(test.scaleSet, "vmssee6c2")
mockVMSSClient.EXPECT().List(gomock.Any(), gomock.Any()).Return([]compute.VirtualMachineScaleSet{expectedScaleSet}, nil).AnyTimes()

nodeName, scalesetName, err := ss.GetNodeNameByIPConfigurationID(test.ipConfigurationID)
if test.expectError {
assert.Error(t, err, test.description)
continue
}
expectedVMs, _, _ := buildTestVirtualMachineEnv(ss.cloud, test.scaleSet, "", 0, test.vmList, "", false)
mockVMSSVMClient.EXPECT().List(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(expectedVMs, nil).AnyTimes()

assert.NoError(t, err, test.description)
assert.Equal(t, test.expectedNodeName, nodeName, test.description)
assert.Equal(t, test.expectedScaleSetName, scalesetName, test.description)
nodeName, scalesetName, err := ss.GetNodeNameByIPConfigurationID(test.ipConfigurationID)
assert.Equal(t, err, test.expectError)
assert.Equal(t, test.expectedNodeName, nodeName, test.description)
assert.Equal(t, test.expectedScaleSetName, scalesetName, test.description)
})
}
}

Expand Down Expand Up @@ -2377,6 +2387,7 @@ func TestEnsureBackendPoolDeleted(t *testing.T) {
for _, test := range testCases {
ss, err := newTestScaleSet(ctrl)
assert.NoError(t, err, test.description)
ss.DisableAvailabilitySetNodes = true

expectedVMSS := buildTestVMSSWithLB(testVMSSName, "vmss-vm-", []string{testLBBackendpoolID0}, false)
mockVMSSClient := ss.cloud.VirtualMachineScaleSetsClient.(*mockvmssclient.MockInterface)
Expand Down

0 comments on commit 8f9e096

Please sign in to comment.