Skip to content

Commit

Permalink
distro: Add PartitioningMode to ImageOptions
Browse files Browse the repository at this point in the history
And use it in the distro's getPartitionTable.

TODO Logic about that combination of things is or is not supported needs
a more central location than embedded in the functions.
  • Loading branch information
bcl committed Oct 12, 2023
1 parent 7b99e11 commit 117134d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
9 changes: 5 additions & 4 deletions pkg/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ type ImageType interface {

// The ImageOptions specify options for a specific image build
type ImageOptions struct {
Size uint64
OSTree *ostree.ImageOptions
Subscription *subscription.ImageOptions
Facts *facts.ImageOptions
Size uint64
OSTree *ostree.ImageOptions
Subscription *subscription.ImageOptions
Facts *facts.ImageOptions
PartitioningMode disk.PartitioningMode
}

type BasePartitionTableMap map[string]disk.PartitionTable
Expand Down
11 changes: 8 additions & 3 deletions pkg/distro/fedora/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ func (t *imageType) getPartitionTable(

imageSize := t.Size(options.Size)

partitioningMode := disk.AutoLVMPartitioningMode
partitioningMode := options.PartitioningMode
if t.rpmOstree {
// IoT supports only raw, force it.
partitioningMode = disk.RawPartitioningMode
// IoT supports only LVM, force it.
// Raw is not supported, return an error if it is requested
// TODO Need a central location for logic like this
if partitioningMode == disk.RawPartitioningMode {
return nil, fmt.Errorf("partitioning mode raw not supported for %s on %s", t.Name(), t.arch.Name())
}
partitioningMode = disk.AutoLVMPartitioningMode
}

return disk.NewPartitionTable(&basePartitionTable, mountpoints, imageSize, partitioningMode, t.requiredPartitionSizes, rng)
Expand Down
2 changes: 1 addition & 1 deletion pkg/distro/rhel7/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (t *imageType) getPartitionTable(

imageSize := t.Size(options.Size)

return disk.NewPartitionTable(&basePartitionTable, mountpoints, imageSize, disk.AutoLVMPartitioningMode, nil, rng)
return disk.NewPartitionTable(&basePartitionTable, mountpoints, imageSize, options.PartitioningMode, nil, rng)
}

func (t *imageType) getDefaultImageConfig() *distro.ImageConfig {
Expand Down
7 changes: 6 additions & 1 deletion pkg/distro/rhel8/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ func (t *imageType) getPartitionTable(

imageSize := t.Size(options.Size)

partitioningMode := disk.AutoLVMPartitioningMode
partitioningMode := options.PartitioningMode
if t.rpmOstree {
// Edge supports only raw, force it.
// LVM is not supported, return an error if it is requested
// TODO Need a central location for logic like this
if partitioningMode == disk.LVMPartitioningMode {
return nil, fmt.Errorf("partitioning mode lvm not supported for %s on %s", t.Name(), t.arch.Name())
}
partitioningMode = disk.RawPartitioningMode
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/distro/rhel9/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,15 @@ func (t *imageType) getPartitionTable(

imageSize := t.Size(options.Size)

partitioningMode := disk.AutoLVMPartitioningMode
partitioningMode := options.PartitioningMode
if t.rpmOstree {
// Edge supports only LVM, force it.
// Raw is not supported, return an error if it is requested
// TODO Need a central location for logic like this
if partitioningMode == disk.RawPartitioningMode {
return nil, fmt.Errorf("partitioning mode raw not supported for %s on %s", t.Name(), t.arch.Name())
}

partitioningMode = disk.LVMPartitioningMode
}

Expand Down

0 comments on commit 117134d

Please sign in to comment.