Skip to content

Commit 7c0ec06

Browse files
committed
refactor: move solo5 prefix from block identifiers to annotation key
Ref: #315 Signed-off-by: viju <avijusanjai@gmail.com>
1 parent 8810361 commit 7c0ec06

6 files changed

Lines changed: 38 additions & 39 deletions

File tree

pkg/unikontainers/config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545
annotBlock = "com.urunc.unikernel.block"
4646
annotBlockMntPoint = "com.urunc.unikernel.blkMntPoint"
4747
annotMountRootfs = "com.urunc.unikernel.mountRootfs"
48-
annotSolo5BlkDev = "com.urunc.unikernel.blkDev"
48+
annotBlkDev = "com.urunc.unikernel.solo5BlkDev"
4949
)
5050

5151
// A UnikernelConfig struct holds the info provided by bima image on how to execute our unikernel
@@ -59,7 +59,7 @@ type UnikernelConfig struct {
5959
Block string `json:"com.urunc.unikernel.block,omitempty"`
6060
BlkMntPoint string `json:"com.urunc.unikernel.blkMntPoint,omitempty"`
6161
MountRootfs string `json:"com.urunc.unikernel.mountRootfs"`
62-
Solo5BlkDev string `json:"com.urunc.unikernel.blkDev,omitempty"`
62+
BlkDev string `json:"com.urunc.unikernel.solo5BlkDev,omitempty"`
6363
}
6464

6565
// validate checks if the mandatory configuration fields are present.
@@ -121,7 +121,7 @@ func getConfigFromSpec(spec *specs.Spec) *UnikernelConfig {
121121
block := spec.Annotations[annotBlock]
122122
blkMntPoint := spec.Annotations[annotBlockMntPoint]
123123
MountRootfs := spec.Annotations[annotMountRootfs]
124-
solo5BlkDev := spec.Annotations[annotSolo5BlkDev]
124+
blkDev := spec.Annotations[annotBlkDev]
125125
uniklog.WithFields(logrus.Fields{
126126
"unikernelType": tryDecode(unikernelType),
127127
"unikernelVersion": tryDecode(unikernelVersion),
@@ -132,7 +132,7 @@ func getConfigFromSpec(spec *specs.Spec) *UnikernelConfig {
132132
"block": tryDecode(block),
133133
"blkMntPoint": tryDecode(blkMntPoint),
134134
"mountRootfs": tryDecode(MountRootfs),
135-
"solo5BlkDev": tryDecode(solo5BlkDev),
135+
"blkDev": tryDecode(blkDev),
136136
}).WithField("source", "spec").Debug("urunc annotations")
137137

138138
return &UnikernelConfig{
@@ -145,7 +145,7 @@ func getConfigFromSpec(spec *specs.Spec) *UnikernelConfig {
145145
Block: block,
146146
BlkMntPoint: blkMntPoint,
147147
MountRootfs: MountRootfs,
148-
Solo5BlkDev: solo5BlkDev,
148+
BlkDev: blkDev,
149149
}
150150
}
151151

@@ -185,7 +185,7 @@ func getConfigFromJSON(jsonFilePath string) (*UnikernelConfig, error) {
185185
"block": tryDecode(conf.Block),
186186
"blkMntPoint": tryDecode(conf.BlkMntPoint),
187187
"mountRootfs": tryDecode(conf.MountRootfs),
188-
"solo5BlkDev": tryDecode(conf.Solo5BlkDev),
188+
"blkDev": tryDecode(conf.BlkDev),
189189
}).WithField("source", uruncJSONFilename).Debug("urunc annotations")
190190

191191
return &conf, nil
@@ -256,11 +256,11 @@ func (c *UnikernelConfig) decode() error {
256256
}
257257
c.MountRootfs = string(decoded)
258258

259-
decoded, err = base64.StdEncoding.DecodeString(c.Solo5BlkDev)
259+
decoded, err = base64.StdEncoding.DecodeString(c.BlkDev)
260260
if err != nil {
261261
return fmt.Errorf("failed to decode blkDev: %v", err)
262262
}
263-
c.Solo5BlkDev = string(decoded)
263+
c.BlkDev = string(decoded)
264264

265265
return nil
266266
}
@@ -295,8 +295,8 @@ func (c *UnikernelConfig) Map() map[string]string {
295295
if c.MountRootfs != "" {
296296
myMap[annotMountRootfs] = c.MountRootfs
297297
}
298-
if c.Solo5BlkDev != "" {
299-
myMap[annotSolo5BlkDev] = c.Solo5BlkDev
298+
if c.BlkDev != "" {
299+
myMap[annotBlkDev] = c.BlkDev
300300
}
301301

302302
return myMap

pkg/unikontainers/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestGetConfigFromSpec(t *testing.T) {
3838
annotBlock: "block1",
3939
annotBlockMntPoint: "point1",
4040
annotMountRootfs: "true",
41-
annotSolo5BlkDev: "mydisk",
41+
annotBlkDev: "mydisk",
4242
},
4343
}
4444

@@ -51,7 +51,7 @@ func TestGetConfigFromSpec(t *testing.T) {
5151
Block: "block1",
5252
BlkMntPoint: "point1",
5353
MountRootfs: "true",
54-
Solo5BlkDev: "mydisk",
54+
BlkDev: "mydisk",
5555
}
5656

5757
config := getConfigFromSpec(spec)
@@ -241,7 +241,7 @@ func TestMap(t *testing.T) {
241241
Block: "block_value",
242242
BlkMntPoint: "point_value",
243243
MountRootfs: "false",
244-
Solo5BlkDev: "blkdev_value",
244+
BlkDev: "blkdev_value",
245245
}
246246
expectedMap := map[string]string{
247247
annotCmdLine: "cmd_value",
@@ -252,7 +252,7 @@ func TestMap(t *testing.T) {
252252
annotBlock: "block_value",
253253
annotBlockMntPoint: "point_value",
254254
annotMountRootfs: "false",
255-
annotSolo5BlkDev: "blkdev_value",
255+
annotBlkDev: "blkdev_value",
256256
}
257257
resultMap := config.Map()
258258
assert.Equal(t, expectedMap, resultMap)

pkg/unikontainers/types/types.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ type UnikernelParams struct {
8686
Monitor string // The monitor where guest will execute
8787
Version string // The version of the unikernel
8888
InitrdPath string // The path to the initrd of the unikernel
89-
// Solo5BlkDevName is the Solo5 block device name declared at build time
90-
Solo5BlkDevName string
91-
Net NetDevParams
92-
Block []BlockDevParams
93-
Rootfs RootfsParams // Information about rootfs
94-
ProcConf ProcessConfig // Information for the process execution inside the guest
89+
BlkDevName string // The name of the guest block device declared at build time
90+
Net NetDevParams
91+
Block []BlockDevParams
92+
Rootfs RootfsParams // Information about rootfs
93+
ProcConf ProcessConfig // Information for the process execution inside the guest
9594
}
9695

9796
// ExecArgs holds the data required by Execve to start the VMM

pkg/unikontainers/unikernels/mirage.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import (
2424
const MirageUnikernel string = "mirage"
2525

2626
type Mirage struct {
27-
Command string
28-
Monitor string
29-
Net MirageNet
30-
Block []MirageBlock
31-
solo5BlkDevName string
27+
Command string
28+
Monitor string
29+
Net MirageNet
30+
Block []MirageBlock
31+
blkDevName string
3232
}
3333

3434
type MirageNet struct {
@@ -84,7 +84,7 @@ func (m *Mirage) MonitorBlockCli() []types.MonitorBlockArgs {
8484
// how MirageOS handles/configures them.
8585
return []types.MonitorBlockArgs{
8686
{
87-
ID: m.solo5BlkDevName,
87+
ID: m.blkDevName,
8888
Path: m.Block[0].HostPath,
8989
},
9090
}
@@ -119,10 +119,10 @@ func (m *Mirage) Init(data types.UnikernelParams) error {
119119
m.Command = strings.Join(data.CmdLine, " ")
120120
m.Monitor = data.Monitor
121121

122-
if data.Solo5BlkDevName != "" {
123-
m.solo5BlkDevName = data.Solo5BlkDevName
122+
if data.BlkDevName != "" {
123+
m.blkDevName = data.BlkDevName
124124
} else {
125-
m.solo5BlkDevName = "storage"
125+
m.blkDevName = "storage"
126126
}
127127

128128
return nil

pkg/unikontainers/unikernels/mirage_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ func TestMirageInitSubnetMask(t *testing.T) {
7474
}
7575
}
7676

77-
func TestMirageSolo5BlkDevName(t *testing.T) {
77+
func TestMirageBlkDevName(t *testing.T) {
7878
t.Run("uses block device name from annotation", func(t *testing.T) {
7979
t.Parallel()
8080
m := &Mirage{}
8181
err := m.Init(types.UnikernelParams{
82-
Monitor: "hvt",
83-
Solo5BlkDevName: "mydisk",
84-
Block: []types.BlockDevParams{{Source: "/path/to/img"}},
82+
Monitor: "hvt",
83+
BlkDevName: "mydisk",
84+
Block: []types.BlockDevParams{{Source: "/path/to/img"}},
8585
})
8686
assert.NoError(t, err)
8787
args := m.MonitorBlockCli()

pkg/unikontainers/unikontainers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,12 @@ func (u *Unikontainer) Exec(metrics m.Writer) error {
391391
// UnikernelParams
392392
// populate unikernel params
393393
unikernelParams := types.UnikernelParams{
394-
CmdLine: u.Spec.Process.Args,
395-
EnvVars: u.Spec.Process.Env,
396-
Monitor: vmmType,
397-
Version: unikernelVersion,
398-
ProcConf: procAttrs,
399-
Solo5BlkDevName: u.State.Annotations[annotSolo5BlkDev],
394+
CmdLine: u.Spec.Process.Args,
395+
EnvVars: u.Spec.Process.Env,
396+
Monitor: vmmType,
397+
Version: unikernelVersion,
398+
ProcConf: procAttrs,
399+
BlkDevName: u.State.Annotations[annotBlkDev],
400400
}
401401
if len(unikernelParams.CmdLine) == 0 {
402402
unikernelParams.CmdLine = strings.Fields(u.State.Annotations[annotCmdLine])

0 commit comments

Comments
 (0)