Skip to content

Commit d5bcf21

Browse files
authored
Merge pull request #2430 from damdo/fix-data-disk-ultrassd-w-caching-option
fix: validation of caching options for Ultra disks as data disks
2 parents 9ecbfd4 + 69152d4 commit d5bcf21

File tree

5 files changed

+80
-4
lines changed

5 files changed

+80
-4
lines changed

api/v1beta1/azuremachine_default.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"encoding/base64"
2121

22+
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
2223
"golang.org/x/crypto/ssh"
2324
"k8s.io/apimachinery/pkg/util/uuid"
2425
utilSSH "sigs.k8s.io/cluster-api-provider-azure/util/ssh"
@@ -67,7 +68,12 @@ func (s *AzureMachineSpec) SetDataDisksDefaults() {
6768
}
6869
}
6970
if disk.CachingType == "" {
70-
s.DataDisks[i].CachingType = "ReadWrite"
71+
if s.DataDisks[i].ManagedDisk != nil &&
72+
s.DataDisks[i].ManagedDisk.StorageAccountType == string(compute.StorageAccountTypesUltraSSDLRS) {
73+
s.DataDisks[i].CachingType = string(compute.CachingTypesNone)
74+
} else {
75+
s.DataDisks[i].CachingType = string(compute.CachingTypesReadWrite)
76+
}
7177
}
7278
}
7379
}

api/v1beta1/azuremachine_default_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) {
215215
DiskSizeGB: 30,
216216
Lun: to.Int32Ptr(2),
217217
},
218+
{
219+
NameSuffix: "testdisk3",
220+
DiskSizeGB: 30,
221+
ManagedDisk: &ManagedDiskParameters{
222+
StorageAccountType: "UltraSSD_LRS",
223+
},
224+
Lun: to.Int32Ptr(3),
225+
},
218226
},
219227
output: []DataDisk{
220228
{
@@ -229,6 +237,15 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) {
229237
Lun: to.Int32Ptr(2),
230238
CachingType: "ReadWrite",
231239
},
240+
{
241+
NameSuffix: "testdisk3",
242+
DiskSizeGB: 30,
243+
Lun: to.Int32Ptr(3),
244+
ManagedDisk: &ManagedDiskParameters{
245+
StorageAccountType: "UltraSSD_LRS",
246+
},
247+
CachingType: "None",
248+
},
232249
},
233250
},
234251
}

api/v1beta1/azuremachine_validation.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func ValidateDataDisks(dataDisks []DataDisk, fieldPath *field.Path) field.ErrorL
143143
}
144144

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

165-
allErrs = append(allErrs, validateCachingType(osDisk.CachingType, fieldPath)...)
165+
allErrs = append(allErrs, validateCachingType(osDisk.CachingType, fieldPath, osDisk.ManagedDisk)...)
166166

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

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

285+
if managedDisk != nil && managedDisk.StorageAccountType == string(compute.StorageAccountTypesUltraSSDLRS) {
286+
if cachingType != string(compute.CachingTypesNone) {
287+
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)))
288+
}
289+
}
290+
285291
for _, possibleCachingType := range compute.PossibleCachingTypesValues() {
286292
if string(possibleCachingType) == cachingType {
287293
return allErrs

api/v1beta1/azuremachine_validation_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,51 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) {
385385
},
386386
wantErr: true,
387387
},
388+
{
389+
name: "valid combination of managed disk storage account type UltraSSD_LRS and cachingType None",
390+
disks: []DataDisk{
391+
{
392+
NameSuffix: "my_disk_1",
393+
DiskSizeGB: 64,
394+
ManagedDisk: &ManagedDiskParameters{
395+
StorageAccountType: string(compute.StorageAccountTypesUltraSSDLRS),
396+
},
397+
Lun: to.Int32Ptr(0),
398+
CachingType: string(compute.CachingTypesNone),
399+
},
400+
},
401+
wantErr: false,
402+
},
403+
{
404+
name: "invalid combination of managed disk storage account type UltraSSD_LRS and cachingType ReadWrite",
405+
disks: []DataDisk{
406+
{
407+
NameSuffix: "my_disk_1",
408+
DiskSizeGB: 64,
409+
ManagedDisk: &ManagedDiskParameters{
410+
StorageAccountType: string(compute.StorageAccountTypesUltraSSDLRS),
411+
},
412+
Lun: to.Int32Ptr(0),
413+
CachingType: string(compute.CachingTypesReadWrite),
414+
},
415+
},
416+
wantErr: true,
417+
},
418+
{
419+
name: "invalid combination of managed disk storage account type UltraSSD_LRS and cachingType ReadOnly",
420+
disks: []DataDisk{
421+
{
422+
NameSuffix: "my_disk_1",
423+
DiskSizeGB: 64,
424+
ManagedDisk: &ManagedDiskParameters{
425+
StorageAccountType: string(compute.StorageAccountTypesUltraSSDLRS),
426+
},
427+
Lun: to.Int32Ptr(0),
428+
CachingType: string(compute.CachingTypesReadOnly),
429+
},
430+
},
431+
wantErr: true,
432+
},
388433
}
389434

390435
for _, test := range testcases {

docs/book/src/topics/data-disks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ az vm list-skus -l <location> -z -s <VM-size>
3434

3535
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).
3636

37+
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`.
38+
3739
See [Ultra disk](https://docs.microsoft.com/en-us/azure/virtual-machines/disks-types#ultra-disk) for ultra disk performance and GA scope.
3840

3941
### Ultra disk support for Persistent Volumes

0 commit comments

Comments
 (0)