Skip to content

Commit

Permalink
pkg: use new datasizes package
Browse files Browse the repository at this point in the history
This commit uses the new `datasizes` package. Its a very boring
commit.
  • Loading branch information
mvo5 authored and achilleas-k committed Oct 17, 2024
1 parent bdef54d commit 1254e47
Show file tree
Hide file tree
Showing 54 changed files with 342 additions and 314 deletions.
4 changes: 2 additions & 2 deletions cmd/osbuild-playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"path"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/dnfjson"
"github.com/osbuild/images/pkg/image"
Expand All @@ -22,7 +22,7 @@ func RunPlayground(img image.ImageKind, d distro.Distro, arch distro.Arch, repos
solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), arch.Name(), d.Name(), path.Join(state_dir, "rpmmd"))

// Set cache size to 1 GiB
solver.SetMaxCacheSize(1 * common.GiB)
solver.SetMaxCacheSize(1 * datasizes.GiB)

manifest := manifest.New()

Expand Down
14 changes: 7 additions & 7 deletions cmd/otk/osbuild-gen-partition-table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"github.com/osbuild/images/internal/buildconfig"
"github.com/osbuild/images/internal/cmdutil"
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/otkdisk"
"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/osbuild"
)
Expand Down Expand Up @@ -120,7 +120,7 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)

var startOffset uint64
if input.Properties.StartOffset != "" {
startOffset, err = common.DataSizeToUint64(input.Properties.StartOffset)
startOffset, err = datasizes.Parse(input.Properties.StartOffset)
if err != nil {
return nil, err
}
Expand All @@ -137,7 +137,7 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
return nil, fmt.Errorf("internal error: bios partition *must* go first")
}
pt.Partitions = append(pt.Partitions, disk.Partition{
Size: 1 * common.MebiByte,
Size: 1 * datasizes.MebiByte,
Bootable: true,
Type: disk.BIOSBootPartitionGUID,
UUID: disk.BIOSBootPartitionUUID,
Expand All @@ -148,7 +148,7 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
if size == "" {
size = "1 GiB"
}
uintSize, err := common.DataSizeToUint64(size)
uintSize, err := datasizes.Parse(size)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
}

for _, part := range input.Partitions {
uintSize, err := common.DataSizeToUint64(part.Size)
uintSize, err := datasizes.Parse(part.Size)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -212,13 +212,13 @@ func getDiskSizeFrom(input *Input) (diskSize uint64, err error) {
var defaultSize, modMinSize uint64

if input.Properties.DefaultSize != "" {
defaultSize, err = common.DataSizeToUint64(input.Properties.DefaultSize)
defaultSize, err = datasizes.Parse(input.Properties.DefaultSize)
if err != nil {
return 0, err
}
}
if input.Modifications.MinDiskSize != "" {
modMinSize, err = common.DataSizeToUint64(input.Modifications.MinDiskSize)
modMinSize, err = datasizes.Parse(input.Modifications.MinDiskSize)
if err != nil {
return 0, err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/otk/osbuild-gen-partition-table/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/stretchr/testify/assert"

genpart "github.com/osbuild/images/cmd/otk/osbuild-gen-partition-table"
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/otkdisk"
"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/disk"
)

Expand Down Expand Up @@ -465,7 +465,7 @@ func TestGenPartitionTableCustomizationExtraMp(t *testing.T) {
Filesystems: []blueprint.FilesystemCustomization{
{
Mountpoint: "/var/log",
MinSize: 3 * common.GigaByte,
MinSize: 3 * datasizes.GigaByte,
},
},
},
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestGenPartitionTableCustomizationExtraMpPlusModificationPartitionMode(t *t
Filesystems: []blueprint.FilesystemCustomization{
{
Mountpoint: "/var/log",
MinSize: 3 * common.GigaByte,
MinSize: 3 * datasizes.GigaByte,
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/otk/osbuild-make-grub2-inst-stage/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import (
"github.com/stretchr/testify/assert"

makeGrub2Inst "github.com/osbuild/images/cmd/otk/osbuild-make-grub2-inst-stage"
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/otkdisk"
"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/disk"
)

var fakePt = &disk.PartitionTable{
Type: "gpt",
Partitions: []disk.Partition{
{
Size: 1 * common.MiB,
Start: 1 * common.MiB,
Size: 1 * datasizes.MiB,
Start: 1 * datasizes.MiB,
Bootable: true,
Type: disk.BIOSBootPartitionGUID,
UUID: disk.BIOSBootPartitionUUID,
},
{
Size: 1 * common.GiB,
Size: 1 * datasizes.GiB,
Payload: &disk.Filesystem{
Type: "ext4",
Mountpoint: "/",
Expand Down
4 changes: 3 additions & 1 deletion internal/common/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package common

import "fmt"
import (
"fmt"
)

// These constants are set during buildtime using additional
// compiler flags. Not all of them are necessarily defined
Expand Down
32 changes: 16 additions & 16 deletions internal/testdisk/partition.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package testdisk

import (
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/disk"
)

const FakePartitionSize = uint64(789) * common.MiB
const FakePartitionSize = uint64(789) * datasizes.MiB

// MakeFakePartitionTable is a helper to create partition table structs
// for tests. It uses sensible defaults for common scenarios.
Expand Down Expand Up @@ -43,7 +43,7 @@ func MakeFakeBtrfsPartitionTable(mntPoints ...string) *disk.PartitionTable {
var subvolumes []disk.BtrfsSubvolume
pt := &disk.PartitionTable{
Type: "gpt",
Size: 10 * common.GiB,
Size: 10 * datasizes.GiB,
Partitions: []disk.Partition{},
}
size := uint64(0)
Expand All @@ -52,24 +52,24 @@ func MakeFakeBtrfsPartitionTable(mntPoints ...string) *disk.PartitionTable {
case "/boot":
pt.Partitions = append(pt.Partitions, disk.Partition{
Start: size,
Size: 1 * common.GiB,
Size: 1 * datasizes.GiB,
Payload: &disk.Filesystem{
Type: "ext4",
Mountpoint: mntPoint,
},
})
size += 1 * common.GiB
size += 1 * datasizes.GiB
case "/boot/efi":
pt.Partitions = append(pt.Partitions, disk.Partition{
Start: size,
Size: 100 * common.MiB,
Size: 100 * datasizes.MiB,
Payload: &disk.Filesystem{
Type: "vfat",
Mountpoint: mntPoint,
UUID: disk.EFIFilesystemUUID,
},
})
size += 100 * common.MiB
size += 100 * datasizes.MiB
default:
name := mntPoint
if name == "/" {
Expand All @@ -89,14 +89,14 @@ func MakeFakeBtrfsPartitionTable(mntPoints ...string) *disk.PartitionTable {

pt.Partitions = append(pt.Partitions, disk.Partition{
Start: size,
Size: 9 * common.GiB,
Size: 9 * datasizes.GiB,
Payload: &disk.Btrfs{
UUID: disk.RootPartitionUUID,
Subvolumes: subvolumes,
},
})

size += 9 * common.GiB
size += 9 * datasizes.GiB
pt.Size = size

return pt
Expand All @@ -108,7 +108,7 @@ func MakeFakeLVMPartitionTable(mntPoints ...string) *disk.PartitionTable {
var lvs []disk.LVMLogicalVolume
pt := &disk.PartitionTable{
Type: "gpt",
Size: 10 * common.GiB,
Size: 10 * datasizes.GiB,
Partitions: []disk.Partition{},
}
size := uint64(0)
Expand All @@ -117,24 +117,24 @@ func MakeFakeLVMPartitionTable(mntPoints ...string) *disk.PartitionTable {
case "/boot":
pt.Partitions = append(pt.Partitions, disk.Partition{
Start: size,
Size: 1 * common.GiB,
Size: 1 * datasizes.GiB,
Payload: &disk.Filesystem{
Type: "ext4",
Mountpoint: mntPoint,
},
})
size += 1 * common.GiB
size += 1 * datasizes.GiB
case "/boot/efi":
pt.Partitions = append(pt.Partitions, disk.Partition{
Start: size,
Size: 100 * common.MiB,
Size: 100 * datasizes.MiB,
Payload: &disk.Filesystem{
Type: "vfat",
Mountpoint: mntPoint,
UUID: disk.EFIFilesystemUUID,
},
})
size += 100 * common.MiB
size += 100 * datasizes.MiB
default:
name := "lv-for-" + mntPoint
if name == "/" {
Expand All @@ -155,13 +155,13 @@ func MakeFakeLVMPartitionTable(mntPoints ...string) *disk.PartitionTable {

pt.Partitions = append(pt.Partitions, disk.Partition{
Start: size,
Size: 9 * common.GiB,
Size: 9 * datasizes.GiB,
Payload: &disk.LVMVolumeGroup{
LogicalVolumes: lvs,
},
})

size += 9 * common.GiB
size += 9 * datasizes.GiB
pt.Size = size

return pt
Expand Down
4 changes: 2 additions & 2 deletions pkg/blueprint/blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/datasizes"
)

func TestBlueprintParse(t *testing.T) {
Expand Down Expand Up @@ -67,7 +67,7 @@ minsize = "20 GiB"
assert.Equal(t, "/var", bp.Customizations.Filesystem[0].Mountpoint)
assert.Equal(t, uint64(2147483648), bp.Customizations.Filesystem[0].MinSize)
assert.Equal(t, "/opt", bp.Customizations.Filesystem[1].Mountpoint)
assert.Equal(t, uint64(20*common.GiB), bp.Customizations.Filesystem[1].MinSize)
assert.Equal(t, uint64(20*datasizes.GiB), bp.Customizations.Filesystem[1].MinSize)
}

func TestGetPackages(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/blueprint/filesystem_customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/pathpolicy"
)

Expand All @@ -32,7 +32,7 @@ func (fsc *FilesystemCustomization) UnmarshalTOML(data interface{}) error {
}
fsc.MinSize = uint64(minSize)
case string:
minSize, err := common.DataSizeToUint64(d["minsize"].(string))
minSize, err := datasizes.Parse(d["minsize"].(string))
if err != nil {
return fmt.Errorf("TOML unmarshal: minsize is not valid filesystem size (%w)", err)
}
Expand Down Expand Up @@ -63,7 +63,7 @@ func (fsc *FilesystemCustomization) UnmarshalJSON(data []byte) error {
case float64:
fsc.MinSize = uint64(d["minsize"].(float64))
case string:
minSize, err := common.DataSizeToUint64(d["minsize"].(string))
minSize, err := datasizes.Parse(d["minsize"].(string))
if err != nil {
return fmt.Errorf("JSON unmarshal: minsize is not valid filesystem size (%w)", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/datasizes"
)

const (
KiB = common.KiB
MiB = common.MiB
GiB = common.GiB
KiB = datasizes.KiB
MiB = datasizes.MiB
GiB = datasizes.GiB
)

func TestDisk_AlignUp(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/disk/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/google/uuid"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/datasizes"
)

// Argon2id defines parameters for the key derivation function for LUKS.
Expand Down Expand Up @@ -116,7 +116,7 @@ func (lc *LUKSContainer) MetadataSize() uint64 {
}

// 16 MiB is the default size for the LUKS2 header
return 16 * common.MiB
return 16 * datasizes.MiB
}

func (lc *LUKSContainer) minSize(size uint64) uint64 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/disk/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"reflect"
"strings"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/datasizes"
)

// Default physical extent size in bytes: logical volumes
// created inside the VG will be aligned to this.
const LVMDefaultExtentSize = 4 * common.MebiByte
const LVMDefaultExtentSize = 4 * datasizes.MebiByte

type LVMVolumeGroup struct {
Name string
Expand Down Expand Up @@ -143,7 +143,7 @@ func (vg *LVMVolumeGroup) MetadataSize() uint64 {
// of the metadata and its location and thus the start of the physical
// extent. For now we assume the default which results in a start of
// the physical extent 1 MiB
return 1 * common.MiB
return 1 * datasizes.MiB
}

func (vg *LVMVolumeGroup) minSize(size uint64) uint64 {
Expand Down
Loading

0 comments on commit 1254e47

Please sign in to comment.