Skip to content

Commit

Permalink
blueprint: add support for selecting partition table type
Browse files Browse the repository at this point in the history
Users need to have control over the partition table type in certain
cases. Most prominently, they need a dos-style partition table for
single-board computers.

Let's add a simple customizations for it.
  • Loading branch information
ondrejbudai authored and supakeen committed Dec 4, 2024
1 parent 54e1ff1 commit 30ba08a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/blueprint/disk_customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import (
)

type DiskCustomization struct {
// TODO: Add partition table type: gpt or dos
// Type of the partition table: gpt or dos.
// Optional, the default depends on the distro and image type.
Type string
MinSize uint64
Partitions []PartitionCustomization
}

type diskCustomizationMarshaler struct {
// TODO: Add partition table type: gpt or dos
Type string `json:"type,omitempty" toml:"type,omitempty"`
MinSize datasizes.Size `json:"minsize,omitempty" toml:"minsize,omitempty"`
Partitions []PartitionCustomization `json:"partitions,omitempty" toml:"partitions,omitempty"`
}
Expand All @@ -30,6 +32,7 @@ func (dc *DiskCustomization) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &dcm); err != nil {
return err
}
dc.Type = dcm.Type
dc.MinSize = dcm.MinSize.Uint64()
dc.Partitions = dcm.Partitions

Expand Down Expand Up @@ -345,6 +348,12 @@ func (p *DiskCustomization) Validate() error {
return nil
}

switch p.Type {
case "gpt", "dos", "":
default:
return fmt.Errorf("unknown partition table type: %s (valid: gpt, dos)", p.Type)
}

mountpoints := make(map[string]bool)
vgnames := make(map[string]bool)
var errs []error
Expand Down
25 changes: 25 additions & 0 deletions pkg/blueprint/disk_customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,22 @@ func TestPartitioningValidation(t *testing.T) {
},
expectedMsg: "invalid partitioning customizations:\nmountpoint for swap logical volume with name \"swappylv\" in volume group \"badvg\" must be empty",
},
"gpt": {
partitioning: &blueprint.DiskCustomization{
Type: "gpt",
},
},
"dos": {
partitioning: &blueprint.DiskCustomization{
Type: "dos",
},
},
"unhappy-badtype": {
partitioning: &blueprint.DiskCustomization{
Type: "toucan",
},
expectedMsg: "unknown partition table type: toucan (valid: gpt, dos)",
},
}

for name := range testCases {
Expand Down Expand Up @@ -1737,6 +1753,15 @@ func TestDiskCustomizationUnmarshalJSON(t *testing.T) {
MinSize: 1 * datasizes.GiB,
},
},
"type": {
inputJSON: `{
"type": "gpt"
}`,
inputTOML: `type = "gpt"`,
expected: &blueprint.DiskCustomization{
Type: "gpt",
},
},
}

for name := range testCases {
Expand Down

0 comments on commit 30ba08a

Please sign in to comment.