Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Azure disk snapshot SKU configurable (#96) #96

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 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)
pavb74 marked this conversation as resolved.
Show resolved Hide resolved
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"
pavb74 marked this conversation as resolved.
Show resolved Hide resolved

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
}
pavb74 marked this conversation as resolved.
Show resolved Hide resolved

// 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