summaryrefslogtreecommitdiff
path: root/libpod/networking_linux.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-11-20 12:48:30 -0500
committerMatthew Heon <matthew.heon@pm.me>2019-11-26 09:56:14 -0500
commit01ae532a899997cb4c930003d4f2f5d5820ba7d7 (patch)
tree6abe3cfe142b406334d8867eaaa2f24670687301 /libpod/networking_linux.go
parentaef38585ed313d1096c1fa4f6281f36e5e47422b (diff)
downloadpodman-01ae532a899997cb4c930003d4f2f5d5820ba7d7.tar.gz
podman-01ae532a899997cb4c930003d4f2f5d5820ba7d7.tar.bz2
podman-01ae532a899997cb4c930003d4f2f5d5820ba7d7.zip
Allow --ip and --mac to be set when joining a CNI net
These only conflict when joining more than one network. We can still set a single CNI network and set a static IP and/or static MAC. Fixes #4500 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/networking_linux.go')
-rw-r--r--libpod/networking_linux.go34
1 files changed, 25 insertions, 9 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index cba7b636a..a68338dbb 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -29,19 +29,40 @@ import (
// Get an OCICNI network config
func (r *Runtime) getPodNetwork(id, name, nsPath string, networks []string, ports []ocicni.PortMapping, staticIP net.IP, staticMAC net.HardwareAddr) ocicni.PodNetwork {
- defaultNetwork := r.netPlugin.GetDefaultNetworkName()
+ var networkKey string
+ if len(networks) > 0 {
+ // This is inconsistent for >1 network, but it's probably the
+ // best we can do.
+ networkKey = networks[0]
+ } else {
+ networkKey = r.netPlugin.GetDefaultNetworkName()
+ }
network := ocicni.PodNetwork{
Name: name,
Namespace: name, // TODO is there something else we should put here? We don't know about Kube namespaces
ID: id,
NetNS: nsPath,
RuntimeConfig: map[string]ocicni.RuntimeConfig{
- defaultNetwork: {PortMappings: ports},
+ networkKey: {PortMappings: ports},
},
}
+ // If we have extra networks, add them
+ if len(networks) > 0 {
+ network.Networks = make([]ocicni.NetAttachment, len(networks))
+ for i, netName := range networks {
+ network.Networks[i].Name = netName
+ }
+ }
+
if staticIP != nil || staticMAC != nil {
- network.Networks = []ocicni.NetAttachment{{Name: defaultNetwork}}
+ // For static IP or MAC, we need to populate networks even if
+ // it's just the default.
+ if len(networks) == 0 {
+ // If len(networks) == 0 this is guaranteed to be the
+ // default network.
+ network.Networks = []ocicni.NetAttachment{{Name: networkKey}}
+ }
var rt ocicni.RuntimeConfig = ocicni.RuntimeConfig{PortMappings: ports}
if staticIP != nil {
rt.IP = staticIP.String()
@@ -50,12 +71,7 @@ func (r *Runtime) getPodNetwork(id, name, nsPath string, networks []string, port
rt.MAC = staticMAC.String()
}
network.RuntimeConfig = map[string]ocicni.RuntimeConfig{
- defaultNetwork: rt,
- }
- } else {
- network.Networks = make([]ocicni.NetAttachment, len(networks))
- for i, netName := range networks {
- network.Networks[i].Name = netName
+ networkKey: rt,
}
}