Skip to content

Commit

Permalink
blueprint: fix DiskCustomization.MinSize with existing pattern
Browse files Browse the repository at this point in the history
This commit fixes the issue that minsize cannot be a string
by using the existing pattern.

See osbuild#1049 for alternative
ideas.
  • Loading branch information
mvo5 committed Nov 22, 2024
1 parent a704960 commit 37a9bef
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/blueprint/disk_customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ type DiskCustomization struct {
Partitions []PartitionCustomization `json:"partitions,omitempty" toml:"partitions,omitempty"`
}

func (dc *DiskCustomization) UnmarshalJSON(data []byte) error {
var dcAnySize struct {
MinSize any `json:"minsize,omitempty" toml:"minsize,omitempty"`
Partitions []PartitionCustomization `json:"partitions,omitempty" toml:"partitions,omitempty"`
}
if err := json.Unmarshal(data, &dcAnySize); err != nil {
return err
}

dc.Partitions = dcAnySize.Partitions

if dcAnySize.MinSize != nil {
size, err := decodeSize(dcAnySize.MinSize)
if err != nil {
return err
}
dc.MinSize = size
}
return nil
}

// PartitionCustomization defines a single partition on a disk. The Type
// defines the kind of "payload" for the partition: plain, lvm, or btrfs.
// - plain: the payload will be a filesystem on a partition (e.g. xfs, ext4).
Expand Down

0 comments on commit 37a9bef

Please sign in to comment.