From 9c3fb62b540cfca1bcb75363a21c76c9369181da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vieillard-Baron=20Pierre-Andre=CC=81?= Date: Sun, 2 May 2021 16:39:31 +0200 Subject: [PATCH 1/4] Make Azure disk snapshot SKU configurable (#96) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new supported key to the config ('sku') which allows to specify the SKU used for the Azure disk snapshot The values supported depend of the Azure zone, it can be: Premium_LRS, Standard_LRS or Standard_ZRS Signed-off-by: Vieillard-Baron Pierre-André --- changelogs/unreleased/pr-pavb74 | 1 + .../volume_snapshotter.go | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 changelogs/unreleased/pr-pavb74 diff --git a/changelogs/unreleased/pr-pavb74 b/changelogs/unreleased/pr-pavb74 new file mode 100644 index 0000000..b684839 --- /dev/null +++ b/changelogs/unreleased/pr-pavb74 @@ -0,0 +1 @@ +- add support for sku on snapshots of Azure disks (#96, @pavb74) diff --git a/velero-plugin-for-microsoft-azure/volume_snapshotter.go b/velero-plugin-for-microsoft-azure/volume_snapshotter.go index 8a9c548..58315fa 100644 --- a/velero-plugin-for-microsoft-azure/volume_snapshotter.go +++ b/velero-plugin-for-microsoft-azure/volume_snapshotter.go @@ -44,6 +44,7 @@ const ( apiTimeoutConfigKey = "apiTimeout" snapsIncrementalConfigKey = "incremental" + snapsSkuConfigKey = "sku" snapshotsResource = "snapshots" disksResource = "disks" @@ -58,6 +59,7 @@ type VolumeSnapshotter struct { disksResourceGroup string snapsResourceGroup string snapsIncremental *bool + snapsSku *disk.SnapshotSku apiTimeout time.Duration } @@ -81,6 +83,7 @@ func (b *VolumeSnapshotter) Init(config map[string]string) error { apiTimeoutConfigKey, subscriptionIDConfigKey, snapsIncrementalConfigKey, + snapsSkuConfigKey, ); err != nil { return err } @@ -145,6 +148,25 @@ func (b *VolumeSnapshotter) Init(config map[string]string) error { snapshotsIncremental = nil } + // if config["snapsSkuConfigKey"] is empty, default to nil; otherwise, convert it + var snapshotsSku *disk.SnapshotSku + if val := config[snapsSkuConfigKey]; val != "" { + var snapshotsSkuName disk.SnapshotStorageAccountTypes; + switch val { + case "Premium_LRS": snapshotsSkuName = disk.SnapshotStorageAccountTypesPremiumLRS + case "Standard_LRS": snapshotsSkuName = disk.SnapshotStorageAccountTypesStandardLRS + case "Standard_ZRS": snapshotsSkuName = disk.SnapshotStorageAccountTypesStandardZRS + default: + return errors.New(fmt.Sprintf("Invalid value %s for config key %s (Premium_LRS, Standard_LRS or Standard_ZRS are supported)", val, snapsSkuConfigKey)) + } + + snapshotsSku = &disk.SnapshotSku{ + Name: snapshotsSkuName, + } + } else { + snapshotsSku = nil + } + // set up clients disksClient := disk.NewDisksClientWithBaseURI(env.ResourceManagerEndpoint, envVars[subscriptionIDEnvVar]) snapsClient := disk.NewSnapshotsClientWithBaseURI(env.ResourceManagerEndpoint, snapshotsSubscriptionID) @@ -172,6 +194,7 @@ func (b *VolumeSnapshotter) Init(config map[string]string) error { b.apiTimeout = apiTimeout b.snapsIncremental = snapshotsIncremental + b.snapsSku = snapshotsSku return nil } @@ -261,6 +284,7 @@ func (b *VolumeSnapshotter) CreateSnapshot(volumeID, volumeAZ string, tags map[s snap := disk.Snapshot{ Name: &snapshotName, + Sku: b.snapsSku, SnapshotProperties: &disk.SnapshotProperties{ CreationData: &disk.CreationData{ CreateOption: disk.Copy, From c49e0b509bbe38e4c76de1a0092d133e97715f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Andr=C3=A9=20VIEILLARD-BARON?= Date: Fri, 23 Jul 2021 16:49:07 +0200 Subject: [PATCH 2/4] Update changelogs/unreleased/pr-pavb74 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: JenTing Hsiao Signed-off-by: Vieillard-Baron Pierre-André --- changelogs/unreleased/pr-pavb74 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/unreleased/pr-pavb74 b/changelogs/unreleased/pr-pavb74 index b684839..16d0278 100644 --- a/changelogs/unreleased/pr-pavb74 +++ b/changelogs/unreleased/pr-pavb74 @@ -1 +1 @@ -- add support for sku on snapshots of Azure disks (#96, @pavb74) +Add support for sku on snapshots of Azure disks From 5481cb9772eee66c0e53c18428dec42d294d011e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Andr=C3=A9=20VIEILLARD-BARON?= Date: Fri, 23 Jul 2021 16:49:17 +0200 Subject: [PATCH 3/4] Update velero-plugin-for-microsoft-azure/volume_snapshotter.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: JenTing Hsiao Signed-off-by: Vieillard-Baron Pierre-André --- velero-plugin-for-microsoft-azure/volume_snapshotter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/velero-plugin-for-microsoft-azure/volume_snapshotter.go b/velero-plugin-for-microsoft-azure/volume_snapshotter.go index 58315fa..6148207 100644 --- a/velero-plugin-for-microsoft-azure/volume_snapshotter.go +++ b/velero-plugin-for-microsoft-azure/volume_snapshotter.go @@ -44,7 +44,7 @@ const ( apiTimeoutConfigKey = "apiTimeout" snapsIncrementalConfigKey = "incremental" - snapsSkuConfigKey = "sku" + snapsSkuConfigKey = "sku" snapshotsResource = "snapshots" disksResource = "disks" From 1fa7ff09afb7c578f709221206d995dfc146ca48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Andr=C3=A9=20VIEILLARD-BARON?= Date: Fri, 23 Jul 2021 16:56:53 +0200 Subject: [PATCH 4/4] Update velero-plugin-for-microsoft-azure/volume_snapshotter.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: JenTing Hsiao Signed-off-by: Vieillard-Baron Pierre-André --- .../volume_snapshotter.go | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/velero-plugin-for-microsoft-azure/volume_snapshotter.go b/velero-plugin-for-microsoft-azure/volume_snapshotter.go index 6148207..5139049 100644 --- a/velero-plugin-for-microsoft-azure/volume_snapshotter.go +++ b/velero-plugin-for-microsoft-azure/volume_snapshotter.go @@ -150,22 +150,25 @@ func (b *VolumeSnapshotter) Init(config map[string]string) error { // if config["snapsSkuConfigKey"] is empty, default to nil; otherwise, convert it var snapshotsSku *disk.SnapshotSku - if val := config[snapsSkuConfigKey]; val != "" { - var snapshotsSkuName disk.SnapshotStorageAccountTypes; - switch val { - case "Premium_LRS": snapshotsSkuName = disk.SnapshotStorageAccountTypesPremiumLRS - case "Standard_LRS": snapshotsSkuName = disk.SnapshotStorageAccountTypesStandardLRS - case "Standard_ZRS": snapshotsSkuName = disk.SnapshotStorageAccountTypesStandardZRS - default: - return errors.New(fmt.Sprintf("Invalid value %s for config key %s (Premium_LRS, Standard_LRS or Standard_ZRS are supported)", val, snapsSkuConfigKey)) - } - - snapshotsSku = &disk.SnapshotSku{ - Name: snapshotsSkuName, - } - } else { - snapshotsSku = nil - } + if val := config[snapsSkuConfigKey]; val != "" { + var snapshotsSkuName disk.SnapshotStorageAccountTypes + var found bool + for _, name := range disk.PossibleSnapshotStorageAccountTypesValues() { + if val == string(name) { + found = true + snapshotsSkuName = name + } + } + if !found { + return fmt.Errorf("Invalid value %s for config key %s (%v are supported)", val, snapsSkuConfigKey, disk.PossibleSnapshotStorageAccountTypesValues()) + } + + snapshotsSku = &disk.SnapshotSku{ + Name: snapshotsSkuName, + } + } else { + snapshotsSku = nil + } // set up clients disksClient := disk.NewDisksClientWithBaseURI(env.ResourceManagerEndpoint, envVars[subscriptionIDEnvVar])