mirror of https://github.com/containers/podman.git
CNI: network create support macvlan modes
Support setting the macvlan mode with `podman network create -d macvlan --opt mode=bridge`. This will correctly set the specified macvlan mode in the cni conflist file. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
9119a578e7
commit
c20f61148c
|
@ -32,9 +32,14 @@ As rootless the `macvlan` driver has no access to the host network interfaces be
|
||||||
|
|
||||||
Set driver specific options.
|
Set driver specific options.
|
||||||
|
|
||||||
For the `bridge` driver the following options are supported: `mtu` and `vlan`.
|
All drivers accept the `mtu` option. The `mtu` option sets the Maximum Transmission Unit (MTU) and takes an integer value.
|
||||||
The `mtu` option sets the Maximum Transmission Unit (MTU) and takes an integer value.
|
|
||||||
The `vlan` option assign VLAN tag and enables vlan\_filtering. Defaults to none.
|
Additionally the `bridge` driver supports the following option:
|
||||||
|
- `vlan`: This option assign VLAN tag and enables vlan\_filtering. Defaults to none.
|
||||||
|
|
||||||
|
The `macvlan` driver supports the following options:
|
||||||
|
- `parent`: The host device which should be used for the macvlan interface. Defaults to the default route interface.
|
||||||
|
- `mode`: This options sets the specified macvlan mode on the interface. Supported values are `bridge`, `private`, `vepa`, `passthru`. Defaults to `bridge`.
|
||||||
|
|
||||||
#### **--gateway**
|
#### **--gateway**
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,10 @@ func createNetworkFromCNIConfigList(conf *libcni.NetworkConfigList, confPath str
|
||||||
network.Options["mtu"] = strconv.Itoa(macvlan.MTU)
|
network.Options["mtu"] = strconv.Itoa(macvlan.MTU)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if macvlan.Mode != "" {
|
||||||
|
network.Options["mode"] = macvlan.Mode
|
||||||
|
}
|
||||||
|
|
||||||
err = convertIPAMConfToNetwork(&network, macvlan.IPAM, confPath)
|
err = convertIPAMConfToNetwork(&network, macvlan.IPAM, confPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -237,6 +241,7 @@ func (n *cniNetwork) createCNIConfigListFromNetwork(network *types.Network, writ
|
||||||
|
|
||||||
vlan := 0
|
vlan := 0
|
||||||
mtu := 0
|
mtu := 0
|
||||||
|
macvlanMode := ""
|
||||||
for k, v := range network.Options {
|
for k, v := range network.Options {
|
||||||
switch k {
|
switch k {
|
||||||
case "mtu":
|
case "mtu":
|
||||||
|
@ -251,6 +256,12 @@ func (n *cniNetwork) createCNIConfigListFromNetwork(network *types.Network, writ
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "mode":
|
||||||
|
if !pkgutil.StringInSlice(v, []string{"", "bridge", "private", "vepa", "passthru"}) {
|
||||||
|
return nil, "", errors.Errorf("unknown macvlan mode %q", v)
|
||||||
|
}
|
||||||
|
macvlanMode = v
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, "", errors.Errorf("unsupported network option %s", k)
|
return nil, "", errors.Errorf("unsupported network option %s", k)
|
||||||
}
|
}
|
||||||
|
@ -281,7 +292,7 @@ func (n *cniNetwork) createCNIConfigListFromNetwork(network *types.Network, writ
|
||||||
}
|
}
|
||||||
|
|
||||||
case types.MacVLANNetworkDriver:
|
case types.MacVLANNetworkDriver:
|
||||||
plugins = append(plugins, newMacVLANPlugin(network.NetworkInterface, mtu, ipamConf))
|
plugins = append(plugins, newMacVLANPlugin(network.NetworkInterface, macvlanMode, mtu, ipamConf))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, "", errors.Errorf("driver %q is not supported by cni", network.Driver)
|
return nil, "", errors.Errorf("driver %q is not supported by cni", network.Driver)
|
||||||
|
|
|
@ -50,7 +50,7 @@ type hostLocalBridge struct {
|
||||||
PromiscMode bool `json:"promiscMode,omitempty"`
|
PromiscMode bool `json:"promiscMode,omitempty"`
|
||||||
Vlan int `json:"vlan,omitempty"`
|
Vlan int `json:"vlan,omitempty"`
|
||||||
IPAM ipamConfig `json:"ipam"`
|
IPAM ipamConfig `json:"ipam"`
|
||||||
Capabilities map[string]bool `json:"capabilities"`
|
Capabilities map[string]bool `json:"capabilities,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ipamConfig describes an IPAM configuration
|
// ipamConfig describes an IPAM configuration
|
||||||
|
@ -88,7 +88,8 @@ type macVLANConfig struct {
|
||||||
Master string `json:"master"`
|
Master string `json:"master"`
|
||||||
IPAM ipamConfig `json:"ipam"`
|
IPAM ipamConfig `json:"ipam"`
|
||||||
MTU int `json:"mtu,omitempty"`
|
MTU int `json:"mtu,omitempty"`
|
||||||
Capabilities map[string]bool `json:"capabilities"`
|
Mode string `json:"mode,omitempty"`
|
||||||
|
Capabilities map[string]bool `json:"capabilities,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// firewallConfig describes the firewall plugin
|
// firewallConfig describes the firewall plugin
|
||||||
|
@ -260,7 +261,7 @@ func hasDNSNamePlugin(paths []string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMacVLANPlugin creates a macvlanconfig with a given device name
|
// newMacVLANPlugin creates a macvlanconfig with a given device name
|
||||||
func newMacVLANPlugin(device string, mtu int, ipam ipamConfig) macVLANConfig {
|
func newMacVLANPlugin(device, mode string, mtu int, ipam ipamConfig) macVLANConfig {
|
||||||
m := macVLANConfig{
|
m := macVLANConfig{
|
||||||
PluginType: "macvlan",
|
PluginType: "macvlan",
|
||||||
IPAM: ipam,
|
IPAM: ipam,
|
||||||
|
@ -268,6 +269,9 @@ func newMacVLANPlugin(device string, mtu int, ipam ipamConfig) macVLANConfig {
|
||||||
if mtu > 0 {
|
if mtu > 0 {
|
||||||
m.MTU = mtu
|
m.MTU = mtu
|
||||||
}
|
}
|
||||||
|
if len(mode) > 0 {
|
||||||
|
m.Mode = mode
|
||||||
|
}
|
||||||
// CNI is supposed to use the default route if a
|
// CNI is supposed to use the default route if a
|
||||||
// parent device is not provided
|
// parent device is not provided
|
||||||
if len(device) > 0 {
|
if len(device) > 0 {
|
||||||
|
|
|
@ -250,6 +250,39 @@ var _ = Describe("Config", func() {
|
||||||
grepInFile(path, `"type": "host-local"`)
|
grepInFile(path, `"type": "host-local"`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("create macvlan config with mode", func() {
|
||||||
|
for _, mode := range []string{"bridge", "private", "vepa", "passthru"} {
|
||||||
|
network := types.Network{
|
||||||
|
Driver: "macvlan",
|
||||||
|
Options: map[string]string{
|
||||||
|
"mode": mode,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
network1, err := libpodNet.NetworkCreate(network)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(network1.Name).ToNot(BeEmpty())
|
||||||
|
path := filepath.Join(cniConfDir, network1.Name+".conflist")
|
||||||
|
Expect(path).To(BeARegularFile())
|
||||||
|
Expect(network1.Driver).To(Equal("macvlan"))
|
||||||
|
Expect(network1.Options).To(HaveKeyWithValue("mode", mode))
|
||||||
|
Expect(network1.IPAMOptions).ToNot(BeEmpty())
|
||||||
|
Expect(network1.IPAMOptions).To(HaveKeyWithValue("driver", "dhcp"))
|
||||||
|
grepInFile(path, `"mode": "`+mode+`"`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
It("create macvlan config with invalid mode", func() {
|
||||||
|
network := types.Network{
|
||||||
|
Driver: "macvlan",
|
||||||
|
Options: map[string]string{
|
||||||
|
"mode": "test",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, err := libpodNet.NetworkCreate(network)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(err.Error()).To(ContainSubstring(`unknown macvlan mode "test"`))
|
||||||
|
})
|
||||||
|
|
||||||
It("create macvlan config with invalid device", func() {
|
It("create macvlan config with invalid device", func() {
|
||||||
network := types.Network{
|
network := types.Network{
|
||||||
Driver: "macvlan",
|
Driver: "macvlan",
|
||||||
|
|
Loading…
Reference in New Issue