-
Notifications
You must be signed in to change notification settings - Fork 134
fix: use annotation for MirageOS net device name #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ const ( | |
| annotBlock = "com.urunc.unikernel.block" | ||
| annotBlockMntPoint = "com.urunc.unikernel.blkMntPoint" | ||
| annotMountRootfs = "com.urunc.unikernel.mountRootfs" | ||
| annotNetDev = "com.urunc.unikernel.netDev" | ||
| ) | ||
|
|
||
| // A UnikernelConfig struct holds the info provided by bima image on how to execute our unikernel | ||
|
|
@@ -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"` | ||
| NetDev string `json:"com.urunc.unikernel.netDev,omitempty"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| // validate checks if the mandatory configuration fields are present. | ||
|
|
@@ -127,6 +129,7 @@ func getConfigFromSpec(spec *specs.Spec) *UnikernelConfig { | |
| block := spec.Annotations[annotBlock] | ||
| blkMntPoint := spec.Annotations[annotBlockMntPoint] | ||
| MountRootfs := spec.Annotations[annotMountRootfs] | ||
| netDev := spec.Annotations[annotNetDev] | ||
| uniklog.WithFields(logrus.Fields{ | ||
| "unikernelType": tryDecode(unikernelType), | ||
| "unikernelVersion": tryDecode(unikernelVersion), | ||
|
|
@@ -137,6 +140,7 @@ func getConfigFromSpec(spec *specs.Spec) *UnikernelConfig { | |
| "block": tryDecode(block), | ||
| "blkMntPoint": tryDecode(blkMntPoint), | ||
| "mountRootfs": tryDecode(MountRootfs), | ||
| "netDev": tryDecode(netDev), | ||
| }).WithField("source", "spec").Debug("urunc annotations") | ||
|
|
||
| return &UnikernelConfig{ | ||
|
|
@@ -149,6 +153,7 @@ func getConfigFromSpec(spec *specs.Spec) *UnikernelConfig { | |
| Block: block, | ||
| BlkMntPoint: blkMntPoint, | ||
| MountRootfs: MountRootfs, | ||
| NetDev: netDev, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -188,6 +193,7 @@ func getConfigFromJSON(jsonFilePath string) (*UnikernelConfig, error) { | |
| "block": tryDecode(conf.Block), | ||
| "blkMntPoint": tryDecode(conf.BlkMntPoint), | ||
| "mountRootfs": tryDecode(conf.MountRootfs), | ||
| "netDev": tryDecode(conf.NetDev), | ||
| }).WithField("source", uruncJSONFilename).Debug("urunc annotations") | ||
|
|
||
| return &conf, nil | ||
|
|
@@ -258,6 +264,12 @@ func (c *UnikernelConfig) decode() error { | |
| } | ||
| c.MountRootfs = string(decoded) | ||
|
|
||
| decoded, err = base64.StdEncoding.DecodeString(c.NetDev) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to decode netDev: %v", err) | ||
| } | ||
| c.NetDev = string(decoded) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -291,6 +303,9 @@ func (c *UnikernelConfig) Map() map[string]string { | |
| if c.MountRootfs != "" { | ||
| myMap[annotMountRootfs] = c.MountRootfs | ||
| } | ||
| if c.NetDev != "" { | ||
| myMap[annotNetDev] = c.NetDev | ||
| } | ||
|
|
||
| return myMap | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| netDevName string | ||
| } | ||
|
|
||
| type MirageNet struct { | ||
|
|
@@ -57,8 +58,9 @@ func (m *Mirage) SupportsFS(_ string) bool { | |
| func (m *Mirage) MonitorNetCli(ifName string, mac string) string { | ||
| switch m.Monitor { | ||
| case "hvt", "spt": | ||
| netOption := "--net:service=" + ifName | ||
| netOption += " --net-mac:service=" + mac | ||
| name := m.netDevName | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No reason for this assignment. |
||
| netOption := "--net:" + name + "=" + ifName | ||
| netOption += " --net-mac:" + name + "=" + mac | ||
| return netOption | ||
| default: | ||
| return "" | ||
|
|
@@ -99,8 +101,13 @@ func (m *Mirage) MonitorCli() types.MonitorCliArgs { | |
| func (m *Mirage) Init(data types.UnikernelParams) error { | ||
| // if Mask is empty, there is no network support | ||
| if data.Net.Mask != "" { | ||
| m.Net.Address = "--ipv4=" + data.Net.IP + "/24" | ||
| m.Net.Gateway = "--ipv4-gateway=" + data.Net.Gateway | ||
| if data.NetDevName != "" && data.NetDevName != "service" { | ||
| m.Net.Address = "--" + data.NetDevName + "-ipv4=" + data.Net.IP + "/24" | ||
| m.Net.Gateway = "--" + data.NetDevName + "-ipv4-gateway=" + data.Net.Gateway | ||
| } else { | ||
| m.Net.Address = "--ipv4=" + data.Net.IP + "/24" | ||
| m.Net.Gateway = "--ipv4-gateway=" + data.Net.Gateway | ||
| } | ||
| } | ||
|
Comment on lines
102
to
115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Mirage you can "group" parameters to network devices. What this effectively means is that you can add a prefix to the command line options (often the interface name). An example is for an interface So to configure extra interfaces there's no good way to do it, but I think a decent heuristic is for each interface that is not called "service" to use Finally, you can construct unikernels in whatever way you want so you are never guaranteed that the unikernel accepts these options.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah makes sense, pushed it as a new commit
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add this as a comment to explain the cli argument construction? It is useful information. |
||
| m.Block = make([]MirageBlock, 0, len(data.Block)) | ||
| for _, blk := range data.Block { | ||
|
|
@@ -114,6 +121,12 @@ func (m *Mirage) Init(data types.UnikernelParams) error { | |
| m.Command = strings.Join(data.CmdLine, " ") | ||
| m.Monitor = data.Monitor | ||
|
|
||
| if data.NetDevName != "" { | ||
| m.netDevName = data.NetDevName | ||
| } else { | ||
| m.netDevName = "service" | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) 2023-2026, Nubificus LTD | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package unikernels | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/urunc-dev/urunc/pkg/unikontainers/types" | ||
| ) | ||
|
|
||
| func TestMirageNetDevName(t *testing.T) { | ||
| t.Run("uses net device name from annotation", func(t *testing.T) { | ||
| t.Parallel() | ||
| m := &Mirage{} | ||
| err := m.Init(types.UnikernelParams{Monitor: "hvt", NetDevName: "mynetdev"}) | ||
| assert.NoError(t, err) | ||
| cli := m.MonitorNetCli("tap0", "aa:bb:cc:dd:ee:ff") | ||
| assert.Contains(t, cli, "--net:mynetdev=tap0") | ||
| assert.Contains(t, cli, "--net-mac:mynetdev=aa:bb:cc:dd:ee:ff") | ||
| }) | ||
|
|
||
| t.Run("falls back to service when annotation is absent", func(t *testing.T) { | ||
| t.Parallel() | ||
| m := &Mirage{} | ||
| err := m.Init(types.UnikernelParams{Monitor: "hvt"}) | ||
| assert.NoError(t, err) | ||
| cli := m.MonitorNetCli("tap0", "aa:bb:cc:dd:ee:ff") | ||
| assert.Contains(t, cli, "--net:service=tap0") | ||
| assert.Contains(t, cli, "--net-mac:service=aa:bb:cc:dd:ee:ff") | ||
| }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is Solo5 specific, I would suggest to add a Solo5 prefix (e.g. Solo5NetDevName).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefixed the Go identifiers as suggested. I'm assuming you want the annotation key to stay as com.urunc.unikernel.netDev?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I meant the annotation key to have a prefix