Skip to content

Commit 5493e53

Browse files
authored
Merge pull request #4928 from helio/diffdiskplacement
feat: support OSDisk.DiffDiskPlacement
2 parents 39ee175 + e9bc86d commit 5493e53

17 files changed

+331
-4
lines changed

api/v1beta1/azuremachine_validation.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ func ValidateOSDisk(osDisk OSDisk, fieldPath *field.Path) field.ErrorList {
248248
"diskEncryptionSet is not supported when diffDiskSettings.option is 'Local'",
249249
))
250250
}
251+
if osDisk.DiffDiskSettings != nil && osDisk.DiffDiskSettings.Placement != nil {
252+
if osDisk.DiffDiskSettings.Option != string(armcompute.DiffDiskOptionsLocal) {
253+
allErrs = append(allErrs, field.Invalid(
254+
fieldPath.Child("diffDiskSettings"),
255+
osDisk.DiffDiskSettings,
256+
"placement is only supported when diffDiskSettings.option is 'Local'",
257+
))
258+
}
259+
}
251260

252261
return allErrs
253262
}

api/v1beta1/azuremachine_validation_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,37 @@ func TestAzureMachine_ValidateOSDisk(t *testing.T) {
109109
},
110110
},
111111
},
112+
{
113+
name: "valid resourceDisk placement spec with option local",
114+
wantErr: false,
115+
osDisk: OSDisk{
116+
DiskSizeGB: ptr.To[int32](30),
117+
CachingType: "None",
118+
OSType: "blah",
119+
DiffDiskSettings: &DiffDiskSettings{
120+
Option: string(armcompute.DiffDiskOptionsLocal),
121+
Placement: ptr.To(DiffDiskPlacementResourceDisk),
122+
},
123+
ManagedDisk: &ManagedDiskParameters{
124+
StorageAccountType: "Standard_LRS",
125+
},
126+
},
127+
},
128+
{
129+
name: "valid resourceDisk placement spec requires option local",
130+
wantErr: true,
131+
osDisk: OSDisk{
132+
DiskSizeGB: ptr.To[int32](30),
133+
CachingType: "None",
134+
OSType: "blah",
135+
DiffDiskSettings: &DiffDiskSettings{
136+
Placement: ptr.To(DiffDiskPlacementResourceDisk),
137+
},
138+
ManagedDisk: &ManagedDiskParameters{
139+
StorageAccountType: "Standard_LRS",
140+
},
141+
},
142+
},
112143
{
113144
name: "byoc encryption with ephemeral os disk spec",
114145
wantErr: true,

api/v1beta1/types.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,45 @@ type DiskEncryptionSetParameters struct {
687687
ID string `json:"id,omitempty"`
688688
}
689689

690+
// DiffDiskPlacement - Specifies the ephemeral disk placement for operating system disk. This property can be used by user
691+
// in the request to choose the location i.e, cache disk, resource disk or nvme disk space for
692+
// Ephemeral OS disk provisioning. For more information on Ephemeral OS disk size requirements, please refer Ephemeral OS
693+
// disk size requirements for Windows VM at
694+
// https://docs.microsoft.com/azure/virtual-machines/windows/ephemeral-os-disks#size-requirements and Linux VM at
695+
// https://docs.microsoft.com/azure/virtual-machines/linux/ephemeral-os-disks#size-requirements.
696+
type DiffDiskPlacement string
697+
698+
const (
699+
// DiffDiskPlacementCacheDisk places the OsDisk on cache disk.
700+
DiffDiskPlacementCacheDisk DiffDiskPlacement = "CacheDisk"
701+
702+
// DiffDiskPlacementNvmeDisk places the OsDisk on NVMe disk.
703+
DiffDiskPlacementNvmeDisk DiffDiskPlacement = "NvmeDisk"
704+
705+
// DiffDiskPlacementResourceDisk places the OsDisk on temp disk.
706+
DiffDiskPlacementResourceDisk DiffDiskPlacement = "ResourceDisk"
707+
)
708+
709+
// PossibleDiffDiskPlacementValues returns the possible values for the DiffDiskPlacement const type.
710+
func PossibleDiffDiskPlacementValues() []DiffDiskPlacement {
711+
return []DiffDiskPlacement{
712+
DiffDiskPlacementCacheDisk,
713+
DiffDiskPlacementNvmeDisk,
714+
DiffDiskPlacementResourceDisk,
715+
}
716+
}
717+
690718
// DiffDiskSettings describe ephemeral disk settings for the os disk.
691719
type DiffDiskSettings struct {
692720
// Option enables ephemeral OS when set to "Local"
693721
// See https://learn.microsoft.com/azure/virtual-machines/ephemeral-os-disks for full details
694722
// +kubebuilder:validation:Enum=Local
695723
Option string `json:"option"`
724+
725+
// Placement specifies the ephemeral disk placement for operating system disk. If placement is specified, Option must be set to "Local".
726+
// +kubebuilder:validation:Enum=CacheDisk;NvmeDisk;ResourceDisk
727+
// +optional
728+
Placement *DiffDiskPlacement `json:"placement,omitempty"`
696729
}
697730

698731
// SubnetRole defines the unique role of a subnet.

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

azure/converters/spotinstances_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ func TestGetSpotVMOptions(t *testing.T) {
9393
billingProfile: nil,
9494
},
9595
},
96+
{
97+
name: "spot with ResourceDisk",
98+
spot: &infrav1.SpotVMOptions{
99+
MaxPrice: nil,
100+
},
101+
diffDiskSettings: &infrav1.DiffDiskSettings{
102+
Option: string(armcompute.DiffDiskOptionsLocal),
103+
Placement: ptr.To(infrav1.DiffDiskPlacementResourceDisk),
104+
},
105+
want: resultParams{
106+
vmPriorityTypes: ptr.To(armcompute.VirtualMachinePriorityTypesSpot),
107+
vmEvictionPolicyTypes: nil,
108+
billingProfile: nil,
109+
},
110+
},
96111
{
97112
name: "spot with eviction policy",
98113
spot: &infrav1.SpotVMOptions{

azure/services/scalesets/spec.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ func (s *ScaleSetSpec) generateStorageProfile(ctx context.Context) (*armcompute.
391391
storageProfile.OSDisk.DiffDiskSettings = &armcompute.DiffDiskSettings{
392392
Option: ptr.To(armcompute.DiffDiskOptions(s.OSDisk.DiffDiskSettings.Option)),
393393
}
394+
395+
if s.OSDisk.DiffDiskSettings.Placement != nil {
396+
storageProfile.OSDisk.DiffDiskSettings.Placement = ptr.To(armcompute.DiffDiskPlacement(*s.OSDisk.DiffDiskSettings.Placement))
397+
}
394398
}
395399

396400
if s.OSDisk.ManagedDisk != nil {

azure/services/scalesets/spec_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939
customNetworkingSpec, customNetworkingVMSS = getCustomNetworkingVMSS()
4040
spotVMSpec, spotVMVMSS = getSpotVMVMSS()
4141
ephemeralSpec, ephemeralVMSS = getEPHVMSSS()
42+
resourceDiskSpec, resourceDiskVMSS = getResourceDiskVMSS()
4243
evictionSpec, evictionVMSS = getEvictionPolicyVMSS()
4344
maxPriceSpec, maxPriceVMSS = getMaxPriceVMSS()
4445
encryptionSpec, encryptionVMSS = getEncryptionVMSS()
@@ -233,6 +234,32 @@ func getEPHVMSSS() (ScaleSetSpec, armcompute.VirtualMachineScaleSet) {
233234
return spec, vmss
234235
}
235236

237+
func getResourceDiskVMSS() (ScaleSetSpec, armcompute.VirtualMachineScaleSet) {
238+
spec := newDefaultVMSSSpec()
239+
spec.Size = vmSizeEPH
240+
spec.SKU = resourceskus.SKU{
241+
Capabilities: []*armcompute.ResourceSKUCapabilities{
242+
{
243+
Name: ptr.To(resourceskus.EphemeralOSDisk),
244+
Value: ptr.To("True"),
245+
},
246+
},
247+
}
248+
spec.SpotVMOptions = &infrav1.SpotVMOptions{}
249+
spec.OSDisk.DiffDiskSettings = &infrav1.DiffDiskSettings{
250+
Option: string(armcompute.DiffDiskOptionsLocal),
251+
Placement: ptr.To(infrav1.DiffDiskPlacementResourceDisk),
252+
}
253+
vmss := newDefaultVMSS(vmSizeEPH)
254+
vmss.Properties.VirtualMachineProfile.StorageProfile.OSDisk.DiffDiskSettings = &armcompute.DiffDiskSettings{
255+
Option: ptr.To(armcompute.DiffDiskOptionsLocal),
256+
Placement: ptr.To(armcompute.DiffDiskPlacementResourceDisk),
257+
}
258+
vmss.Properties.VirtualMachineProfile.Priority = ptr.To(armcompute.VirtualMachinePriorityTypesSpot)
259+
260+
return spec, vmss
261+
}
262+
236263
func getEvictionPolicyVMSS() (ScaleSetSpec, armcompute.VirtualMachineScaleSet) {
237264
spec := newDefaultVMSSSpec()
238265
spec.Size = vmSizeEPH
@@ -586,6 +613,13 @@ func TestScaleSetParameters(t *testing.T) {
586613
expected: ephemeralVMSS,
587614
expectedError: "",
588615
},
616+
{
617+
name: "spot vm and ephemeral disk with resourceDisk placement vmss",
618+
spec: resourceDiskSpec,
619+
existing: nil,
620+
expected: resourceDiskVMSS,
621+
expectedError: "",
622+
},
589623
{
590624
name: "spot vm and eviction policy vmss",
591625
spec: evictionSpec,

azure/services/virtualmachines/spec.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func (s *VMSpec) generateStorageProfile() (*armcompute.StorageProfile, error) {
183183
if !MemoryCapability {
184184
return nil, azure.WithTerminalError(errors.New("VM memory should be bigger or equal to at least 2Gi"))
185185
}
186+
186187
// enable ephemeral OS
187188
if s.OSDisk.DiffDiskSettings != nil {
188189
if !s.SKU.HasCapability(resourceskus.EphemeralOSDisk) {
@@ -192,6 +193,10 @@ func (s *VMSpec) generateStorageProfile() (*armcompute.StorageProfile, error) {
192193
storageProfile.OSDisk.DiffDiskSettings = &armcompute.DiffDiskSettings{
193194
Option: ptr.To(armcompute.DiffDiskOptions(s.OSDisk.DiffDiskSettings.Option)),
194195
}
196+
197+
if s.OSDisk.DiffDiskSettings.Placement != nil {
198+
storageProfile.OSDisk.DiffDiskSettings.Placement = ptr.To(armcompute.DiffDiskPlacement(*s.OSDisk.DiffDiskSettings.Placement))
199+
}
195200
}
196201

197202
if s.OSDisk.ManagedDisk != nil {

azure/services/virtualmachines/spec_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,35 @@ func TestParameters(t *testing.T) {
461461
},
462462
expectedError: "",
463463
},
464+
{
465+
name: "can create a vm with DiffDiskPlacement ResourceDisk",
466+
spec: &VMSpec{
467+
Name: "my-vm",
468+
Role: infrav1.Node,
469+
NICIDs: []string{"my-nic"},
470+
SSHKeyData: "fakesshpublickey",
471+
Size: "Standard_D2v3",
472+
OSDisk: infrav1.OSDisk{
473+
OSType: "Linux",
474+
DiskSizeGB: ptr.To[int32](128),
475+
ManagedDisk: &infrav1.ManagedDiskParameters{
476+
StorageAccountType: string(armcompute.StorageAccountTypesPremiumLRS),
477+
},
478+
DiffDiskSettings: &infrav1.DiffDiskSettings{
479+
Option: string(armcompute.DiffDiskOptionsLocal),
480+
Placement: ptr.To(infrav1.DiffDiskPlacementResourceDisk),
481+
},
482+
},
483+
Image: &infrav1.Image{ID: ptr.To("fake-image-id")},
484+
SKU: validSKUWithEphemeralOS,
485+
},
486+
existing: nil,
487+
expect: func(g *WithT, result interface{}) {
488+
g.Expect(result).To(BeAssignableToTypeOf(armcompute.VirtualMachine{}))
489+
g.Expect(result.(armcompute.VirtualMachine).Properties.StorageProfile.OSDisk.DiffDiskSettings.Placement).To(Equal(ptr.To(armcompute.DiffDiskPlacementResourceDisk)))
490+
},
491+
expectedError: "",
492+
},
464493
{
465494
name: "can create a trusted launch vm",
466495
spec: &VMSpec{

config/crd/bases/infrastructure.cluster.x-k8s.io_azuremachinepools.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,15 @@ spec:
578578
enum:
579579
- Local
580580
type: string
581+
placement:
582+
description: Placement specifies the ephemeral disk placement
583+
for operating system disk. If placement is specified,
584+
Option must be set to "Local".
585+
enum:
586+
- CacheDisk
587+
- NvmeDisk
588+
- ResourceDisk
589+
type: string
581590
required:
582591
- option
583592
type: object

0 commit comments

Comments
 (0)