Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #74191: remove get azure accounts in the init process set timeout #74486

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 2 additions & 16 deletions pkg/cloudprovider/providers/azure/azure.go
Expand Up @@ -456,22 +456,8 @@ func initDiskControllers(az *Cloud) error {
cloud: az,
}

// BlobDiskController: contains the function needed to
// create/attach/detach/delete blob based (unmanaged disks)
blobController, err := newBlobDiskController(common)
if err != nil {
return fmt.Errorf("AzureDisk - failed to init Blob Disk Controller with error (%s)", err.Error())
}

// ManagedDiskController: contains the functions needed to
// create/attach/detach/delete managed disks
managedController, err := newManagedDiskController(common)
if err != nil {
return fmt.Errorf("AzureDisk - failed to init Managed Disk Controller with error (%s)", err.Error())
}

az.BlobDiskController = blobController
az.ManagedDiskController = managedController
az.BlobDiskController = &BlobDiskController{common: common}
az.ManagedDiskController = &ManagedDiskController{common: common}
az.controllerCommon = common

return nil
Expand Down
26 changes: 15 additions & 11 deletions pkg/cloudprovider/providers/azure/azure_blobDiskController.go
Expand Up @@ -18,6 +18,7 @@ package azure

import (
"bytes"
"context"
"encoding/binary"
"fmt"
"net/url"
Expand Down Expand Up @@ -62,18 +63,19 @@ var (
accountsLock = &sync.Mutex{}
)

func newBlobDiskController(common *controllerCommon) (*BlobDiskController, error) {
c := BlobDiskController{common: common}
func (c *BlobDiskController) initStorageAccounts() {
accountsLock.Lock()
defer accountsLock.Unlock()

// get accounts
accounts, err := c.getAllStorageAccounts()
if err != nil {
klog.Errorf("azureDisk - getAllStorageAccounts error: %v", err)
c.accounts = make(map[string]*storageAccountState)
return &c, nil
if c.accounts == nil {
// get accounts
accounts, err := c.getAllStorageAccounts()
if err != nil {
klog.Errorf("azureDisk - getAllStorageAccounts error: %v", err)
c.accounts = make(map[string]*storageAccountState)
}
c.accounts = accounts
}
c.accounts = accounts
return &c, nil
}

// CreateVolume creates a VHD blob in a storage account that has storageType and location using the given storage account.
Expand Down Expand Up @@ -217,6 +219,8 @@ func (c *BlobDiskController) deleteVhdBlob(accountName, accountKey, blobName str
func (c *BlobDiskController) CreateBlobDisk(dataDiskName string, storageAccountType storage.SkuName, sizeGB int) (string, error) {
klog.V(4).Infof("azureDisk - creating blob data disk named:%s on StorageAccountType:%s", dataDiskName, storageAccountType)

c.initStorageAccounts()

storageAccountName, err := c.findSANameForDisk(storageAccountType)
if err != nil {
return "", err
Expand Down Expand Up @@ -436,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 {
Expand Down
Expand Up @@ -68,10 +68,6 @@ type ManagedDiskOptions struct {
DiskMBpsReadWrite string
}

func newManagedDiskController(common *controllerCommon) (*ManagedDiskController, error) {
return &ManagedDiskController{common: common}, nil
}

//CreateManagedDisk : create managed disk
func (c *ManagedDiskController) CreateManagedDisk(options *ManagedDiskOptions) (string, error) {
var err error
Expand Down
5 changes: 4 additions & 1 deletion pkg/volume/azure_dd/azure_dd.go
Expand Up @@ -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"
Expand Down Expand Up @@ -160,7 +161,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
Expand Down