Skip to content
Open
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
15 changes: 15 additions & 0 deletions pkg/unikontainers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
annotBlock = "com.urunc.unikernel.block"
annotBlockMntPoint = "com.urunc.unikernel.blkMntPoint"
annotMountRootfs = "com.urunc.unikernel.mountRootfs"
annotSolo5BlkDev = "com.urunc.unikernel.blkDev"
)

// A UnikernelConfig struct holds the info provided by bima image on how to execute our unikernel
Expand All @@ -58,6 +59,7 @@ type UnikernelConfig struct {
Block string `json:"com.urunc.unikernel.block,omitempty"`
BlkMntPoint string `json:"com.urunc.unikernel.blkMntPoint,omitempty"`
MountRootfs string `json:"com.urunc.unikernel.mountRootfs"`
Solo5BlkDev string `json:"com.urunc.unikernel.blkDev,omitempty"`
}

// validate checks if the mandatory configuration fields are present.
Expand Down Expand Up @@ -119,6 +121,7 @@ func getConfigFromSpec(spec *specs.Spec) *UnikernelConfig {
block := spec.Annotations[annotBlock]
blkMntPoint := spec.Annotations[annotBlockMntPoint]
MountRootfs := spec.Annotations[annotMountRootfs]
solo5BlkDev := spec.Annotations[annotSolo5BlkDev]
uniklog.WithFields(logrus.Fields{
"unikernelType": tryDecode(unikernelType),
"unikernelVersion": tryDecode(unikernelVersion),
Expand All @@ -129,6 +132,7 @@ func getConfigFromSpec(spec *specs.Spec) *UnikernelConfig {
"block": tryDecode(block),
"blkMntPoint": tryDecode(blkMntPoint),
"mountRootfs": tryDecode(MountRootfs),
"solo5BlkDev": tryDecode(solo5BlkDev),
}).WithField("source", "spec").Debug("urunc annotations")

return &UnikernelConfig{
Expand All @@ -141,6 +145,7 @@ func getConfigFromSpec(spec *specs.Spec) *UnikernelConfig {
Block: block,
BlkMntPoint: blkMntPoint,
MountRootfs: MountRootfs,
Solo5BlkDev: solo5BlkDev,
}
}

Expand Down Expand Up @@ -180,6 +185,7 @@ func getConfigFromJSON(jsonFilePath string) (*UnikernelConfig, error) {
"block": tryDecode(conf.Block),
"blkMntPoint": tryDecode(conf.BlkMntPoint),
"mountRootfs": tryDecode(conf.MountRootfs),
"solo5BlkDev": tryDecode(conf.Solo5BlkDev),
}).WithField("source", uruncJSONFilename).Debug("urunc annotations")

return &conf, nil
Expand Down Expand Up @@ -250,6 +256,12 @@ func (c *UnikernelConfig) decode() error {
}
c.MountRootfs = string(decoded)

decoded, err = base64.StdEncoding.DecodeString(c.Solo5BlkDev)
if err != nil {
return fmt.Errorf("failed to decode blkDev: %v", err)
}
c.Solo5BlkDev = string(decoded)

return nil
}

Expand Down Expand Up @@ -283,6 +295,9 @@ func (c *UnikernelConfig) Map() map[string]string {
if c.MountRootfs != "" {
myMap[annotMountRootfs] = c.MountRootfs
}
if c.Solo5BlkDev != "" {
myMap[annotSolo5BlkDev] = c.Solo5BlkDev
}

return myMap
}
4 changes: 4 additions & 0 deletions pkg/unikontainers/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestGetConfigFromSpec(t *testing.T) {
annotBlock: "block1",
annotBlockMntPoint: "point1",
annotMountRootfs: "true",
annotSolo5BlkDev: "mydisk",
},
}

Expand All @@ -50,6 +51,7 @@ func TestGetConfigFromSpec(t *testing.T) {
Block: "block1",
BlkMntPoint: "point1",
MountRootfs: "true",
Solo5BlkDev: "mydisk",
}

config := getConfigFromSpec(spec)
Expand Down Expand Up @@ -239,6 +241,7 @@ func TestMap(t *testing.T) {
Block: "block_value",
BlkMntPoint: "point_value",
MountRootfs: "false",
Solo5BlkDev: "blkdev_value",
}
expectedMap := map[string]string{
annotCmdLine: "cmd_value",
Expand All @@ -249,6 +252,7 @@ func TestMap(t *testing.T) {
annotBlock: "block_value",
annotBlockMntPoint: "point_value",
annotMountRootfs: "false",
annotSolo5BlkDev: "blkdev_value",
}
resultMap := config.Map()
assert.Equal(t, expectedMap, resultMap)
Expand Down
10 changes: 6 additions & 4 deletions pkg/unikontainers/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ type UnikernelParams struct {
Monitor string // The monitor where guest will execute
Version string // The version of the unikernel
InitrdPath string // The path to the initrd of the unikernel
Net NetDevParams
Block []BlockDevParams
Rootfs RootfsParams // Information about rootfs
ProcConf ProcessConfig // Information for the process execution inside the guest
// Solo5BlkDevName is the Solo5 block device name declared at build time
Solo5BlkDevName string
Net NetDevParams
Block []BlockDevParams
Rootfs RootfsParams // Information about rootfs
ProcConf ProcessConfig // Information for the process execution inside the guest
}

// ExecArgs holds the data required by Execve to start the VMM
Expand Down
17 changes: 12 additions & 5 deletions pkg/unikontainers/unikernels/mirage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
const MirageUnikernel string = "mirage"

type Mirage struct {
Command string
Monitor string
Net MirageNet
Block []MirageBlock
Command string
Monitor string
Net MirageNet
Block []MirageBlock
solo5BlkDevName string
}

type MirageNet struct {
Expand Down Expand Up @@ -83,7 +84,7 @@ func (m *Mirage) MonitorBlockCli() []types.MonitorBlockArgs {
// how MirageOS handles/configures them.
return []types.MonitorBlockArgs{
{
ID: "storage",
ID: m.solo5BlkDevName,
Path: m.Block[0].HostPath,
},
}
Expand Down Expand Up @@ -118,6 +119,12 @@ func (m *Mirage) Init(data types.UnikernelParams) error {
m.Command = strings.Join(data.CmdLine, " ")
m.Monitor = data.Monitor

if data.Solo5BlkDevName != "" {
m.solo5BlkDevName = data.Solo5BlkDevName
} else {
m.solo5BlkDevName = "storage"
}

return nil
}

Expand Down
30 changes: 30 additions & 0 deletions pkg/unikontainers/unikernels/mirage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,33 @@ func TestMirageInitSubnetMask(t *testing.T) {
})
}
}

func TestMirageSolo5BlkDevName(t *testing.T) {
t.Run("uses block device name from annotation", func(t *testing.T) {
t.Parallel()
m := &Mirage{}
err := m.Init(types.UnikernelParams{
Monitor: "hvt",
Solo5BlkDevName: "mydisk",
Block: []types.BlockDevParams{{Source: "/path/to/img"}},
})
assert.NoError(t, err)
args := m.MonitorBlockCli()
assert.Len(t, args, 1)
assert.Equal(t, "mydisk", args[0].ID)
assert.Equal(t, "/path/to/img", args[0].Path)
})

t.Run("falls back to storage when annotation is absent", func(t *testing.T) {
t.Parallel()
m := &Mirage{}
err := m.Init(types.UnikernelParams{
Monitor: "hvt",
Block: []types.BlockDevParams{{Source: "/path/to/img"}},
})
assert.NoError(t, err)
args := m.MonitorBlockCli()
assert.Len(t, args, 1)
assert.Equal(t, "storage", args[0].ID)
})
}
11 changes: 6 additions & 5 deletions pkg/unikontainers/unikontainers.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,12 @@ func (u *Unikontainer) Exec(metrics m.Writer) error {
// UnikernelParams
// populate unikernel params
unikernelParams := types.UnikernelParams{
CmdLine: u.Spec.Process.Args,
EnvVars: u.Spec.Process.Env,
Monitor: vmmType,
Version: unikernelVersion,
ProcConf: procAttrs,
CmdLine: u.Spec.Process.Args,
EnvVars: u.Spec.Process.Env,
Monitor: vmmType,
Version: unikernelVersion,
ProcConf: procAttrs,
Solo5BlkDevName: u.State.Annotations[annotSolo5BlkDev],
}
if len(unikernelParams.CmdLine) == 0 {
unikernelParams.CmdLine = strings.Fields(u.State.Annotations[annotCmdLine])
Expand Down