Skip to content

Commit

Permalink
distro/rhel: support new partitioning customizations on RHEL
Browse files Browse the repository at this point in the history
Read the new Partitioning/Disk customizations in the RHEL partition
table generators.
Validate the customizations and check that they're not used at the same
time as FilesystemCustomization.
  • Loading branch information
achilleas-k committed Nov 29, 2024
1 parent 1b4d5e6 commit 7a5d80d
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 18 deletions.
27 changes: 27 additions & 0 deletions pkg/distro/rhel/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ const (
BlueprintPkgsKey = "blueprint"
)

// Default directory size minimums for all image types.
var requiredDirectorySizes = map[string]uint64{
"/": 1 * datasizes.GiB,
"/usr": 2 * datasizes.GiB,
}

type ImageFunc func(workload workload.Workload, t *ImageType, customizations *blueprint.Customizations, options distro.ImageOptions, packageSets map[string]rpmmd.PackageSet, containers []container.SourceSpec, rng *rand.Rand) (image.ImageKind, error)

type PackageSetFunc func(t *ImageType) rpmmd.PackageSet
Expand Down Expand Up @@ -193,6 +199,27 @@ func (t *ImageType) GetPartitionTable(
}

imageSize := t.Size(options.Size)
partitioning, err := customizations.GetPartitioning()
if err != nil {
return nil, err
}
if partitioning != nil {
// Use the new custom partition table to create a PT fully based on the user's customizations.
// This overrides FilesystemCustomizations, but we should never have both defined.
if options.Size > 0 {
// user specified a size on the command line, so let's override the
// customization with the calculated/rounded imageSize
partitioning.MinSize = imageSize
}

partOptions := &disk.CustomPartitionTableOptions{
PartitionTableType: basePartitionTable.Type, // PT type is not customizable, it is determined by the base PT for an image type or architecture
BootMode: t.BootMode(),
DefaultFSType: disk.FS_EXT4, // default fs type for Fedora
RequiredMinSizes: requiredDirectorySizes,
}
return disk.NewCustomPartitionTable(partitioning, partOptions, rng)
}

return disk.NewPartitionTable(&basePartitionTable, customizations.GetFilesystems(), imageSize, options.PartitioningMode, nil, rng)
}
Expand Down
19 changes: 17 additions & 2 deletions pkg/distro/rhel/rhel10/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@ func checkOptions(t *rhel.ImageType, bp *blueprint.Blueprint, options distro.Ima
}

mountpoints := customizations.GetFilesystems()

err := blueprint.CheckMountpointsPolicy(mountpoints, policies.MountpointPolicies)
partitioning, err := customizations.GetPartitioning()
if err != nil {
return nil, err
}

if err := blueprint.CheckMountpointsPolicy(mountpoints, policies.MountpointPolicies); err != nil {
return warnings, err
}

if len(mountpoints) > 0 && partitioning != nil {
return nil, fmt.Errorf("partitioning customizations cannot be used with custom filesystems (mountpoints)")
}

if err := blueprint.CheckDiskMountpointsPolicy(partitioning, policies.MountpointPolicies); err != nil {
return warnings, err
}

if err := partitioning.ValidateLayoutConstraints(); err != nil {
return warnings, err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/distro/rhel/rhel8/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func TestDistro_CustomFileSystemManifestError(t *testing.T) {
imgType, _ := arch.GetImageType(imgTypeName)
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if imgTypeName == "edge-commit" || imgTypeName == "edge-container" {
assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types")
assert.EqualError(t, err, "custom mountpoints and partitioning are not supported for ostree types")
} else if unsupported[imgTypeName] {
assert.Error(t, err)
} else {
Expand Down Expand Up @@ -712,7 +712,7 @@ func TestDistro_TestRootMountPoint(t *testing.T) {
imgType, _ := arch.GetImageType(imgTypeName)
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if imgTypeName == "edge-commit" || imgTypeName == "edge-container" {
assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types")
assert.EqualError(t, err, "custom mountpoints and partitioning are not supported for ostree types")
} else if unsupported[imgTypeName] {
assert.Error(t, err)
} else {
Expand Down Expand Up @@ -872,7 +872,7 @@ func TestDistro_CustomUsrPartitionNotLargeEnough(t *testing.T) {
imgType, _ := arch.GetImageType(imgTypeName)
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if imgTypeName == "edge-commit" || imgTypeName == "edge-container" {
assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types")
assert.EqualError(t, err, "custom mountpoints and partitioning are not supported for ostree types")
} else if unsupported[imgTypeName] {
assert.Error(t, err)
} else {
Expand Down
22 changes: 18 additions & 4 deletions pkg/distro/rhel/rhel8/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,27 @@ func checkOptions(t *rhel.ImageType, bp *blueprint.Blueprint, options distro.Ima
}

mountpoints := customizations.GetFilesystems()
partitioning, err := customizations.GetPartitioning()
if err != nil {
return nil, err
}
if len(mountpoints) > 0 && partitioning != nil {
return nil, fmt.Errorf("partitioning customizations cannot be used with custom filesystems (mountpoints)")
}

if mountpoints != nil && t.RPMOSTree {
return warnings, fmt.Errorf("Custom mountpoints are not supported for ostree types")
if (mountpoints != nil || partitioning != nil) && t.RPMOSTree {
return warnings, fmt.Errorf("custom mountpoints and partitioning are not supported for ostree types")
}

err := blueprint.CheckMountpointsPolicy(mountpoints, policies.MountpointPolicies)
if err != nil {
if err := blueprint.CheckMountpointsPolicy(mountpoints, policies.MountpointPolicies); err != nil {
return warnings, err
}

if err := partitioning.ValidateLayoutConstraints(); err != nil {
return warnings, err
}

if err := blueprint.CheckDiskMountpointsPolicy(partitioning, policies.MountpointPolicies); err != nil {
return warnings, err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/distro/rhel/rhel9/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ func TestDistro_CustomFileSystemManifestError(t *testing.T) {
imgType, _ := arch.GetImageType(imgTypeName)
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if imgTypeName == "edge-commit" || imgTypeName == "edge-container" {
assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types")
assert.EqualError(t, err, "custom mountpoints and partitioning are not supported for ostree types")
} else if imgTypeName == "edge-installer" || imgTypeName == "edge-simplified-installer" || imgTypeName == "edge-raw-image" || imgTypeName == "edge-ami" || imgTypeName == "edge-vsphere" {
continue
} else {
Expand Down Expand Up @@ -699,7 +699,7 @@ func TestDistro_TestRootMountPoint(t *testing.T) {
imgType, _ := arch.GetImageType(imgTypeName)
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if imgTypeName == "edge-commit" || imgTypeName == "edge-container" {
assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types")
assert.EqualError(t, err, "custom mountpoints and partitioning are not supported for ostree types")
} else if imgTypeName == "edge-installer" || imgTypeName == "edge-simplified-installer" || imgTypeName == "edge-raw-image" || imgTypeName == "edge-ami" || imgTypeName == "edge-vsphere" {
continue
} else {
Expand Down Expand Up @@ -829,7 +829,7 @@ func TestDistro_CustomUsrPartitionNotLargeEnough(t *testing.T) {
imgType, _ := arch.GetImageType(imgTypeName)
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if imgTypeName == "edge-commit" || imgTypeName == "edge-container" {
assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types")
assert.EqualError(t, err, "custom mountpoints and partitioning are not supported for ostree types")
} else if imgTypeName == "edge-installer" || imgTypeName == "edge-simplified-installer" || imgTypeName == "edge-raw-image" || imgTypeName == "edge-ami" || imgTypeName == "edge-vsphere" {
continue
} else {
Expand Down
26 changes: 20 additions & 6 deletions pkg/distro/rhel/rhel9/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,33 @@ func checkOptions(t *rhel.ImageType, bp *blueprint.Blueprint, options distro.Ima
}

mountpoints := customizations.GetFilesystems()

if mountpoints != nil && t.RPMOSTree && (t.Name() == "edge-container" || t.Name() == "edge-commit") {
return warnings, fmt.Errorf("Custom mountpoints are not supported for ostree types")
} else if mountpoints != nil && t.RPMOSTree && !(t.Name() == "edge-container" || t.Name() == "edge-commit") {
partitioning, err := customizations.GetPartitioning()
if err != nil {
return nil, err
}
if (mountpoints != nil || partitioning != nil) && t.RPMOSTree && (t.Name() == "edge-container" || t.Name() == "edge-commit") {
return warnings, fmt.Errorf("custom mountpoints and partitioning are not supported for ostree types")
} else if (mountpoints != nil || partitioning != nil) && t.RPMOSTree && !(t.Name() == "edge-container" || t.Name() == "edge-commit") {
//customization allowed for edge-raw-image,edge-ami,edge-vsphere,edge-simplified-installer
err := blueprint.CheckMountpointsPolicy(mountpoints, policies.OstreeMountpointPolicies)
if err != nil {
return warnings, err
}
}

err := blueprint.CheckMountpointsPolicy(mountpoints, policies.MountpointPolicies)
if err != nil {
if len(mountpoints) > 0 && partitioning != nil {
return nil, fmt.Errorf("partitioning customizations cannot be used with custom filesystems (mountpoints)")
}

if err := blueprint.CheckMountpointsPolicy(mountpoints, policies.MountpointPolicies); err != nil {
return warnings, err
}

if err := blueprint.CheckDiskMountpointsPolicy(partitioning, policies.MountpointPolicies); err != nil {
return warnings, err
}

if err := partitioning.ValidateLayoutConstraints(); err != nil {
return warnings, err
}

Expand Down

0 comments on commit 7a5d80d

Please sign in to comment.