Skip to content
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
16 changes: 4 additions & 12 deletions pkg/asset/machines/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,18 +625,10 @@ func (m *Master) Generate(ctx context.Context, dependencies asset.Parents) error
if installConfig.Config.Enabled(features.FeatureGateMultiDiskSetup) {
for i, diskSetup := range installConfig.Config.ControlPlane.DiskSetup {
var dataDisk any
var diskName string

switch diskSetup.Type {
case types.Etcd:
diskName = diskSetup.Etcd.PlatformDiskID
case types.Swap:
diskName = diskSetup.Etcd.PlatformDiskID
case types.UserDefined:
diskName = diskSetup.UserDefined.PlatformDiskID
default:
// We shouldn't get here, but just in case
return errors.Errorf("disk setup type %s is not supported", diskSetup.Type)

diskName, err := DiskName(diskSetup)
if err != nil {
return err
}

switch ic.Platform.Name() {
Expand Down
14 changes: 14 additions & 0 deletions pkg/asset/machines/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ const (
VsphereScsiByPath = "/dev/disk/by-path/pci-0000:03:00.0-scsi-0:0:%d:0"
)

// DiskName returns the platform disk ID for the given disk setup entry.
func DiskName(diskSetup types.Disk) (string, error) {
switch diskSetup.Type {
case types.Etcd:
return diskSetup.Etcd.PlatformDiskID, nil
case types.Swap:
return diskSetup.Swap.PlatformDiskID, nil
case types.UserDefined:
return diskSetup.UserDefined.PlatformDiskID, nil
default:
return "", errors.Errorf("disk setup type %s is not supported", diskSetup.Type)
}
}

// NodeDiskSetup determines the path per disk type, and per platform and role, runs ForDiskSetup.
func NodeDiskSetup(installConfig *installconfig.InstallConfig, role string, diskSetup types.Disk, dataDisk any) (*v1.MachineConfig, error) {
var path string
Expand Down
16 changes: 4 additions & 12 deletions pkg/asset/machines/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,10 @@ func (w *Worker) Generate(ctx context.Context, dependencies asset.Parents) error
if installConfig.Config.Enabled(features.FeatureGateMultiDiskSetup) {
for i, diskSetup := range pool.DiskSetup {
var dataDisk any
var diskName string

switch diskSetup.Type {
case types.Etcd:
diskName = diskSetup.Etcd.PlatformDiskID
case types.Swap:
diskName = diskSetup.Etcd.PlatformDiskID
case types.UserDefined:
diskName = diskSetup.UserDefined.PlatformDiskID
default:
// We shouldn't get here, but just in case
return errors.Errorf("disk setup type %s is not supported", diskSetup.Type)

diskName, err := DiskName(diskSetup)
if err != nil {
return err
}

switch ic.Platform.Name() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/types/validation/machinepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func validateDiskSetup(p *types.MachinePool, fldPath *field.Path) field.ErrorLis
}
foundEtcd = true
case types.Swap:
if p.Name == "master" {
allErrs = append(allErrs, field.Invalid(fldPath.Child("swap"), dsYaml, "swap is unsupported on control plane nodes"))
continue
}
if foundSwap {
allErrs = append(allErrs, field.TooMany(fldPath.Child("swap"), 2, 1))
continue
Expand Down
16 changes: 16 additions & 0 deletions pkg/types/validation/machinepools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,22 @@ func TestValidateMachinePool(t *testing.T) {
}(),
expectedError: `^test-path\.diskSetup\.etcd: Invalid value: "type: etcd\\n": etcd configuration must be created$`,
},
{
name: "invalid swap disk on master machine pool",
platform: &types.Platform{Azure: &azure.Platform{Region: "eastus"}},
pool: func() *types.MachinePool {
p := validMachinePool("master")
p.DiskSetup = append(p.DiskSetup, types.Disk{
Type: "swap",
Swap: &types.DiskSwap{PlatformDiskID: "swap"},
})
p.Platform = types.MachinePoolPlatform{
Azure: &azure.MachinePool{},
}
return p
}(),
expectedError: `^test-path\.diskSetup\.swap: Invalid value: "swap:\\n platformDiskID: swap\\ntype: swap\\n": swap is unsupported on control plane nodes$`,
},
{
name: "valid swap disk",
platform: &types.Platform{Azure: &azure.Platform{Region: "eastus"}},
Expand Down