From 37a9beff15077d3ed327f835fba7bb567e9b4040 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 22 Nov 2024 09:06:35 +0100 Subject: [PATCH] blueprint: fix DiskCustomization.MinSize with existing pattern This commit fixes the issue that minsize cannot be a string by using the existing pattern. See https://github.com/osbuild/images/pull/1049 for alternative ideas. --- pkg/blueprint/disk_customizations.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg/blueprint/disk_customizations.go b/pkg/blueprint/disk_customizations.go index 09b92099fd..53aa4e4719 100644 --- a/pkg/blueprint/disk_customizations.go +++ b/pkg/blueprint/disk_customizations.go @@ -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).