Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1981 from feiskyer/abs
Browse files Browse the repository at this point in the history
Add cloud environment support for ABS backup
  • Loading branch information
fanminshi committed Aug 9, 2018
2 parents b33cca8 + 40d9d65 commit 0aec6b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/apis/etcd/v1beta2/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
BackupStorageTypeABS BackupStorageType = "ABS"
AzureSecretStorageAccount = "storage-account"
AzureSecretStorageKey = "storage-key"
AzureCloudKey = "cloud"
)

type BackupStorageType string
Expand Down
21 changes: 19 additions & 2 deletions pkg/util/azureutil/absfactory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"

"github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/go-autorest/autorest/azure"
api "github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -29,6 +30,15 @@ type ABSClient struct {
ABS *storage.BlobStorageClient
}

// parseAzureEnvironment returns azure environment by name
func parseAzureEnvironment(cloudName string) (azure.Environment, error) {
if cloudName == "" {
return azure.PublicCloud, nil
}

return azure.EnvironmentFromName(cloudName)
}

// NewClientFromSecret returns a ABS client based on given k8s secret containing azure credentials.
func NewClientFromSecret(kubecli kubernetes.Interface, namespace, absSecret string) (w *ABSClient, err error) {
defer func() {
Expand All @@ -44,10 +54,17 @@ func NewClientFromSecret(kubecli kubernetes.Interface, namespace, absSecret stri

storageAccount := se.Data[api.AzureSecretStorageAccount]
storageKey := se.Data[api.AzureSecretStorageKey]
cloudName := se.Data[api.AzureCloudKey]

cloud, err := parseAzureEnvironment(string(cloudName))
if err != nil {
return nil, err
}

bc, err := storage.NewBasicClient(
bc, err := storage.NewBasicClientOnSovereignCloud(
string(storageAccount),
string(storageKey))
string(storageKey),
cloud)
if err != nil {
return nil, fmt.Errorf("failed to create Azure storage client: %v", err)
}
Expand Down

0 comments on commit 0aec6b1

Please sign in to comment.