Skip to content

Commit

Permalink
Make Azure disk snapshot SKU configurable (#96)
Browse files Browse the repository at this point in the history
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é <[email protected]>
  • Loading branch information
Vieillard-Baron Pierre-André committed May 12, 2021
1 parent 002f406 commit 9c3fb62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/pr-pavb74
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- add support for sku on snapshots of Azure disks (#96, @pavb74)
24 changes: 24 additions & 0 deletions velero-plugin-for-microsoft-azure/volume_snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (

apiTimeoutConfigKey = "apiTimeout"
snapsIncrementalConfigKey = "incremental"
snapsSkuConfigKey = "sku"

snapshotsResource = "snapshots"
disksResource = "disks"
Expand All @@ -58,6 +59,7 @@ type VolumeSnapshotter struct {
disksResourceGroup string
snapsResourceGroup string
snapsIncremental *bool
snapsSku *disk.SnapshotSku
apiTimeout time.Duration
}

Expand All @@ -81,6 +83,7 @@ func (b *VolumeSnapshotter) Init(config map[string]string) error {
apiTimeoutConfigKey,
subscriptionIDConfigKey,
snapsIncrementalConfigKey,
snapsSkuConfigKey,
); err != nil {
return err
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -172,6 +194,7 @@ func (b *VolumeSnapshotter) Init(config map[string]string) error {
b.apiTimeout = apiTimeout

b.snapsIncremental = snapshotsIncremental
b.snapsSku = snapshotsSku

return nil
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9c3fb62

Please sign in to comment.