diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2018-10-11 10:40:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-11 10:40:37 -0700 |
commit | 6983e00a2808b29481d1cb460aab2eea1db6ef73 (patch) | |
tree | 2ee6bc368cc698e13d5dd5249061ecd2e2f93f6e /libpod/networking_linux.go | |
parent | 3c23bfca807eab55c145092c73dd8eb1e6599f38 (diff) | |
parent | 112e1402c9e2ee29a387cd84a973471c1888e4b9 (diff) | |
download | podman-6983e00a2808b29481d1cb460aab2eea1db6ef73.tar.gz podman-6983e00a2808b29481d1cb460aab2eea1db6ef73.tar.bz2 podman-6983e00a2808b29481d1cb460aab2eea1db6ef73.zip |
Merge pull request #1623 from mheon/static_ip
Add ability to specify static IPs with --ip flag
Diffstat (limited to 'libpod/networking_linux.go')
-rw-r--r-- | libpod/networking_linux.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index 17e79aa62..acb4e2a90 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -5,6 +5,7 @@ package libpod import ( "crypto/rand" "fmt" + "net" "os" "os/exec" "path/filepath" @@ -25,8 +26,8 @@ import ( ) // Get an OCICNI network config -func getPodNetwork(id, name, nsPath string, networks []string, ports []ocicni.PortMapping) ocicni.PodNetwork { - return ocicni.PodNetwork{ +func (r *Runtime) getPodNetwork(id, name, nsPath string, networks []string, ports []ocicni.PortMapping, staticIP net.IP) ocicni.PodNetwork { + 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, @@ -34,11 +35,21 @@ func getPodNetwork(id, name, nsPath string, networks []string, ports []ocicni.Po PortMappings: ports, Networks: networks, } + + if staticIP != nil { + defaultNetwork := r.netPlugin.GetDefaultNetworkName() + + network.Networks = []string{defaultNetwork} + network.NetworkConfig = make(map[string]ocicni.NetworkConfig) + network.NetworkConfig[defaultNetwork] = ocicni.NetworkConfig{IP: staticIP.String()} + } + + return network } // Create and configure a new network namespace for a container func (r *Runtime) configureNetNS(ctr *Container, ctrNS ns.NetNS) (err error) { - podNetwork := getPodNetwork(ctr.ID(), ctr.Name(), ctrNS.Path(), ctr.config.Networks, ctr.config.PortMappings) + podNetwork := r.getPodNetwork(ctr.ID(), ctr.Name(), ctrNS.Path(), ctr.config.Networks, ctr.config.PortMappings, ctr.config.StaticIP) results, err := r.netPlugin.SetUpPod(podNetwork) if err != nil { @@ -216,7 +227,7 @@ func (r *Runtime) teardownNetNS(ctr *Container) error { logrus.Debugf("Tearing down network namespace at %s for container %s", ctr.state.NetNS.Path(), ctr.ID()) - podNetwork := getPodNetwork(ctr.ID(), ctr.Name(), ctr.state.NetNS.Path(), ctr.config.Networks, ctr.config.PortMappings) + podNetwork := r.getPodNetwork(ctr.ID(), ctr.Name(), ctr.state.NetNS.Path(), ctr.config.Networks, ctr.config.PortMappings, ctr.config.StaticIP) // The network may have already been torn down, so don't fail here, just log if err := r.netPlugin.TearDownPod(podNetwork); err != nil { |