Skip to content

[wip] Azure multi disk #9706

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
58 changes: 58 additions & 0 deletions pkg/asset/ignition/machine/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package machine
import (
"context"
"encoding/json"
"fmt"
"os"

igntypes "github.com/coreos/ignition/v2/config/v3_2/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/utils/ptr"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/ignition"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/tls"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/azure"
)

Expand Down Expand Up @@ -50,6 +53,22 @@ func (a *Master) Generate(_ context.Context, dependencies asset.Parents) error {
ignition.AppendVarPartition(a.Config)
}

if installConfig.Config.ControlPlane != nil {
for i, d := range installConfig.Config.ControlPlane.DiskSetup {
if d.Type == types.Etcd {

// platform specific...
if installConfig.Config.ControlPlane.Platform.Azure != nil {
azurePlatform := installConfig.Config.ControlPlane.Platform.Azure
if d.Etcd.PlatformDiskID == azurePlatform.DataDisks[i].NameSuffix {
device := fmt.Sprintf("/dev/disk/azure/scsi1/lun%d", *azurePlatform.DataDisks[i].Lun)
AddEtcdDisk(a.Config, device)
}
}
}
}
}

data, err := ignition.Marshal(a.Config)
if err != nil {
return errors.Wrap(err, "failed to marshal Ignition config")
Expand Down Expand Up @@ -93,3 +112,42 @@ func (a *Master) Load(f asset.FileFetcher) (found bool, err error) {
a.File, a.Config = file, config
return true, nil
}

func AddEtcdDisk(config *igntypes.Config, device string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yuqi-zhang @patrickdillon suggested that I get your opinion on these changes. When you have a moment can you take a look?

We are starting an enhancement too but it isn't ready for a PR just yet.

config.Storage.Disks = append(config.Storage.Disks, igntypes.Disk{
Device: device,
Partitions: []igntypes.Partition{{
Label: ptr.To("etcddisk"),
StartMiB: ptr.To(0),
SizeMiB: ptr.To(0),
}},
WipeTable: ptr.To(true),
})

config.Storage.Filesystems = append(config.Storage.Filesystems, igntypes.Filesystem{
Device: "/dev/disk/by-partlabel/etcddisk",
Format: ptr.To("xfs"),
Label: ptr.To("etcdpart"),
MountOptions: []igntypes.MountOption{"defaults", "prjquota"},
Path: ptr.To("/var/lib/etcd"),
WipeFilesystem: ptr.To(true),
})
config.Systemd.Units = append(config.Systemd.Units, igntypes.Unit{
Name: "var-lib-etcd.mount",
Enabled: ptr.To(true),
Contents: ptr.To(`
[Unit]
Requires=systemd-fsck@dev-disk-by\x2dpartlabel-var.service
After=systemd-fsck@dev-disk-by\x2dpartlabel-var.service

[Mount]
Where=/var/lib/etcd
What=/dev/disk/by-partlabel/etcddisk
Type=xfs
Options=defaults,prjquota

[Install]
RequiredBy=local-fs.target
`),
})
}
1 change: 1 addition & 0 deletions pkg/asset/machines/azure/azuremachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func GenerateMachines(clusterID, resourceGroup, subscriptionID string, session *
Identity: mpool.Identity.Type,
UserAssignedIdentities: userAssignedIdentities,
Diagnostics: controlPlaneDiag,
DataDisks: mpool.DataDisks,
},
}

Expand Down
33 changes: 33 additions & 0 deletions pkg/asset/machines/azure/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,38 @@ func provider(platform *azure.Platform, mpool *azure.MachinePool, osImage string

ultraSSDCapability := machineapi.AzureUltraSSDCapabilityState(mpool.UltraSSDCapability)

//dataDisks := make([]machineapi.DataDisk, len(mpool.DataDisks))

var dataDisks []machineapi.DataDisk

for _, disk := range mpool.DataDisks {
dataDisk := machineapi.DataDisk{
NameSuffix: disk.NameSuffix,
DiskSizeGB: disk.DiskSizeGB,
CachingType: machineapi.CachingTypeOption(disk.CachingType),

// TODO: jcallen ** WARNING ** does this make sense to force delete?
// TODO: jcallen why does mapi have this and capz does not?
DeletionPolicy: machineapi.DiskDeletionPolicyTypeDelete,
}

if disk.Lun != nil {
dataDisk.Lun = *disk.Lun
}

if disk.ManagedDisk != nil {
dataDisk.ManagedDisk = machineapi.DataDiskManagedDiskParameters{
StorageAccountType: machineapi.StorageAccountType(disk.ManagedDisk.StorageAccountType),
}

if disk.ManagedDisk.DiskEncryptionSet != nil {
dataDisk.ManagedDisk.DiskEncryptionSet = (*machineapi.DiskEncryptionSetParameters)(disk.ManagedDisk.SecurityProfile.DiskEncryptionSet)
}
}

dataDisks = append(dataDisks, dataDisk)
}

spec := &machineapi.AzureMachineProviderSpec{
TypeMeta: metav1.TypeMeta{
APIVersion: "machine.openshift.io/v1beta1",
Expand Down Expand Up @@ -272,6 +304,7 @@ func provider(platform *azure.Platform, mpool *azure.MachinePool, osImage string
PublicLoadBalancer: publicLB,
AcceleratedNetworking: getVMNetworkingType(mpool.VMNetworkingType),
Tags: platform.UserTags,
DataDisks: dataDisks,
}
var bootDiagnostics *machineapi.AzureDiagnostics
if platform.DefaultMachinePlatform != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/types/azure/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ type MachinePool struct {
// +kubebuilder:default=None
// +optional
Identity *VMIdentity `json:"identity,omitempty"`

// DataDisk specifies the parameters that are used to add one or more data disks to the machine.
// +optional
DataDisks []capz.DataDisk `json:"dataDisks,omitempty"`
}

// SecuritySettings define the security type and the UEFI settings of the virtual machine.
Expand Down Expand Up @@ -232,6 +236,10 @@ func (a *MachinePool) Set(required *MachinePool) {
if required.Identity != nil {
a.Identity = required.Identity
}

if required.DataDisks != nil {
a.DataDisks = required.DataDisks
}
}

// ImagePurchasePlan defines the purchase plan of a Marketplace image.
Expand Down
30 changes: 30 additions & 0 deletions pkg/types/machinepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@ const (
ArchitectureARM64 = "arm64"
)

type DiskType string

const (
Etcd DiskType = "etcd"
Swap DiskType = "swap"
UserDefined DiskType = "user-defined"
)

type Disk struct {
Type DiskType `json:"type,omitempty"`

UserDefined *DiskUserDefined `json:"userDefined,omitempty"`
Etcd *DiskEtcd `json:"etcd,omitempty"`
Swap *DiskSwap `json:"swap,omitempty"`
}

type DiskUserDefined struct {
PlatformDiskID string `json:"platformDiskID,omitempty"`
MountPath string `json:"mountPath,omitempty"`
}
type DiskSwap struct {
PlatformDiskID string `json:"platformDiskID,omitempty"`
}
type DiskEtcd struct {
PlatformDiskID string `json:"platformDiskID,omitempty"`
}

// MachinePool is a pool of machines to be installed.
type MachinePool struct {
// Name is the name of the machine pool.
Expand Down Expand Up @@ -83,6 +110,9 @@ type MachinePool struct {
// Fencing may only be set for control plane nodes.
// +optional
Fencing *Fencing `json:"fencing,omitempty"`

// datadisk
DiskSetup []Disk `json:"diskSetup,omitempty"`
}

// MachinePoolPlatform is the platform-specific configuration for a machine
Expand Down