From 9310a7a122e68259feeeb34b4a8cbd28ed53fb82 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] 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-AndreĢ --- 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..a4c7eeb 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("Invalid value %q for config key %q (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,