-
Notifications
You must be signed in to change notification settings - Fork 1.5k
SPLAT-2295: Setup additional disks via machine configs #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
Merged
openshift-merge-bot
merged 2 commits into
openshift:main
from
jcpowermac:azure-multi-disk
Jul 29, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.