remove initialize storage account pool process

remove init func

allow getStorageAccounts failed
This commit is contained in:
andyzhangx 2017-11-17 07:27:01 +00:00
parent bb42103fca
commit 3d60d18002
3 changed files with 10 additions and 68 deletions

View File

@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"math"
"net/url" "net/url"
"regexp" "regexp"
"sync" "sync"
@ -63,12 +62,21 @@ type BlobDiskController struct {
var defaultContainerName = "" var defaultContainerName = ""
var storageAccountNamePrefix = "" var storageAccountNamePrefix = ""
var storageAccountNameMatch = "" var storageAccountNameMatch = ""
var initFlag int64
var accountsLock = &sync.Mutex{} var accountsLock = &sync.Mutex{}
func newBlobDiskController(common *controllerCommon) (*BlobDiskController, error) { func newBlobDiskController(common *controllerCommon) (*BlobDiskController, error) {
c := BlobDiskController{common: common} c := BlobDiskController{common: common}
c.setUniqueStrings()
// get accounts
accounts, err := c.getAllStorageAccounts()
if err != nil {
glog.Errorf("azureDisk - getAllStorageAccounts error: %v", err)
c.accounts = make(map[string]*storageAccountState)
return &c, nil
}
c.accounts = accounts
return &c, nil return &c, nil
} }
@ -307,60 +315,6 @@ func (c *BlobDiskController) DeleteBlobDisk(diskURI string, wasForced bool) erro
return err return err
} }
// Init tries best effort to ensure that 2 accounts standard/premium were created
// to be used by shared blob disks. This to increase the speed pvc provisioning (in most of cases)
func (c *BlobDiskController) InitStorageAccount() error {
if !c.shouldInit() {
return nil
}
c.setUniqueStrings()
// get accounts
accounts, err := c.getAllStorageAccounts()
if err != nil {
return err
}
c.accounts = accounts
if len(c.accounts) == 0 {
counter := 1
for counter <= storageAccountsCountInit {
accountType := storage.PremiumLRS
if n := math.Mod(float64(counter), 2); n == 0 {
accountType = storage.StandardLRS
}
// We don't really care if these calls failed
// at this stage, we are trying to ensure 2 accounts (Standard/Premium)
// are there ready for PVC creation
// if we failed here, the accounts will be created in the process
// of creating PVC
// nor do we care if they were partially created, as the entire
// account creation process is idempotent
go func(thisNext int) {
newAccountName := getAccountNameForNum(thisNext)
glog.Infof("azureDisk - BlobDiskController init process will create new storageAccount:%s type:%s", newAccountName, accountType)
err := c.createStorageAccount(newAccountName, accountType, c.common.location, true)
// TODO return created and error from
if err != nil {
glog.Infof("azureDisk - BlobDiskController init: create account %s with error:%s", newAccountName, err.Error())
} else {
glog.Infof("azureDisk - BlobDiskController init: created account %s", newAccountName)
}
}(counter)
counter = counter + 1
}
}
return nil
}
//Sets unique strings to be used as accountnames && || blob containers names //Sets unique strings to be used as accountnames && || blob containers names
func (c *BlobDiskController) setUniqueStrings() { func (c *BlobDiskController) setUniqueStrings() {
uniqueString := c.common.resourceGroup + c.common.location + c.common.subscriptionID uniqueString := c.common.resourceGroup + c.common.location + c.common.subscriptionID
@ -532,13 +486,6 @@ func (c *BlobDiskController) getDiskCount(SAName string) (int, error) {
return int(c.accounts[SAName].diskCount), nil return int(c.accounts[SAName].diskCount), nil
} }
// shouldInit ensures that we only init the plugin once
// and we only do that in the controller
func (c *BlobDiskController) shouldInit() bool {
return atomic.CompareAndSwapInt64(&initFlag, 0, 1)
}
func (c *BlobDiskController) getAllStorageAccounts() (map[string]*storageAccountState, error) { func (c *BlobDiskController) getAllStorageAccounts() (map[string]*storageAccountState, error) {
accountListResult, err := c.common.cloud.StorageAccountClient.List() accountListResult, err := c.common.cloud.StorageAccountClient.List()
if err != nil { if err != nil {

View File

@ -28,8 +28,6 @@ import (
// interface exposed by the cloud provider implementing Disk functionlity // interface exposed by the cloud provider implementing Disk functionlity
type DiskController interface { type DiskController interface {
InitStorageAccount() error
CreateBlobDisk(dataDiskName string, storageAccountType storage.SkuName, sizeGB int, forceStandAlone bool) (string, error) CreateBlobDisk(dataDiskName string, storageAccountType storage.SkuName, sizeGB int, forceStandAlone bool) (string, error)
DeleteBlobDisk(diskUri string, wasForced bool) error DeleteBlobDisk(diskUri string, wasForced bool) error

View File

@ -168,9 +168,6 @@ func (p *azureDiskProvisioner) Provision() (*v1.PersistentVolume, error) {
} }
} }
} else { } else {
if err = diskController.InitStorageAccount(); err != nil {
return nil, err
}
diskURI, err = diskController.CreateBlobDisk(name, skuName, requestGB, forceStandAlone) diskURI, err = diskController.CreateBlobDisk(name, skuName, requestGB, forceStandAlone)
if err != nil { if err != nil {
return nil, err return nil, err