Skip to content

Commit 1d40721

Browse files
authored
Merge pull request kubernetes#88699 from feiskyer/vmss-update-improvement
Improve performance for VMSS LoadBalancerBackendAddressPools updates
2 parents debb1ed + 7f27003 commit 1d40721

File tree

15 files changed

+392
-202
lines changed

15 files changed

+392
-202
lines changed

staging/src/k8s.io/legacy-cloud-providers/azure/azure_fakes.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@ func (fVMC *fakeVirtualMachineScaleSetVMsClient) Update(ctx context.Context, res
530530
return nil
531531
}
532532

533+
func (fVMC *fakeVirtualMachineScaleSetVMsClient) UpdateVMs(ctx context.Context, resourceGroupName string, VMScaleSetName string, instances map[string]compute.VirtualMachineScaleSetVM, source string) *retry.Error {
534+
return nil
535+
}
536+
533537
type fakeVirtualMachineScaleSetsClient struct {
534538
mutex *sync.Mutex
535539
FakeStore map[string]map[string]compute.VirtualMachineScaleSet

staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -722,36 +722,36 @@ func (as *availabilitySet) getPrimaryInterfaceWithVMSet(nodeName, vmSetName stri
722722

723723
// EnsureHostInPool ensures the given VM's Primary NIC's Primary IP Configuration is
724724
// participating in the specified LoadBalancer Backend Pool.
725-
func (as *availabilitySet) EnsureHostInPool(service *v1.Service, nodeName types.NodeName, backendPoolID string, vmSetName string, isInternal bool) error {
725+
func (as *availabilitySet) EnsureHostInPool(service *v1.Service, nodeName types.NodeName, backendPoolID string, vmSetName string, isInternal bool) (string, string, string, *compute.VirtualMachineScaleSetVM, error) {
726726
vmName := mapNodeNameToVMName(nodeName)
727727
serviceName := getServiceName(service)
728728
nic, err := as.getPrimaryInterfaceWithVMSet(vmName, vmSetName)
729729
if err != nil {
730730
if err == errNotInVMSet {
731731
klog.V(3).Infof("EnsureHostInPool skips node %s because it is not in the vmSet %s", nodeName, vmSetName)
732-
return nil
732+
return "", "", "", nil, nil
733733
}
734734

735735
klog.Errorf("error: az.EnsureHostInPool(%s), az.vmSet.GetPrimaryInterface.Get(%s, %s), err=%v", nodeName, vmName, vmSetName, err)
736-
return err
736+
return "", "", "", nil, err
737737
}
738738

739739
if nic.ProvisioningState != nil && *nic.ProvisioningState == nicFailedState {
740740
klog.Warningf("EnsureHostInPool skips node %s because its primary nic %s is in Failed state", nodeName, *nic.Name)
741-
return nil
741+
return "", "", "", nil, nil
742742
}
743743

744744
var primaryIPConfig *network.InterfaceIPConfiguration
745745
ipv6 := utilnet.IsIPv6String(service.Spec.ClusterIP)
746746
if !as.Cloud.ipv6DualStackEnabled && !ipv6 {
747747
primaryIPConfig, err = getPrimaryIPConfig(nic)
748748
if err != nil {
749-
return err
749+
return "", "", "", nil, err
750750
}
751751
} else {
752752
primaryIPConfig, err = getIPConfigByIPFamily(nic, ipv6)
753753
if err != nil {
754-
return err
754+
return "", "", "", nil, err
755755
}
756756
}
757757

@@ -780,11 +780,11 @@ func (as *availabilitySet) EnsureHostInPool(service *v1.Service, nodeName types.
780780
}
781781
isSameLB, oldLBName, err := isBackendPoolOnSameLB(backendPoolID, newBackendPoolsIDs)
782782
if err != nil {
783-
return err
783+
return "", "", "", nil, err
784784
}
785785
if !isSameLB {
786786
klog.V(4).Infof("Node %q has already been added to LB %q, omit adding it to a new one", nodeName, oldLBName)
787-
return nil
787+
return "", "", "", nil, nil
788788
}
789789
}
790790

@@ -799,10 +799,10 @@ func (as *availabilitySet) EnsureHostInPool(service *v1.Service, nodeName types.
799799
klog.V(3).Infof("nicupdate(%s): nic(%s) - updating", serviceName, nicName)
800800
err := as.CreateOrUpdateInterface(service, nic)
801801
if err != nil {
802-
return err
802+
return "", "", "", nil, err
803803
}
804804
}
805-
return nil
805+
return "", "", "", nil, nil
806806
}
807807

808808
// EnsureHostsInPool ensures the given Node's primary IP configurations are
@@ -822,7 +822,7 @@ func (as *availabilitySet) EnsureHostsInPool(service *v1.Service, nodes []*v1.No
822822
}
823823

824824
f := func() error {
825-
err := as.EnsureHostInPool(service, types.NodeName(localNodeName), backendPoolID, vmSetName, isInternal)
825+
_, _, _, _, err := as.EnsureHostInPool(service, types.NodeName(localNodeName), backendPoolID, vmSetName, isInternal)
826826
if err != nil {
827827
return fmt.Errorf("ensure(%s): backendPoolID(%s) - failed to ensure host in pool: %q", getServiceName(service), backendPoolID, err)
828828
}

staging/src/k8s.io/legacy-cloud-providers/azure/azure_utils.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ package azure
2121
import (
2222
"context"
2323
"sync"
24-
"time"
25-
26-
utilerrors "k8s.io/apimachinery/pkg/util/errors"
2724
)
2825

2926
// lockMap used to lock on entries
@@ -77,21 +74,3 @@ func (lm *lockMap) unlockEntry(entry string) {
7774
func getContextWithCancel() (context.Context, context.CancelFunc) {
7875
return context.WithCancel(context.Background())
7976
}
80-
81-
// aggregateGoroutinesWithDelay aggregates goroutines and runs them
82-
// in parallel with delay before starting each goroutine
83-
func aggregateGoroutinesWithDelay(delay time.Duration, funcs ...func() error) utilerrors.Aggregate {
84-
errChan := make(chan error, len(funcs))
85-
86-
for _, f := range funcs {
87-
go func(f func() error) { errChan <- f() }(f)
88-
time.Sleep(delay)
89-
}
90-
errs := make([]error, 0)
91-
for i := 0; i < cap(errChan); i++ {
92-
if err := <-errChan; err != nil {
93-
errs = append(errs, err)
94-
}
95-
}
96-
return utilerrors.NewAggregate(errs)
97-
}

staging/src/k8s.io/legacy-cloud-providers/azure/azure_utils_test.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ limitations under the License.
1919
package azure
2020

2121
import (
22-
"fmt"
2322
"testing"
2423
"time"
2524
)
@@ -84,67 +83,3 @@ func ensureNoCallback(t *testing.T, callbackChan <-chan interface{}) bool {
8483
return true
8584
}
8685
}
87-
88-
// running same unit tests as https://github.com/kubernetes/apimachinery/blob/master/pkg/util/errors/errors_test.go#L371
89-
func TestAggregateGoroutinesWithDelay(t *testing.T) {
90-
testCases := []struct {
91-
errs []error
92-
expected map[string]bool
93-
}{
94-
{
95-
[]error{},
96-
nil,
97-
},
98-
{
99-
[]error{nil},
100-
nil,
101-
},
102-
{
103-
[]error{nil, nil},
104-
nil,
105-
},
106-
{
107-
[]error{fmt.Errorf("1")},
108-
map[string]bool{"1": true},
109-
},
110-
{
111-
[]error{fmt.Errorf("1"), nil},
112-
map[string]bool{"1": true},
113-
},
114-
{
115-
[]error{fmt.Errorf("1"), fmt.Errorf("267")},
116-
map[string]bool{"1": true, "267": true},
117-
},
118-
{
119-
[]error{fmt.Errorf("1"), nil, fmt.Errorf("1234")},
120-
map[string]bool{"1": true, "1234": true},
121-
},
122-
{
123-
[]error{nil, fmt.Errorf("1"), nil, fmt.Errorf("1234"), fmt.Errorf("22")},
124-
map[string]bool{"1": true, "1234": true, "22": true},
125-
},
126-
}
127-
for i, testCase := range testCases {
128-
funcs := make([]func() error, len(testCase.errs))
129-
for i := range testCase.errs {
130-
err := testCase.errs[i]
131-
funcs[i] = func() error { return err }
132-
}
133-
agg := aggregateGoroutinesWithDelay(100*time.Millisecond, funcs...)
134-
if agg == nil {
135-
if len(testCase.expected) > 0 {
136-
t.Errorf("%d: expected %v, got nil", i, testCase.expected)
137-
}
138-
continue
139-
}
140-
if len(agg.Errors()) != len(testCase.expected) {
141-
t.Errorf("%d: expected %d errors in aggregate, got %v", i, len(testCase.expected), agg)
142-
continue
143-
}
144-
for _, err := range agg.Errors() {
145-
if !testCase.expected[err.Error()] {
146-
t.Errorf("%d: expected %v, got aggregate containing %v", i, testCase.expected, err)
147-
}
148-
}
149-
}
150-
}

staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmsets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type VMSet interface {
6262
EnsureHostsInPool(service *v1.Service, nodes []*v1.Node, backendPoolID string, vmSetName string, isInternal bool) error
6363
// EnsureHostInPool ensures the given VM's Primary NIC's Primary IP Configuration is
6464
// participating in the specified LoadBalancer Backend Pool.
65-
EnsureHostInPool(service *v1.Service, nodeName types.NodeName, backendPoolID string, vmSetName string, isInternal bool) error
65+
EnsureHostInPool(service *v1.Service, nodeName types.NodeName, backendPoolID string, vmSetName string, isInternal bool) (string, string, string, *compute.VirtualMachineScaleSetVM, error)
6666
// EnsureBackendPoolDeleted ensures the loadBalancer backendAddressPools deleted from the specified nodes.
6767
EnsureBackendPoolDeleted(service *v1.Service, backendPoolID, vmSetName string, backendAddressPools *[]network.BackendAddressPool) error
6868

0 commit comments

Comments
 (0)