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
117 changes: 117 additions & 0 deletions data/data/install.openshift.io_installconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,45 @@ spec:
- ""
- amd64
type: string
diskSetup:
description: |-
DiskSetup stores the type of disks that will be setup with MachineConfigs.
The available types are etcd, swap and user-defined.
items:
description: |-
Disk defines the type of disk (etcd, swap or user-defined) and the configuration
of each disk type.
properties:
etcd:
description: DiskEtcd defines a disk type of etcd.
properties:
platformDiskID:
type: string
type: object
swap:
description: DiskSwap defines a disk type of swap.
properties:
platformDiskID:
type: string
type: object
type:
description: DiskType is the string representation of the three
types disk setups
enum:
- etcd
- swap
- user-defined
type: string
userDefined:
description: DiskUserDefined defines a disk type of user-defined.
properties:
mountPath:
type: string
platformDiskID:
type: string
type: object
type: object
type: array
fencing:
description: |-
Fencing stores the information about a baremetal host's management controller.
Expand Down Expand Up @@ -1458,6 +1497,45 @@ spec:
- ""
- amd64
type: string
diskSetup:
description: |-
DiskSetup stores the type of disks that will be setup with MachineConfigs.
The available types are etcd, swap and user-defined.
items:
description: |-
Disk defines the type of disk (etcd, swap or user-defined) and the configuration
of each disk type.
properties:
etcd:
description: DiskEtcd defines a disk type of etcd.
properties:
platformDiskID:
type: string
type: object
swap:
description: DiskSwap defines a disk type of swap.
properties:
platformDiskID:
type: string
type: object
type:
description: DiskType is the string representation of the
three types disk setups
enum:
- etcd
- swap
- user-defined
type: string
userDefined:
description: DiskUserDefined defines a disk type of user-defined.
properties:
mountPath:
type: string
platformDiskID:
type: string
type: object
type: object
type: array
fencing:
description: |-
Fencing stores the information about a baremetal host's management controller.
Expand Down Expand Up @@ -2799,6 +2877,45 @@ spec:
- ""
- amd64
type: string
diskSetup:
description: |-
DiskSetup stores the type of disks that will be setup with MachineConfigs.
The available types are etcd, swap and user-defined.
items:
description: |-
Disk defines the type of disk (etcd, swap or user-defined) and the configuration
of each disk type.
properties:
etcd:
description: DiskEtcd defines a disk type of etcd.
properties:
platformDiskID:
type: string
type: object
swap:
description: DiskSwap defines a disk type of swap.
properties:
platformDiskID:
type: string
type: object
type:
description: DiskType is the string representation of the three
types disk setups
enum:
- etcd
- swap
- user-defined
type: string
userDefined:
description: DiskUserDefined defines a disk type of user-defined.
properties:
mountPath:
type: string
platformDiskID:
type: string
type: object
type: object
type: array
fencing:
description: |-
Fencing stores the information about a baremetal host's management controller.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ require (
github.com/nutanix-cloud-native/cluster-api-provider-nutanix v1.5.4-0.20250116153252-296a5347104c
github.com/nutanix-cloud-native/prism-go-client v0.5.0
github.com/onsi/gomega v1.36.2
github.com/openshift/api v0.0.0-20250527072845-f5e205b58365
github.com/openshift/api v0.0.0-20250704153732-ad766c4e6d8e
github.com/openshift/assisted-image-service v0.0.0-20240607085136-02df2e56dde6
github.com/openshift/assisted-service/api v0.0.0
github.com/openshift/assisted-service/client v0.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQ
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk=
github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/openshift/api v0.0.0-20250527072845-f5e205b58365 h1:WfJTorFO5mJP6DLhK84K83TWuSqmeC3jCN436stKRZk=
github.com/openshift/api v0.0.0-20250527072845-f5e205b58365/go.mod h1:yk60tHAmHhtVpJQo3TwVYq2zpuP70iJIFDCmeKMIzPw=
github.com/openshift/api v0.0.0-20250704153732-ad766c4e6d8e h1:9hzClGu+YAziWP6X93S/To86Q6P8aIfAeasl7zIPYA8=
github.com/openshift/api v0.0.0-20250704153732-ad766c4e6d8e/go.mod h1:yk60tHAmHhtVpJQo3TwVYq2zpuP70iJIFDCmeKMIzPw=
github.com/openshift/assisted-image-service v0.0.0-20240607085136-02df2e56dde6 h1:U6ve+dnHlHhAELoxX+rdFOHVhoaYl0l9qtxwYtsO6C0=
github.com/openshift/assisted-image-service v0.0.0-20240607085136-02df2e56dde6/go.mod h1:o2H5VwQhUD8P6XsK6dRmKpCCJqVvv12KJQZBXmcCXCU=
github.com/openshift/assisted-service v1.0.10-0.20230830164851-6573b5d7021d h1:CKw2Y4EdaFsMoqAdr2Tq0nlYTaaXmCRdP0gOu7pN64U=
Expand Down
173 changes: 173 additions & 0 deletions pkg/asset/machines/machineconfig/disks.go
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 when you have a moment can you review this? I have tested this quite a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pablintino if you have a moment I would like your opinion as well, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Just looking at the MC generation and configs, they make sense to me. If there's any edge cases or concerns around the specific partition schema I think we can check with the coreos team.

Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package machineconfig

import (
"bytes"
"fmt"
"regexp"
"strings"
"text/template"

igntypes "github.com/coreos/ignition/v2/config/v3_2/types"
Copy link
Contributor

Choose a reason for hiding this comment

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

this does remind me we should probably update the installer ignition default type (MCO is using 3.5)

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/ptr"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
"github.com/openshift/installer/pkg/asset/ignition"
"github.com/openshift/installer/pkg/types"
)

// DiskMountUnit is used to supply the template the proper fields to produce the unit string.
type diskMount struct {
MountPath string
Label string
}

const diskMountUnit = `
[Unit]
Requires=systemd-fsck@dev-disk-by\x2dpartlabel-{{.Label}}.service
After=systemd-fsck@dev-disk-by\x2dpartlabel-{{.Label}}.service

[Mount]
Where={{.MountPath}}
What=/dev/disk/by-partlabel/{{.Label}}
Type=xfs
Options=defaults,prjquota

[Install]
RequiredBy=local-fs.target
`

const swapMountUnit = `
[Swap]
What=/dev/disk/by-partlabel/{{.Label}}

[Install]
WantedBy=swap.target
`

const gptSwap = "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F"

// ForDiskSetup generates a machine config for the three disk setup types, etcd, swap or user-defined.
func ForDiskSetup(role, device, label, path string, diskType types.DiskType) (*mcfgv1.MachineConfig, error) {
ignConfig := igntypes.Config{
Ignition: igntypes.Ignition{
Version: igntypes.MaxVersion.String(),
},
}

// Remove all non-alphanumeric characters from the label
reg := regexp.MustCompile(`[^a-zA-Z0-9]+`)
label = reg.ReplaceAllString(label, "")

mountUnit := diskMount{
MountPath: path,
Label: label,
}

var templateStringToParse string
switch diskType {
case types.Etcd, types.UserDefined:
templateStringToParse = diskMountUnit
case types.Swap:
templateStringToParse = swapMountUnit
}

diskMountUnitTemplate, err := template.New("mountUnit").Parse(templateStringToParse)
if err != nil {
return nil, err
}

var dmu bytes.Buffer
err = diskMountUnitTemplate.Execute(&dmu, mountUnit)
if err != nil {
return nil, err
}

units := dmu.String()

var rawExt runtime.RawExtension
switch diskType {
case types.Etcd, types.UserDefined:
rawExt, err = getDiskIgnition(ignConfig, device, label, path, units)
if err != nil {
return nil, err
}
case types.Swap:
rawExt, err = getSwapIgnition(ignConfig, device, label, units)
if err != nil {
return nil, err
}
}

return &mcfgv1.MachineConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: mcfgv1.SchemeGroupVersion.String(),
Kind: "MachineConfig",
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("01-disk-setup-%s-%s", label, role),
Labels: map[string]string{
"machineconfiguration.openshift.io/role": role,
},
},
Spec: mcfgv1.MachineConfigSpec{
Config: rawExt,
},
}, nil
}
func getDiskIgnition(ignConfig igntypes.Config, device, label, path, units string) (runtime.RawExtension, error) {
unitName := strings.Trim(path, "/")
unitName = strings.ReplaceAll(unitName, "/", "-")

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

ignConfig.Storage.Filesystems = append(ignConfig.Storage.Filesystems, igntypes.Filesystem{
Device: fmt.Sprintf("/dev/disk/by-partlabel/%s", label),
Format: ptr.To("xfs"),
Label: ptr.To(label),
MountOptions: []igntypes.MountOption{"defaults", "prjquota"},
Path: ptr.To(path),
WipeFilesystem: ptr.To(true),
})
ignConfig.Systemd.Units = append(ignConfig.Systemd.Units, igntypes.Unit{
Name: fmt.Sprintf("%s.mount", unitName),
Enabled: ptr.To(true),
Contents: &units,
})
return ignition.ConvertToRawExtension(ignConfig)
}

func getSwapIgnition(ignConfig igntypes.Config, device, label, units string) (runtime.RawExtension, error) {
unitName := "dev-disk-by\\x2dpartlabel-swap.swap"
ignConfig.Storage.Disks = append(ignConfig.Storage.Disks, igntypes.Disk{
Device: device,
Partitions: []igntypes.Partition{{
Label: ptr.To(label),
StartMiB: ptr.To(0),
SizeMiB: ptr.To(0),
GUID: ptr.To(gptSwap),
}},
WipeTable: ptr.To(true),
})

ignConfig.Storage.Filesystems = append(ignConfig.Storage.Filesystems, igntypes.Filesystem{
Device: fmt.Sprintf("/dev/disk/by-partlabel/%s", label),
Format: ptr.To("swap"),
Label: ptr.To(label),
})
ignConfig.Systemd.Units = append(ignConfig.Systemd.Units, igntypes.Unit{
Name: unitName,
Enabled: ptr.To(true),
Contents: &units,
})
return ignition.ConvertToRawExtension(ignConfig)
}
Loading