Skip to content

Commit 1254e47

Browse files
mvo5achilleas-k
authored andcommitted
pkg: use new datasizes package
This commit uses the new `datasizes` package. Its a very boring commit.
1 parent bdef54d commit 1254e47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+342
-314
lines changed

cmd/osbuild-playground/playground.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"path"
88

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

2424
// Set cache size to 1 GiB
25-
solver.SetMaxCacheSize(1 * common.GiB)
25+
solver.SetMaxCacheSize(1 * datasizes.GiB)
2626

2727
manifest := manifest.New()
2828

cmd/otk/osbuild-gen-partition-table/main.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
"github.com/osbuild/images/internal/buildconfig"
1111
"github.com/osbuild/images/internal/cmdutil"
12-
"github.com/osbuild/images/internal/common"
1312
"github.com/osbuild/images/internal/otkdisk"
1413
"github.com/osbuild/images/pkg/blueprint"
14+
"github.com/osbuild/images/pkg/datasizes"
1515
"github.com/osbuild/images/pkg/disk"
1616
"github.com/osbuild/images/pkg/osbuild"
1717
)
@@ -120,7 +120,7 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
120120

121121
var startOffset uint64
122122
if input.Properties.StartOffset != "" {
123-
startOffset, err = common.DataSizeToUint64(input.Properties.StartOffset)
123+
startOffset, err = datasizes.Parse(input.Properties.StartOffset)
124124
if err != nil {
125125
return nil, err
126126
}
@@ -137,7 +137,7 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
137137
return nil, fmt.Errorf("internal error: bios partition *must* go first")
138138
}
139139
pt.Partitions = append(pt.Partitions, disk.Partition{
140-
Size: 1 * common.MebiByte,
140+
Size: 1 * datasizes.MebiByte,
141141
Bootable: true,
142142
Type: disk.BIOSBootPartitionGUID,
143143
UUID: disk.BIOSBootPartitionUUID,
@@ -148,7 +148,7 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
148148
if size == "" {
149149
size = "1 GiB"
150150
}
151-
uintSize, err := common.DataSizeToUint64(size)
151+
uintSize, err := datasizes.Parse(size)
152152
if err != nil {
153153
return nil, err
154154
}
@@ -180,7 +180,7 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
180180
}
181181

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

214214
if input.Properties.DefaultSize != "" {
215-
defaultSize, err = common.DataSizeToUint64(input.Properties.DefaultSize)
215+
defaultSize, err = datasizes.Parse(input.Properties.DefaultSize)
216216
if err != nil {
217217
return 0, err
218218
}
219219
}
220220
if input.Modifications.MinDiskSize != "" {
221-
modMinSize, err = common.DataSizeToUint64(input.Modifications.MinDiskSize)
221+
modMinSize, err = datasizes.Parse(input.Modifications.MinDiskSize)
222222
if err != nil {
223223
return 0, err
224224
}

cmd/otk/osbuild-gen-partition-table/main_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"github.com/stretchr/testify/assert"
1010

1111
genpart "github.com/osbuild/images/cmd/otk/osbuild-gen-partition-table"
12-
"github.com/osbuild/images/internal/common"
1312
"github.com/osbuild/images/internal/otkdisk"
1413
"github.com/osbuild/images/pkg/blueprint"
14+
"github.com/osbuild/images/pkg/datasizes"
1515
"github.com/osbuild/images/pkg/disk"
1616
)
1717

@@ -465,7 +465,7 @@ func TestGenPartitionTableCustomizationExtraMp(t *testing.T) {
465465
Filesystems: []blueprint.FilesystemCustomization{
466466
{
467467
Mountpoint: "/var/log",
468-
MinSize: 3 * common.GigaByte,
468+
MinSize: 3 * datasizes.GigaByte,
469469
},
470470
},
471471
},
@@ -554,7 +554,7 @@ func TestGenPartitionTableCustomizationExtraMpPlusModificationPartitionMode(t *t
554554
Filesystems: []blueprint.FilesystemCustomization{
555555
{
556556
Mountpoint: "/var/log",
557-
MinSize: 3 * common.GigaByte,
557+
MinSize: 3 * datasizes.GigaByte,
558558
},
559559
},
560560
},

cmd/otk/osbuild-make-grub2-inst-stage/main_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ import (
88
"github.com/stretchr/testify/assert"
99

1010
makeGrub2Inst "github.com/osbuild/images/cmd/otk/osbuild-make-grub2-inst-stage"
11-
"github.com/osbuild/images/internal/common"
1211
"github.com/osbuild/images/internal/otkdisk"
12+
"github.com/osbuild/images/pkg/datasizes"
1313
"github.com/osbuild/images/pkg/disk"
1414
)
1515

1616
var fakePt = &disk.PartitionTable{
1717
Type: "gpt",
1818
Partitions: []disk.Partition{
1919
{
20-
Size: 1 * common.MiB,
21-
Start: 1 * common.MiB,
20+
Size: 1 * datasizes.MiB,
21+
Start: 1 * datasizes.MiB,
2222
Bootable: true,
2323
Type: disk.BIOSBootPartitionGUID,
2424
UUID: disk.BIOSBootPartitionUUID,
2525
},
2626
{
27-
Size: 1 * common.GiB,
27+
Size: 1 * datasizes.GiB,
2828
Payload: &disk.Filesystem{
2929
Type: "ext4",
3030
Mountpoint: "/",

internal/common/constants.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package common
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
)
46

57
// These constants are set during buildtime using additional
68
// compiler flags. Not all of them are necessarily defined

internal/testdisk/partition.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package testdisk
22

33
import (
4-
"github.com/osbuild/images/internal/common"
4+
"github.com/osbuild/images/pkg/datasizes"
55
"github.com/osbuild/images/pkg/disk"
66
)
77

8-
const FakePartitionSize = uint64(789) * common.MiB
8+
const FakePartitionSize = uint64(789) * datasizes.MiB
99

1010
// MakeFakePartitionTable is a helper to create partition table structs
1111
// for tests. It uses sensible defaults for common scenarios.
@@ -43,7 +43,7 @@ func MakeFakeBtrfsPartitionTable(mntPoints ...string) *disk.PartitionTable {
4343
var subvolumes []disk.BtrfsSubvolume
4444
pt := &disk.PartitionTable{
4545
Type: "gpt",
46-
Size: 10 * common.GiB,
46+
Size: 10 * datasizes.GiB,
4747
Partitions: []disk.Partition{},
4848
}
4949
size := uint64(0)
@@ -52,24 +52,24 @@ func MakeFakeBtrfsPartitionTable(mntPoints ...string) *disk.PartitionTable {
5252
case "/boot":
5353
pt.Partitions = append(pt.Partitions, disk.Partition{
5454
Start: size,
55-
Size: 1 * common.GiB,
55+
Size: 1 * datasizes.GiB,
5656
Payload: &disk.Filesystem{
5757
Type: "ext4",
5858
Mountpoint: mntPoint,
5959
},
6060
})
61-
size += 1 * common.GiB
61+
size += 1 * datasizes.GiB
6262
case "/boot/efi":
6363
pt.Partitions = append(pt.Partitions, disk.Partition{
6464
Start: size,
65-
Size: 100 * common.MiB,
65+
Size: 100 * datasizes.MiB,
6666
Payload: &disk.Filesystem{
6767
Type: "vfat",
6868
Mountpoint: mntPoint,
6969
UUID: disk.EFIFilesystemUUID,
7070
},
7171
})
72-
size += 100 * common.MiB
72+
size += 100 * datasizes.MiB
7373
default:
7474
name := mntPoint
7575
if name == "/" {
@@ -89,14 +89,14 @@ func MakeFakeBtrfsPartitionTable(mntPoints ...string) *disk.PartitionTable {
8989

9090
pt.Partitions = append(pt.Partitions, disk.Partition{
9191
Start: size,
92-
Size: 9 * common.GiB,
92+
Size: 9 * datasizes.GiB,
9393
Payload: &disk.Btrfs{
9494
UUID: disk.RootPartitionUUID,
9595
Subvolumes: subvolumes,
9696
},
9797
})
9898

99-
size += 9 * common.GiB
99+
size += 9 * datasizes.GiB
100100
pt.Size = size
101101

102102
return pt
@@ -108,7 +108,7 @@ func MakeFakeLVMPartitionTable(mntPoints ...string) *disk.PartitionTable {
108108
var lvs []disk.LVMLogicalVolume
109109
pt := &disk.PartitionTable{
110110
Type: "gpt",
111-
Size: 10 * common.GiB,
111+
Size: 10 * datasizes.GiB,
112112
Partitions: []disk.Partition{},
113113
}
114114
size := uint64(0)
@@ -117,24 +117,24 @@ func MakeFakeLVMPartitionTable(mntPoints ...string) *disk.PartitionTable {
117117
case "/boot":
118118
pt.Partitions = append(pt.Partitions, disk.Partition{
119119
Start: size,
120-
Size: 1 * common.GiB,
120+
Size: 1 * datasizes.GiB,
121121
Payload: &disk.Filesystem{
122122
Type: "ext4",
123123
Mountpoint: mntPoint,
124124
},
125125
})
126-
size += 1 * common.GiB
126+
size += 1 * datasizes.GiB
127127
case "/boot/efi":
128128
pt.Partitions = append(pt.Partitions, disk.Partition{
129129
Start: size,
130-
Size: 100 * common.MiB,
130+
Size: 100 * datasizes.MiB,
131131
Payload: &disk.Filesystem{
132132
Type: "vfat",
133133
Mountpoint: mntPoint,
134134
UUID: disk.EFIFilesystemUUID,
135135
},
136136
})
137-
size += 100 * common.MiB
137+
size += 100 * datasizes.MiB
138138
default:
139139
name := "lv-for-" + mntPoint
140140
if name == "/" {
@@ -155,13 +155,13 @@ func MakeFakeLVMPartitionTable(mntPoints ...string) *disk.PartitionTable {
155155

156156
pt.Partitions = append(pt.Partitions, disk.Partition{
157157
Start: size,
158-
Size: 9 * common.GiB,
158+
Size: 9 * datasizes.GiB,
159159
Payload: &disk.LVMVolumeGroup{
160160
LogicalVolumes: lvs,
161161
},
162162
})
163163

164-
size += 9 * common.GiB
164+
size += 9 * datasizes.GiB
165165
pt.Size = size
166166

167167
return pt

pkg/blueprint/blueprint_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/stretchr/testify/assert"
99
"github.com/stretchr/testify/require"
1010

11-
"github.com/osbuild/images/internal/common"
11+
"github.com/osbuild/images/pkg/datasizes"
1212
)
1313

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

7373
func TestGetPackages(t *testing.T) {

pkg/blueprint/filesystem_customizations.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"errors"
66
"fmt"
77

8-
"github.com/osbuild/images/internal/common"
8+
"github.com/osbuild/images/pkg/datasizes"
99
"github.com/osbuild/images/pkg/pathpolicy"
1010
)
1111

@@ -32,7 +32,7 @@ func (fsc *FilesystemCustomization) UnmarshalTOML(data interface{}) error {
3232
}
3333
fsc.MinSize = uint64(minSize)
3434
case string:
35-
minSize, err := common.DataSizeToUint64(d["minsize"].(string))
35+
minSize, err := datasizes.Parse(d["minsize"].(string))
3636
if err != nil {
3737
return fmt.Errorf("TOML unmarshal: minsize is not valid filesystem size (%w)", err)
3838
}
@@ -63,7 +63,7 @@ func (fsc *FilesystemCustomization) UnmarshalJSON(data []byte) error {
6363
case float64:
6464
fsc.MinSize = uint64(d["minsize"].(float64))
6565
case string:
66-
minSize, err := common.DataSizeToUint64(d["minsize"].(string))
66+
minSize, err := datasizes.Parse(d["minsize"].(string))
6767
if err != nil {
6868
return fmt.Errorf("JSON unmarshal: minsize is not valid filesystem size (%w)", err)
6969
}

pkg/disk/disk_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
1111

12-
"github.com/osbuild/images/internal/common"
1312
"github.com/osbuild/images/pkg/blueprint"
13+
"github.com/osbuild/images/pkg/datasizes"
1414
)
1515

1616
const (
17-
KiB = common.KiB
18-
MiB = common.MiB
19-
GiB = common.GiB
17+
KiB = datasizes.KiB
18+
MiB = datasizes.MiB
19+
GiB = datasizes.GiB
2020
)
2121

2222
func TestDisk_AlignUp(t *testing.T) {

pkg/disk/luks.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/google/uuid"
99

10-
"github.com/osbuild/images/internal/common"
10+
"github.com/osbuild/images/pkg/datasizes"
1111
)
1212

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

118118
// 16 MiB is the default size for the LUKS2 header
119-
return 16 * common.MiB
119+
return 16 * datasizes.MiB
120120
}
121121

122122
func (lc *LUKSContainer) minSize(size uint64) uint64 {

pkg/disk/lvm.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"reflect"
66
"strings"
77

8-
"github.com/osbuild/images/internal/common"
8+
"github.com/osbuild/images/pkg/datasizes"
99
)
1010

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

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

149149
func (vg *LVMVolumeGroup) minSize(size uint64) uint64 {

0 commit comments

Comments
 (0)