Commit bb42103f authored by andyzhangx's avatar andyzhangx

move InitStorageAccount into azure disk provision func

parent 11fc906c
...@@ -22,7 +22,6 @@ import ( ...@@ -22,7 +22,6 @@ import (
"fmt" "fmt"
"math" "math"
"net/url" "net/url"
"os"
"regexp" "regexp"
"sync" "sync"
...@@ -70,12 +69,6 @@ var accountsLock = &sync.Mutex{} ...@@ -70,12 +69,6 @@ var accountsLock = &sync.Mutex{}
func newBlobDiskController(common *controllerCommon) (*BlobDiskController, error) { func newBlobDiskController(common *controllerCommon) (*BlobDiskController, error) {
c := BlobDiskController{common: common} c := BlobDiskController{common: common}
err := c.init()
if err != nil {
return nil, err
}
return &c, nil return &c, nil
} }
...@@ -316,7 +309,7 @@ func (c *BlobDiskController) DeleteBlobDisk(diskURI string, wasForced bool) erro ...@@ -316,7 +309,7 @@ func (c *BlobDiskController) DeleteBlobDisk(diskURI string, wasForced bool) erro
// Init tries best effort to ensure that 2 accounts standard/premium were created // 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) // to be used by shared blob disks. This to increase the speed pvc provisioning (in most of cases)
func (c *BlobDiskController) init() error { func (c *BlobDiskController) InitStorageAccount() error {
if !c.shouldInit() { if !c.shouldInit() {
return nil return nil
} }
...@@ -543,13 +536,7 @@ func (c *BlobDiskController) getDiskCount(SAName string) (int, error) { ...@@ -543,13 +536,7 @@ func (c *BlobDiskController) getDiskCount(SAName string) (int, error) {
// and we only do that in the controller // and we only do that in the controller
func (c *BlobDiskController) shouldInit() bool { func (c *BlobDiskController) shouldInit() bool {
if os.Args[0] == "kube-controller-manager" || (os.Args[0] == "/hyperkube" && os.Args[1] == "controller-manager") { return atomic.CompareAndSwapInt64(&initFlag, 0, 1)
swapped := atomic.CompareAndSwapInt64(&initFlag, 0, 1)
if swapped {
return true
}
}
return false
} }
func (c *BlobDiskController) getAllStorageAccounts() (map[string]*storageAccountState, error) { func (c *BlobDiskController) getAllStorageAccounts() (map[string]*storageAccountState, error) {
......
...@@ -28,6 +28,8 @@ import ( ...@@ -28,6 +28,8 @@ 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
......
...@@ -168,6 +168,9 @@ func (p *azureDiskProvisioner) Provision() (*v1.PersistentVolume, error) { ...@@ -168,6 +168,9 @@ 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
......
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