Remove unused function aggregateGoroutinesWithDelay

This commit is contained in:
Pengfei Ni 2020-03-01 06:48:57 +00:00
parent 0f4cfe58d8
commit 7f270038d3
6 changed files with 5 additions and 97 deletions

View File

@ -21,9 +21,6 @@ package azure
import (
"context"
"sync"
"time"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
)
// lockMap used to lock on entries
@ -77,21 +74,3 @@ func (lm *lockMap) unlockEntry(entry string) {
func getContextWithCancel() (context.Context, context.CancelFunc) {
return context.WithCancel(context.Background())
}
// aggregateGoroutinesWithDelay aggregates goroutines and runs them
// in parallel with delay before starting each goroutine
func aggregateGoroutinesWithDelay(delay time.Duration, funcs ...func() error) utilerrors.Aggregate {
errChan := make(chan error, len(funcs))
for _, f := range funcs {
go func(f func() error) { errChan <- f() }(f)
time.Sleep(delay)
}
errs := make([]error, 0)
for i := 0; i < cap(errChan); i++ {
if err := <-errChan; err != nil {
errs = append(errs, err)
}
}
return utilerrors.NewAggregate(errs)
}

View File

@ -19,7 +19,6 @@ limitations under the License.
package azure
import (
"fmt"
"testing"
"time"
)
@ -84,67 +83,3 @@ func ensureNoCallback(t *testing.T, callbackChan <-chan interface{}) bool {
return true
}
}
// running same unit tests as https://github.com/kubernetes/apimachinery/blob/master/pkg/util/errors/errors_test.go#L371
func TestAggregateGoroutinesWithDelay(t *testing.T) {
testCases := []struct {
errs []error
expected map[string]bool
}{
{
[]error{},
nil,
},
{
[]error{nil},
nil,
},
{
[]error{nil, nil},
nil,
},
{
[]error{fmt.Errorf("1")},
map[string]bool{"1": true},
},
{
[]error{fmt.Errorf("1"), nil},
map[string]bool{"1": true},
},
{
[]error{fmt.Errorf("1"), fmt.Errorf("267")},
map[string]bool{"1": true, "267": true},
},
{
[]error{fmt.Errorf("1"), nil, fmt.Errorf("1234")},
map[string]bool{"1": true, "1234": true},
},
{
[]error{nil, fmt.Errorf("1"), nil, fmt.Errorf("1234"), fmt.Errorf("22")},
map[string]bool{"1": true, "1234": true, "22": true},
},
}
for i, testCase := range testCases {
funcs := make([]func() error, len(testCase.errs))
for i := range testCase.errs {
err := testCase.errs[i]
funcs[i] = func() error { return err }
}
agg := aggregateGoroutinesWithDelay(100*time.Millisecond, funcs...)
if agg == nil {
if len(testCase.expected) > 0 {
t.Errorf("%d: expected %v, got nil", i, testCase.expected)
}
continue
}
if len(agg.Errors()) != len(testCase.expected) {
t.Errorf("%d: expected %d errors in aggregate, got %v", i, len(testCase.expected), agg)
continue
}
for _, err := range agg.Errors() {
if !testCase.expected[err.Error()] {
t.Errorf("%d: expected %v, got aggregate containing %v", i, testCase.expected, err)
}
}
}
}

View File

@ -26,7 +26,6 @@ import (
"strconv"
"strings"
"sync"
"time"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
@ -56,13 +55,6 @@ var (
vmssVMProviderIDRE = regexp.MustCompile(`azure:///subscriptions/(?:.*)/resourceGroups/(.+)/providers/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines/(?:\d+)`)
)
const (
// vmssVMInstanceUpdateDelay is used when updating multiple vm instances in parallel
// the optimum value is 3s to prevent any conflicts that result in concurrent vmss vm
// instances update
vmssVMInstanceUpdateDelay = 3 * time.Second
)
// vmssMetaInfo contains the metadata for a VMSS.
type vmssMetaInfo struct {
vmssName string

View File

@ -10,6 +10,7 @@ go_library(
importpath = "k8s.io/legacy-cloud-providers/azure/clients/armclient/mockarmclient",
visibility = ["//visibility:public"],
deps = [
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/armclient:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/retry:go_default_library",
"//vendor/github.com/Azure/go-autorest/autorest:go_default_library",
"//vendor/github.com/Azure/go-autorest/autorest/azure:go_default_library",

View File

@ -11,6 +11,7 @@ go_library(
importpath = "k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient",
visibility = ["//visibility:public"],
deps = [
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients:go_default_library",
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/armclient:go_default_library",

View File

@ -26,7 +26,7 @@ import (
gomock "github.com/golang/mock/gomock"
v1 "k8s.io/api/core/v1"
types "k8s.io/apimachinery/pkg/types"
cloud_provider "k8s.io/cloud-provider"
cloudprovider "k8s.io/cloud-provider"
cache "k8s.io/legacy-cloud-providers/azure/cache"
)
@ -130,10 +130,10 @@ func (mr *MockVMSetMockRecorder) GetNodeNameByProviderID(providerID interface{})
}
// GetZoneByNodeName mocks base method
func (m *MockVMSet) GetZoneByNodeName(name string) (cloud_provider.Zone, error) {
func (m *MockVMSet) GetZoneByNodeName(name string) (cloudprovider.Zone, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetZoneByNodeName", name)
ret0, _ := ret[0].(cloud_provider.Zone)
ret0, _ := ret[0].(cloudprovider.Zone)
ret1, _ := ret[1].(error)
return ret0, ret1
}