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

fix: validation of caching options for Ultra disks as data disks #2430

Merged
merged 1 commit into from
Jun 27, 2022
Merged
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
8 changes: 7 additions & 1 deletion api/v1beta1/azuremachine_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
"encoding/base64"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
"golang.org/x/crypto/ssh"
"k8s.io/apimachinery/pkg/util/uuid"
utilSSH "sigs.k8s.io/cluster-api-provider-azure/util/ssh"
Expand Down Expand Up @@ -67,7 +68,12 @@ func (s *AzureMachineSpec) SetDataDisksDefaults() {
}
}
if disk.CachingType == "" {
s.DataDisks[i].CachingType = "ReadWrite"
if s.DataDisks[i].ManagedDisk != nil &&
damdo marked this conversation as resolved.
Show resolved Hide resolved
s.DataDisks[i].ManagedDisk.StorageAccountType == string(compute.StorageAccountTypesUltraSSDLRS) {
s.DataDisks[i].CachingType = string(compute.CachingTypesNone)
} else {
s.DataDisks[i].CachingType = string(compute.CachingTypesReadWrite)
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions api/v1beta1/azuremachine_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) {
DiskSizeGB: 30,
Lun: to.Int32Ptr(2),
},
{
NameSuffix: "testdisk3",
DiskSizeGB: 30,
ManagedDisk: &ManagedDiskParameters{
StorageAccountType: "UltraSSD_LRS",
},
Lun: to.Int32Ptr(3),
},
},
output: []DataDisk{
{
Expand All @@ -229,6 +237,15 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) {
Lun: to.Int32Ptr(2),
CachingType: "ReadWrite",
},
{
NameSuffix: "testdisk3",
DiskSizeGB: 30,
Lun: to.Int32Ptr(3),
ManagedDisk: &ManagedDiskParameters{
StorageAccountType: "UltraSSD_LRS",
},
CachingType: "None",
},
},
},
}
Expand Down
12 changes: 9 additions & 3 deletions api/v1beta1/azuremachine_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func ValidateDataDisks(dataDisks []DataDisk, fieldPath *field.Path) field.ErrorL
}

// validate cachingType
allErrs = append(allErrs, validateCachingType(disk.CachingType, fieldPath)...)
allErrs = append(allErrs, validateCachingType(disk.CachingType, fieldPath, disk.ManagedDisk)...)
}
return allErrs
}
Expand All @@ -162,7 +162,7 @@ func ValidateOSDisk(osDisk OSDisk, fieldPath *field.Path) field.ErrorList {
allErrs = append(allErrs, field.Required(fieldPath.Child("OSType"), "the OS type cannot be empty"))
}

allErrs = append(allErrs, validateCachingType(osDisk.CachingType, fieldPath)...)
allErrs = append(allErrs, validateCachingType(osDisk.CachingType, fieldPath, osDisk.ManagedDisk)...)

if osDisk.ManagedDisk != nil {
if errs := validateManagedDisk(osDisk.ManagedDisk, fieldPath.Child("managedDisk"), true); len(errs) > 0 {
Expand Down Expand Up @@ -278,10 +278,16 @@ func validateStorageAccountType(storageAccountType string, fieldPath *field.Path
return allErrs
}

func validateCachingType(cachingType string, fieldPath *field.Path) field.ErrorList {
func validateCachingType(cachingType string, fieldPath *field.Path, managedDisk *ManagedDiskParameters) field.ErrorList {
allErrs := field.ErrorList{}
cachingTypeChildPath := fieldPath.Child("CachingType")

if managedDisk != nil && managedDisk.StorageAccountType == string(compute.StorageAccountTypesUltraSSDLRS) {
if cachingType != string(compute.CachingTypesNone) {
allErrs = append(allErrs, field.Invalid(cachingTypeChildPath, cachingType, fmt.Sprintf("cachingType '%s' is not supported when storageAccountType is '%s'. Allowed values are: '%s'", cachingType, compute.StorageAccountTypesUltraSSDLRS, compute.CachingTypesNone)))
}
}

for _, possibleCachingType := range compute.PossibleCachingTypesValues() {
if string(possibleCachingType) == cachingType {
return allErrs
Expand Down
45 changes: 45 additions & 0 deletions api/v1beta1/azuremachine_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,51 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) {
},
wantErr: true,
},
{
name: "valid combination of managed disk storage account type UltraSSD_LRS and cachingType None",
disks: []DataDisk{
{
NameSuffix: "my_disk_1",
DiskSizeGB: 64,
ManagedDisk: &ManagedDiskParameters{
StorageAccountType: string(compute.StorageAccountTypesUltraSSDLRS),
},
Lun: to.Int32Ptr(0),
CachingType: string(compute.CachingTypesNone),
},
},
wantErr: false,
},
{
name: "invalid combination of managed disk storage account type UltraSSD_LRS and cachingType ReadWrite",
disks: []DataDisk{
{
NameSuffix: "my_disk_1",
DiskSizeGB: 64,
ManagedDisk: &ManagedDiskParameters{
StorageAccountType: string(compute.StorageAccountTypesUltraSSDLRS),
},
Lun: to.Int32Ptr(0),
CachingType: string(compute.CachingTypesReadWrite),
},
},
wantErr: true,
},
{
name: "invalid combination of managed disk storage account type UltraSSD_LRS and cachingType ReadOnly",
disks: []DataDisk{
{
NameSuffix: "my_disk_1",
DiskSizeGB: 64,
ManagedDisk: &ManagedDiskParameters{
StorageAccountType: string(compute.StorageAccountTypesUltraSSDLRS),
},
Lun: to.Int32Ptr(0),
CachingType: string(compute.CachingTypesReadOnly),
},
},
wantErr: true,
},
}

for _, test := range testcases {
Expand Down
2 changes: 2 additions & 0 deletions docs/book/src/topics/data-disks.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ az vm list-skus -l <location> -z -s <VM-size>

Provided that the chosen region and zone support Ultra disks, Azure Machine objects having Ultra disks specified as Data disks will have their virtual machines created with the `AdditionalCapabilities.UltraSSDEnabled` additional capability set to `true`. This capability can also be manually set on the Azure Machine spec and will override the automatically chosen value (if any).

When the chosen StorageAccountType is `UltraSSD_LRS`, caching is not supported for the disk and the corresponding `cachingType` field must be set to `None`. In this configuration, if no value is set, `cachingType` will be defaulted to `None`.

See [Ultra disk](https://docs.microsoft.com/en-us/azure/virtual-machines/disks-types#ultra-disk) for ultra disk performance and GA scope.

### Ultra disk support for Persistent Volumes
Expand Down