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

[RFC] blueprint: make minsize required for disk.Customizations #1061

Merged
merged 1 commit into from
Nov 25, 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
42 changes: 24 additions & 18 deletions pkg/blueprint/disk_customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ func (lv *LVCustomization) UnmarshalJSON(data []byte) error {
lv.Name = lvAnySize.Name
lv.FilesystemTypedCustomization = lvAnySize.FilesystemTypedCustomization

if lvAnySize.MinSize != nil {
size, err := decodeSize(lvAnySize.MinSize)
if err != nil {
return err
}
lv.MinSize = size
if lvAnySize.MinSize == nil {
return fmt.Errorf("minsize is required")
}
size, err := decodeSize(lvAnySize.MinSize)
if err != nil {
return err
}
lv.MinSize = size

return nil
}

Expand Down Expand Up @@ -177,14 +179,16 @@ func (v *PartitionCustomization) UnmarshalJSON(data []byte) error {

v.Type = partType

if typeSniffer.MinSize != nil {
minsize, err := decodeSize(typeSniffer.MinSize)
if err != nil {
return fmt.Errorf("%s error decoding minsize for partition: %w", errPrefix, err)
}
v.MinSize = minsize
if typeSniffer.MinSize == nil {
return fmt.Errorf("minsize is required")
}

minsize, err := decodeSize(typeSniffer.MinSize)
if err != nil {
return fmt.Errorf("%s error decoding minsize for partition: %w", errPrefix, err)
}
v.MinSize = minsize

return nil
}

Expand Down Expand Up @@ -301,13 +305,15 @@ func (v *PartitionCustomization) UnmarshalTOML(data any) error {

v.Type = partType

if minsizeField, ok := d["minsize"]; ok {
minsize, err := decodeSize(minsizeField)
if err != nil {
return fmt.Errorf("%s error decoding minsize for partition: %w", errPrefix, err)
}
v.MinSize = minsize
minsizeField, ok := d["minsize"]
if !ok {
return fmt.Errorf("minsize is required")
}
minsize, err := decodeSize(minsizeField)
if err != nil {
return fmt.Errorf("%s error decoding minsize for partition: %w", errPrefix, err)
}
v.MinSize = minsize

return nil
}
Expand Down
31 changes: 4 additions & 27 deletions pkg/blueprint/disk_customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,16 +1035,8 @@ func TestPartitionCustomizationUnmarshalJSON(t *testing.T) {

testCases := map[string]testCase{
"nothing": {
input: "{}",
expected: &blueprint.PartitionCustomization{
Type: "plain",
MinSize: 0,
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
Mountpoint: "",
Label: "",
FSType: "",
},
},
input: "{}",
errorMsg: "minsize is required",
},
"plain": {
input: `{
Expand Down Expand Up @@ -1346,16 +1338,8 @@ func TestPartitionCustomizationUnmarshalTOML(t *testing.T) {

testCases := map[string]testCase{
"nothing": {
input: "",
expected: &blueprint.PartitionCustomization{
Type: "plain",
MinSize: 0,
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
Mountpoint: "",
Label: "",
FSType: "",
},
},
input: "",
errorMsg: "toml: line 0: minsize is required",
},
"plain": {
input: `type = "plain"
Expand Down Expand Up @@ -1647,13 +1631,6 @@ func TestDiskCustomizationUnmarshalJSON(t *testing.T) {
}

testCases := map[string]testCase{
"nothing": {
inputJSON: "{}",
inputTOML: "",
expected: &blueprint.DiskCustomization{
MinSize: 0,
},
},
"minsize/int": {
inputJSON: `{
"minsize": 1234
Expand Down
Loading