add timeout in GetVolumeLimits operation

add timeout for getAllStorageAccounts
pull/564/head
andyzhangx 2019-02-22 06:50:48 +00:00
parent 156602408a
commit 8cd09bb143
2 changed files with 6 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package azure
import (
"bytes"
"context"
"encoding/binary"
"fmt"
"net/url"
@ -439,7 +440,7 @@ func (c *BlobDiskController) getDiskCount(SAName string) (int, error) {
}
func (c *BlobDiskController) getAllStorageAccounts() (map[string]*storageAccountState, error) {
ctx, cancel := getContextWithCancel()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
accountListResult, err := c.common.cloud.StorageAccountClient.ListByResourceGroup(ctx, c.common.resourceGroup)
if err != nil {

View File

@ -20,6 +20,7 @@ import (
"context"
"fmt"
"strings"
"time"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2018-07-01/storage"
@ -164,7 +165,9 @@ func (plugin *azureDataDiskPlugin) GetVolumeLimits() (map[string]int64, error) {
}
if vmSizeList == nil {
result, err := az.VirtualMachineSizesClient.List(context.TODO(), az.Location)
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
result, err := az.VirtualMachineSizesClient.List(ctx, az.Location)
if err != nil || result.Value == nil {
klog.Errorf("failed to list vm sizes in GetVolumeLimits, plugin.host: %s, location: %s", plugin.host.GetHostName(), az.Location)
return volumeLimits, nil