Skip to content
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

RFC: Add support for optional runtime hint using network options #1697

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions drivers/macvlan/macvlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type endpoint struct {
srcName string
dbIndex uint64
dbExists bool
runtime string
}

type network struct {
Expand Down
13 changes: 13 additions & 0 deletions drivers/macvlan/macvlan_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
return err
}
}

// disallow portmapping -p
if opt, ok := epOptions[netlabel.PortMap]; ok {
if _, ok := opt.([]types.PortBinding); ok {
Expand All @@ -57,6 +58,18 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
}
}

// Setup the runtime to default to namespace, override if specified
ep.runtime = "namespace"
if opt, ok := epOptions["runtime"]; ok {
if runtime, ok := opt.(string); ok {
if runtime != "namespace" && runtime != "vm" {
logrus.Warnf("driver does not support [%s] runtime", runtime)
} else {
ep.runtime = runtime
}
}
}

if err := d.storeUpdate(ep); err != nil {
return fmt.Errorf("failed to save macvlan endpoint %s to store: %v", ep.id[0:7], err)
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/macvlan/macvlan_joinleave.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
return fmt.Errorf("error generating an interface name: %s", err)
}
// create the netlink macvlan interface
vethName, err := createMacVlan(containerIfName, n.config.Parent, n.config.MacvlanMode)
vethName, err := createMacVlan(containerIfName, n.config.Parent, n.config.MacvlanMode, endpoint.runtime)
if err != nil {
return err
}
Expand Down
50 changes: 35 additions & 15 deletions drivers/macvlan/macvlan_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const (
macvlanMajorVer = 9 // minimum macvlan major kernel support
)

// Create the macvlan slave specifying the source name
func createMacVlan(containerIfName, parent, macvlanMode string) (string, error) {
// Create the macvlan slave specifying the source name and the runtime type
func createMacVlan(containerIfName, parent, macvlanMode, runtime string) (string, error) {
// Set the macvlan mode. Default is bridge mode
mode, err := setMacVlanMode(macvlanMode)
if err != nil {
Expand All @@ -32,20 +32,40 @@ func createMacVlan(containerIfName, parent, macvlanMode string) (string, error)
if err != nil {
return "", fmt.Errorf("error occoured looking up the %s parent iface %s error: %s", macvlanType, parent, err)
}
// Create a macvlan link
macvlan := &netlink.Macvlan{
LinkAttrs: netlink.LinkAttrs{
Name: containerIfName,
ParentIndex: parentLink.Attrs().Index,
},
Mode: mode,
}
if err := ns.NlHandle().LinkAdd(macvlan); err != nil {
// If a user creates a macvlan and ipvlan on same parent, only one slave iface can be active at a time.
return "", fmt.Errorf("failed to create the %s port: %v", macvlanType, err)
}

return macvlan.Attrs().Name, nil
if runtime == "vm" {
// Create a macvtap link
macvtap := &netlink.Macvtap{
Macvlan: netlink.Macvlan{
LinkAttrs: netlink.LinkAttrs{
Name: containerIfName,
ParentIndex: parentLink.Attrs().Index,
},
Mode: mode,
},
}

if err := ns.NlHandle().LinkAdd(macvtap); err != nil {
return "", fmt.Errorf("failed to create the %s port: %v", macvlanType, err)
}

return macvtap.Attrs().Name, nil
} else {
// Create a macvlan link
macvlan := &netlink.Macvlan{
LinkAttrs: netlink.LinkAttrs{
Name: containerIfName,
ParentIndex: parentLink.Attrs().Index,
},
Mode: mode,
}
if err := ns.NlHandle().LinkAdd(macvlan); err != nil {
// If a user creates a macvlan and ipvlan on same parent, only one slave iface can be active at a time.
return "", fmt.Errorf("failed to create the %s port: %v", macvlanType, err)
}

return macvlan.Attrs().Name, nil
}
}

// setMacVlanMode setter for one of the four macvlan port types
Expand Down
2 changes: 2 additions & 0 deletions drivers/macvlan/macvlan_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func (ep *endpoint) MarshalJSON() ([]byte, error) {
epMap["id"] = ep.id
epMap["nid"] = ep.nid
epMap["SrcName"] = ep.srcName
epMap["runtime"] = ep.runtime
if len(ep.mac) != 0 {
epMap["MacAddress"] = ep.mac.String()
}
Expand Down Expand Up @@ -295,6 +296,7 @@ func (ep *endpoint) UnmarshalJSON(b []byte) error {
ep.id = epMap["id"].(string)
ep.nid = epMap["nid"].(string)
ep.srcName = epMap["SrcName"].(string)
ep.runtime = epMap["runtime"].(string)

return nil
}
Expand Down