Skip to content
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

blueprint,disk: tiny style changes #1056

Merged
merged 1 commit into from
Nov 22, 2024
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
10 changes: 5 additions & 5 deletions pkg/blueprint/disk_customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ func (p *DiskCustomization) Validate() error {
var errs []error
for _, part := range p.Partitions {
switch part.Type {
case "plain", "":
errs = append(errs, part.validatePlain(mountpoints))
case "lvm":
errs = append(errs, part.validateLVM(mountpoints, vgnames))
case "btrfs":
errs = append(errs, part.validateBtrfs(mountpoints))
case "plain", "":
errs = append(errs, part.validatePlain(mountpoints))
default:
errs = append(errs, fmt.Errorf("unknown partition type: %s", part.Type))
}
Expand Down Expand Up @@ -382,19 +382,19 @@ func (p *DiskCustomization) ValidateLayoutConstraints() error {

// Check that the fs type is valid for the mountpoint.
func validateFilesystemType(path, fstype string) error {
badfsMsg := "unsupported filesystem type for %q: %s"
badfsMsgFmt := "unsupported filesystem type for %q: %s"
switch path {
case "/boot":
switch fstype {
case "xfs", "ext4":
default:
return fmt.Errorf(badfsMsg, path, fstype)
return fmt.Errorf(badfsMsgFmt, path, fstype)
}
case "/boot/efi":
switch fstype {
case "vfat":
default:
return fmt.Errorf(badfsMsg, path, fstype)
return fmt.Errorf(badfsMsgFmt, path, fstype)
}
}
return nil
Expand Down
12 changes: 0 additions & 12 deletions pkg/blueprint/disk_customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,12 +848,6 @@ func TestPartitioningLayoutConstraints(t *testing.T) {
"unhappy-btrfs+lvm": {
partitioning: &blueprint.DiskCustomization{
Partitions: []blueprint.PartitionCustomization{
{
Type: "ext4",
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
Mountpoint: "/data",
},
},
{
Type: "btrfs",
BtrfsVolumeCustomization: blueprint.BtrfsVolumeCustomization{
Expand Down Expand Up @@ -1276,12 +1270,6 @@ func TestPartitionCustomizationUnmarshalJSON(t *testing.T) {
"mountpoint": "/home",
"label": "home",
"fs_type": "ext4"
},
{
"name": "loglv",
"mountpoint": "/var/log",
"label": "log",
"fs_type": "xfs"
}
]
}`,
Expand Down
18 changes: 7 additions & 11 deletions pkg/disk/partition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,17 +1000,17 @@ func EnsureRootFilesystem(pt *PartitionTable, defaultFsType FSType) error {
// partition to the end of the existing partition table therefore it is best to
// call this function early to put boot near the front (as is conventional).
func AddBootPartition(pt *PartitionTable, bootFsType FSType) error {
if bootFsType == FS_NONE {
return fmt.Errorf("error creating boot partition: no filesystem type")
}

// collect all labels to avoid conflicts
labels := make(map[string]bool)
_ = pt.ForEachMountable(func(mnt Mountable, path []Entity) error {
labels[mnt.GetFSSpec().Label] = true
return nil
})

if bootFsType == FS_NONE {
return fmt.Errorf("error creating boot partition: no filesystem type")
}

bootLabel, err := genUniqueString("boot", labels)
if err != nil {
return fmt.Errorf("error creating boot partition: %w", err)
Expand Down Expand Up @@ -1158,12 +1158,8 @@ func (options *CustomPartitionTableOptions) getfstype(fstype string) (string, er
// NewCustomPartitionTable creates a partition table based almost entirely on the disk customizations from a blueprint.
func NewCustomPartitionTable(customizations *blueprint.DiskCustomization, options *CustomPartitionTableOptions, rng *rand.Rand) (*PartitionTable, error) {
if options == nil {
// init options with defaults
options = &CustomPartitionTableOptions{
PartitionTableType: PT_GPT,
}
options = &CustomPartitionTableOptions{}
}

if customizations == nil {
customizations = &blueprint.DiskCustomization{}
}
Expand Down Expand Up @@ -1255,7 +1251,7 @@ func addPlainPartition(pt *PartitionTable, partition blueprint.PartitionCustomiz
}
partType, err := getPartitionTypeIDfor(pt.Type, typeName)
if err != nil {
return fmt.Errorf("error creating root partition: %w", err)
return fmt.Errorf("error getting partition type ID for %q: %w", partition.Mountpoint, err)
}
newpart := Partition{
Type: partType,
Expand All @@ -1275,7 +1271,7 @@ func addPlainPartition(pt *PartitionTable, partition blueprint.PartitionCustomiz
func addLVMPartition(pt *PartitionTable, partition blueprint.PartitionCustomization, options *CustomPartitionTableOptions) error {
vgname := partition.Name
if vgname == "" {
// count existing volume groups and generate unique name
// get existing volume groups and generate unique name
existing := make(map[string]bool)
for _, part := range pt.Partitions {
vg, ok := part.Payload.(*LVMVolumeGroup)
Expand Down
Loading