Skip to content

Commit

Permalink
Azure - Migrate snapshot to a resource group (#1019)
Browse files Browse the repository at this point in the history
* migrateresourcegroup

* wrong key, very error

* remove comment

* after carls review

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
bathina2 and mergify[bot] committed Jun 16, 2021
1 parent e10d3eb commit 5e8e217
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/blockstorage/azure/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (s *AdStorage) SnapshotCopy(ctx context.Context, from blockstorage.Snapshot

// SnapshotCopyWithArgs func: args map should contain non-empty StorageAccountName(AZURE_MIGRATE_STORAGE_ACCOUNT_NAME)
// and StorageKey(AZURE_MIGRATE_STORAGE_ACCOUNT_KEY)
// A destination ResourceGroup (AZURE_MIGRATE_RESOURCE_GROUP) can be provided. The created snapshot will belong to this.
func (s *AdStorage) SnapshotCopyWithArgs(ctx context.Context, from blockstorage.Snapshot, to blockstorage.Snapshot, args map[string]string) (*blockstorage.Snapshot, error) {
migrateStorageAccount := args[blockstorage.AzureMigrateStorageAccount]
migrateStorageKey := args[blockstorage.AzureMigrateStorageKey]
Expand Down Expand Up @@ -225,7 +226,11 @@ func (s *AdStorage) SnapshotCopyWithArgs(ctx context.Context, from blockstorage.
},
}

result, err := s.azCli.SnapshotsClient.CreateOrUpdate(ctx, s.azCli.ResourceGroup, snapName, createSnap)
migrateResourceGroup := s.azCli.ResourceGroup
if val, ok := args[blockstorage.AzureMigrateResourceGroup]; ok && val != "" {
migrateResourceGroup = val
}
result, err := s.azCli.SnapshotsClient.CreateOrUpdate(ctx, migrateResourceGroup, snapName, createSnap)
if err != nil {
return nil, errors.Wrapf(err, "Failed to copy snapshot from source snapshot %v", from)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/blockstorage/blockstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func (s *BlockStorageProviderSuite) getConfig(c *C, region string) map[string]st
config[blockstorage.AzureResurceGroup] = envconfig.GetEnvOrSkip(c, blockstorage.AzureResurceGroup)
s.args[blockstorage.AzureMigrateStorageAccount] = envconfig.GetEnvOrSkip(c, blockstorage.AzureMigrateStorageAccount)
s.args[blockstorage.AzureMigrateStorageKey] = envconfig.GetEnvOrSkip(c, blockstorage.AzureMigrateStorageKey)
s.args[blockstorage.AzureMigrateResourceGroup] = envconfig.GetEnvOrSkip(c, blockstorage.AzureMigrateResourceGroup)
default:
c.Errorf("Unknown blockstorage storage type %s", s.storageType)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/blockstorage/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
AzureResurceMgrEndpoint = "AZURE_RESOURCE_MANAGER_ENDPOINT"
AzureMigrateStorageAccount = "AZURE_MIGRATE_STORAGE_ACCOUNT_NAME"
AzureMigrateStorageKey = "AZURE_MIGRATE_STORAGE_ACCOUNT_KEY"
AzureMigrateResourceGroup = "AZURE_MIGRATE_RESOURCE_GROUP"
AzureActiveDirEndpoint = "AZURE_AD_ENDPOINT"
AzureActiveDirResourceID = "AZURE_AD_RESOURCE"
)
Expand Down

0 comments on commit 5e8e217

Please sign in to comment.