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 all commits
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
27 changes: 27 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,28 @@ 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
var found bool
for _, name := range disk.PossibleSnapshotStorageAccountTypesValues() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the possible values and their descriptions, it seems like different SKU types apply to different storage types, e.g. Premium_LRS is for Premium SSDs, Standard_LRS is for standard HDDs. If a user sets the SKU but has a mix of storage types, what is the behaviour? Does it fall back to an appropriate SKU for that storage type?

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])
snapsClient := disk.NewSnapshotsClientWithBaseURI(env.ResourceManagerEndpoint, snapshotsSubscriptionID)
Expand Down Expand Up @@ -172,6 +197,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 +287,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