Commit 51bb3831 authored by andyzhangx's avatar andyzhangx

remove get azure accounts in the init process set timeout for get azure account operation

use const for timeout value remove get azure accounts in the init process add lock for account init
parent ff6a78dd
...@@ -456,22 +456,8 @@ func initDiskControllers(az *Cloud) error { ...@@ -456,22 +456,8 @@ func initDiskControllers(az *Cloud) error {
cloud: az, cloud: az,
} }
// BlobDiskController: contains the function needed to az.BlobDiskController = &BlobDiskController{common: common}
// create/attach/detach/delete blob based (unmanaged disks) az.ManagedDiskController = &ManagedDiskController{common: common}
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.controllerCommon = common az.controllerCommon = common
return nil return nil
......
...@@ -62,18 +62,19 @@ var ( ...@@ -62,18 +62,19 @@ var (
accountsLock = &sync.Mutex{} accountsLock = &sync.Mutex{}
) )
func newBlobDiskController(common *controllerCommon) (*BlobDiskController, error) { func (c *BlobDiskController) initStorageAccounts() {
c := BlobDiskController{common: common} accountsLock.Lock()
defer accountsLock.Unlock()
// get accounts if c.accounts == nil {
accounts, err := c.getAllStorageAccounts() // get accounts
if err != nil { accounts, err := c.getAllStorageAccounts()
klog.Errorf("azureDisk - getAllStorageAccounts error: %v", err) if err != nil {
c.accounts = make(map[string]*storageAccountState) klog.Errorf("azureDisk - getAllStorageAccounts error: %v", err)
return &c, nil 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. // CreateVolume creates a VHD blob in a storage account that has storageType and location using the given storage account.
...@@ -217,6 +218,8 @@ func (c *BlobDiskController) deleteVhdBlob(accountName, accountKey, blobName str ...@@ -217,6 +218,8 @@ func (c *BlobDiskController) deleteVhdBlob(accountName, accountKey, blobName str
func (c *BlobDiskController) CreateBlobDisk(dataDiskName string, storageAccountType storage.SkuName, sizeGB int) (string, error) { 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) klog.V(4).Infof("azureDisk - creating blob data disk named:%s on StorageAccountType:%s", dataDiskName, storageAccountType)
c.initStorageAccounts()
storageAccountName, err := c.findSANameForDisk(storageAccountType) storageAccountName, err := c.findSANameForDisk(storageAccountType)
if err != nil { if err != nil {
return "", err return "", err
......
...@@ -68,10 +68,6 @@ type ManagedDiskOptions struct { ...@@ -68,10 +68,6 @@ type ManagedDiskOptions struct {
DiskMBpsReadWrite string DiskMBpsReadWrite string
} }
func newManagedDiskController(common *controllerCommon) (*ManagedDiskController, error) {
return &ManagedDiskController{common: common}, nil
}
//CreateManagedDisk : create managed disk //CreateManagedDisk : create managed disk
func (c *ManagedDiskController) CreateManagedDisk(options *ManagedDiskOptions) (string, error) { func (c *ManagedDiskController) CreateManagedDisk(options *ManagedDiskOptions) (string, error) {
var err error var err error
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment