Skip to content

Commit

Permalink
remove hardcoded azure storage account name
Browse files Browse the repository at this point in the history
  • Loading branch information
stoader authored and baluchicken committed Jul 30, 2019
1 parent 3afc25a commit 54e7584
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/stub/providers/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"math/rand"
"net/http"
)

Expand Down Expand Up @@ -120,6 +121,7 @@ func createStorageAccount(ctx context.Context, accountName string, az *AzureProv
logrus.Fatalf("%s [%s]: %v: %v", "storage account name not available", accountName, err, *result.Message)
}


future, err := storageAccountsClient.Create(
ctx,
az.metadata.resourceGroupName,
Expand All @@ -130,6 +132,7 @@ func createStorageAccount(ctx context.Context, accountName string, az *AzureProv
Kind: storage.Storage,
Location: to.StringPtr(az.metadata.location),
AccountPropertiesCreateParameters: &storage.AccountPropertiesCreateParameters{},
Tags: map[string]*string{"created-by": to.StringPtr("pvc-operator")},
})

if err != nil {
Expand Down Expand Up @@ -170,7 +173,7 @@ func (az *AzureProvider) determineParameters(pvc *v1.PersistentVolumeClaim) (map
case "ReadWriteMany", "ReadOnlyMany":
loc := az.metadata.location
parameter[location] = loc
parameter[storageAccount] = "banzaicloudtest"
parameter[storageAccount] = generateStorageAccountName()
parameter[skuName] = "Standard_LRS"
return parameter, nil
}
Expand Down Expand Up @@ -202,3 +205,15 @@ func (az *AzureProvider) CheckBucketExistence(bucket *v1alpha1.ObjectStore) (boo
func (az *AzureProvider) CreateObjectStoreBucket(*v1alpha1.ObjectStore) error {
return nil
}

// generateStorageAccountName generates a random name of 24 chars length that consists of lower case letters and numbers
func generateStorageAccountName() string {
letters := "abcdefghijklmnopqrstuvwxyz0123456789"
b := make([]byte, 24)

for i := range b {
b[i] = letters[rand.Int63() % int64(len(letters))]
}

return string(b)
}

0 comments on commit 54e7584

Please sign in to comment.