Skip to content

Commit

Permalink
osbuild,manifest: simplify osbuild.Devices
Browse files Browse the repository at this point in the history
The osbuild.Devices type is just an alias to map[string]osbuild.Device
and it feels like it might be easier to expose the map[string]Device
directly. From the type it's not clear if it's a map and when using
the type it needs to be used like map it seems easiest to expose it
directly.

Another benefit of this is that the pointers used are now clearer (IMHO)
i.e. no indirections required for maps.
  • Loading branch information
mvo5 committed Jan 16, 2024
1 parent 9b86dd5 commit c882c5e
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions pkg/manifest/iso_rootfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (p *ISORootfsImg) serialize() osbuild.Pipeline {
)

devName := "device"
devices := osbuild.Devices{devName: *lodevice}
devices := map[string]osbuild.Device{devName: *lodevice}
mkfsStage := osbuild.NewMkfsExt4Stage(mkfsStageOptions, devices)
pipeline.AddStage(mkfsStage)

Expand All @@ -64,7 +64,7 @@ func (p *ISORootfsImg) serialize() osbuild.Pipeline {
}
copyStageInputs := osbuild.NewPipelineTreeInputs(inputName, p.installerPipeline.Name())
copyStageMounts := &osbuild.Mounts{*osbuild.NewExt4Mount(devName, devName, "/")}
copyStage := osbuild.NewCopyStage(copyStageOptions, copyStageInputs, &devices, copyStageMounts)
copyStage := osbuild.NewCopyStage(copyStageOptions, copyStageInputs, devices, copyStageMounts)
pipeline.AddStage(copyStage)
return pipeline
}
2 changes: 1 addition & 1 deletion pkg/osbuild/clevis_luks_bind_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type ClevisLuksBindStageOptions struct {

func (ClevisLuksBindStageOptions) isStageOptions() {}

func NewClevisLuksBindStage(options *ClevisLuksBindStageOptions, devices Devices) *Stage {
func NewClevisLuksBindStage(options *ClevisLuksBindStageOptions, devices map[string]Device) *Stage {
return &Stage{
Type: "org.osbuild.clevis.luks-bind",
Options: options,
Expand Down
9 changes: 4 additions & 5 deletions pkg/osbuild/copy_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ type CopyStagePath struct {

func (CopyStageOptions) isStageOptions() {}

func NewCopyStage(options *CopyStageOptions, inputs Inputs, devices *Devices, mounts *Mounts) *Stage {
func NewCopyStage(options *CopyStageOptions, inputs Inputs, devices map[string]Device, mounts *Mounts) *Stage {
return &Stage{
Type: "org.osbuild.copy",
Options: options,
Inputs: inputs,
Devices: *devices,
Devices: devices,
Mounts: *mounts,
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ func (*CopyStageFilesInputs) isStageInputs() {}
// function, not just the options, devices, and mounts.
func GenCopyFSTreeOptions(inputName, inputPipeline, filename string, pt *disk.PartitionTable) (
*CopyStageOptions,
*Devices,
map[string]Device,
*Mounts,
) {

Expand Down Expand Up @@ -119,7 +119,6 @@ func GenCopyFSTreeOptions(inputName, inputPipeline, filename string, pt *disk.Pa
}

stageMounts := Mounts(mounts)
stageDevices := Devices(devices)

options := CopyStageOptions{
Paths: []CopyStagePath{
Expand All @@ -130,5 +129,5 @@ func GenCopyFSTreeOptions(inputName, inputPipeline, filename string, pt *disk.Pa
},
}

return &options, &stageDevices, &stageMounts
return &options, devices, &stageMounts
}
3 changes: 1 addition & 2 deletions pkg/osbuild/copy_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func TestNewCopyStage(t *testing.T) {
}
// convert to alias types
stageMounts := Mounts(mounts)
stageDevices := Devices(devices)
actualStage := NewCopyStage(&CopyStageOptions{paths}, NewPipelineTreeInputs("tree-input", "input-pipeline"), &stageDevices, &stageMounts)
actualStage := NewCopyStage(&CopyStageOptions{paths}, NewPipelineTreeInputs("tree-input", "input-pipeline"), devices, &stageMounts)
assert.Equal(t, expectedStage, actualStage)
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/osbuild/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/osbuild/images/pkg/disk"
)

type Devices map[string]Device

type Device struct {
Type string `json:"type"`
Parent string `json:"parent,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/osbuild/luks2_format_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (o LUKS2CreateStageOptions) validate() error {
return nil
}

func NewLUKS2CreateStage(options *LUKS2CreateStageOptions, devices Devices) *Stage {
func NewLUKS2CreateStage(options *LUKS2CreateStageOptions, devices map[string]Device) *Stage {
if err := options.validate(); err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/osbuild/luks2_remove_key_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type LUKS2RemoveKeyStageOptions struct {

func (LUKS2RemoveKeyStageOptions) isStageOptions() {}

func NewLUKS2RemoveKeyStage(options *LUKS2RemoveKeyStageOptions, devices Devices) *Stage {
func NewLUKS2RemoveKeyStage(options *LUKS2RemoveKeyStageOptions, devices map[string]Device) *Stage {
return &Stage{
Type: "org.osbuild.luks2.remove-key",
Options: options,
Expand Down
2 changes: 1 addition & 1 deletion pkg/osbuild/lvm2_create_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type LogicalVolume struct {
Size string `json:"size"`
}

func NewLVM2CreateStage(options *LVM2CreateStageOptions, devices Devices) *Stage {
func NewLVM2CreateStage(options *LVM2CreateStageOptions, devices map[string]Device) *Stage {
if err := options.validate(); err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/osbuild/lvm2_metadata_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (o LVM2MetadataStageOptions) validate() error {
return nil
}

func NewLVM2MetadataStage(options *LVM2MetadataStageOptions, devices Devices) *Stage {
func NewLVM2MetadataStage(options *LVM2MetadataStageOptions, devices map[string]Device) *Stage {
if err := options.validate(); err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/osbuild/mkfs_stages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestNewMkfsStage(t *testing.T) {
mkbtrfsExpected := &Stage{
Type: "org.osbuild.mkfs.btrfs",
Options: btrfsOptions,
Devices: Devices{"device": *device},
Devices: map[string]Device{"device": *device},
}
assert.Equal(t, mkbtrfsExpected, mkbtrfs)

Expand All @@ -42,7 +42,7 @@ func TestNewMkfsStage(t *testing.T) {
mkext4Expected := &Stage{
Type: "org.osbuild.mkfs.ext4",
Options: ext4Options,
Devices: Devices{"device": *device},
Devices: map[string]Device{"device": *device},
}
assert.Equal(t, mkext4Expected, mkext4)

Expand All @@ -55,7 +55,7 @@ func TestNewMkfsStage(t *testing.T) {
mkfatExpected := &Stage{
Type: "org.osbuild.mkfs.fat",
Options: fatOptions,
Devices: Devices{"device": *device},
Devices: map[string]Device{"device": *device},
}
assert.Equal(t, mkfatExpected, mkfat)

Expand All @@ -67,7 +67,7 @@ func TestNewMkfsStage(t *testing.T) {
mkxfsExpected := &Stage{
Type: "org.osbuild.mkfs.xfs",
Options: xfsOptions,
Devices: Devices{"device": *device},
Devices: map[string]Device{"device": *device},
}
assert.Equal(t, mkxfsExpected, mkxfs)
}
4 changes: 3 additions & 1 deletion pkg/osbuild/sfdisk_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func NewSfdiskStage(options *SfdiskStageOptions, device *Device) *Stage {
return &Stage{
Type: "org.osbuild.sfdisk",
Options: options,
Devices: Devices{"device": *device},
Devices: map[string]Device{
"device": *device,
},
}
}
2 changes: 1 addition & 1 deletion pkg/osbuild/sfdisk_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestNewSfdiskStage(t *testing.T) {
}

device := NewLoopbackDevice(&LoopbackDeviceOptions{Filename: "disk.raw"})
devices := Devices{"device": *device}
devices := map[string]Device{"device": *device}

expectedStage := &Stage{
Type: "org.osbuild.sfdisk",
Expand Down
4 changes: 3 additions & 1 deletion pkg/osbuild/sgdisk_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func NewSgdiskStage(options *SgdiskStageOptions, device *Device) *Stage {
return &Stage{
Type: "org.osbuild.sgdisk",
Options: options,
Devices: Devices{"device": *device},
Devices: map[string]Device{
"device": *device,
},
}
}
2 changes: 1 addition & 1 deletion pkg/osbuild/sgdisk_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestNewSgdiskStage(t *testing.T) {
}

device := NewLoopbackDevice(&LoopbackDeviceOptions{Filename: "disk.raw"})
devices := Devices{"device": *device}
devices := map[string]Device{"device": *device}

expectedStage := &Stage{
Type: "org.osbuild.sgdisk",
Expand Down
8 changes: 4 additions & 4 deletions pkg/osbuild/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ type Stage struct {
Type string `json:"type"`
// Stage-type specific options fully determining the operations of the

Inputs Inputs `json:"inputs,omitempty"`
Options StageOptions `json:"options,omitempty"`
Devices Devices `json:"devices,omitempty"`
Mounts Mounts `json:"mounts,omitempty"`
Inputs Inputs `json:"inputs,omitempty"`
Options StageOptions `json:"options,omitempty"`
Devices map[string]Device `json:"devices,omitempty"`
Mounts Mounts `json:"mounts,omitempty"`
}

// StageOptions specify the operations of a given stage-type.
Expand Down
6 changes: 3 additions & 3 deletions pkg/osbuild/zipl_inst_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func (ZiplInstStageOptions) isStageOptions() {}

// Return a new zipl.inst stage. The 'disk' parameter must represent the
// (entire) device that contains the /boot partition.
func NewZiplInstStage(options *ZiplInstStageOptions, disk *Device, devices *Devices, mounts *Mounts) *Stage {
func NewZiplInstStage(options *ZiplInstStageOptions, disk *Device, devices map[string]Device, mounts *Mounts) *Stage {
// create a new devices map and add the disk to it
devmap := map[string]Device(*devices)
devmap := map[string]Device(devices)
devmap["disk"] = *disk
ziplDevices := Devices(devmap)
ziplDevices := map[string]Device(devmap)
return &Stage{
Type: "org.osbuild.zipl.inst",
Options: options,
Expand Down

0 comments on commit c882c5e

Please sign in to comment.