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

Add cloud environment support for ABS backup #1981

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it looks like go-autorest is a transient dependency, this seems to make it a direct dependency.
Should this include an update to Gopkg.toml?

Copy link
Contributor Author

@feiskyer feiskyer Aug 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not farmiliar with dep. Run dep ensure doesn't add that. Should I add it explicitly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add go-autorest. it is vendored already via https://github.com/coreos/etcd-operator/blame/master/Gopkg.lock#L17

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