mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +08:00
libpod: Move setUpNetwork and getCNIPodName to networking_common.go
[NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson <dfr@rabson.org>
This commit is contained in:
@ -40,3 +40,38 @@ func (c *Container) getNetworkOptions(networkOpts map[string]types.PerNetworkOpt
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
// setUpNetwork will set up the the networks, on error it will also tear down the cni
|
||||
// networks. If rootless it will join/create the rootless network namespace.
|
||||
func (r *Runtime) setUpNetwork(ns string, opts types.NetworkOptions) (map[string]types.StatusBlock, error) {
|
||||
rootlessNetNS, err := r.GetRootlessNetNs(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var results map[string]types.StatusBlock
|
||||
setUpPod := func() error {
|
||||
results, err = r.network.Setup(ns, types.SetupOptions{NetworkOptions: opts})
|
||||
return err
|
||||
}
|
||||
// rootlessNetNS is nil if we are root
|
||||
if rootlessNetNS != nil {
|
||||
// execute the setup in the rootless net ns
|
||||
err = rootlessNetNS.Do(setUpPod)
|
||||
rootlessNetNS.Lock.Unlock()
|
||||
} else {
|
||||
err = setUpPod()
|
||||
}
|
||||
return results, err
|
||||
}
|
||||
|
||||
// getCNIPodName return the pod name (hostname) used by CNI and the dnsname plugin.
|
||||
// If we are in the pod network namespace use the pod name otherwise the container name
|
||||
func getCNIPodName(c *Container) string {
|
||||
if c.config.NetMode.IsPod() || c.IsInfra() {
|
||||
pod, err := c.runtime.state.Pod(c.PodID())
|
||||
if err == nil {
|
||||
return pod.Name()
|
||||
}
|
||||
}
|
||||
return c.Name()
|
||||
}
|
||||
|
@ -121,24 +121,6 @@ func (r *Runtime) setupNetNS(ctr *Container) error {
|
||||
return errors.New("not implemented (*Runtime) setupNetNS")
|
||||
}
|
||||
|
||||
// setUpNetwork will set up the the networks, on error it will also tear down the cni
|
||||
// networks. If rootless it will join/create the rootless network namespace.
|
||||
func (r *Runtime) setUpNetwork(ns string, opts types.NetworkOptions) (map[string]types.StatusBlock, error) {
|
||||
return r.network.Setup(ns, types.SetupOptions{NetworkOptions: opts})
|
||||
}
|
||||
|
||||
// getCNIPodName return the pod name (hostname) used by CNI and the dnsname plugin.
|
||||
// If we are in the pod network namespace use the pod name otherwise the container name
|
||||
func getCNIPodName(c *Container) string {
|
||||
if c.config.NetMode.IsPod() || c.IsInfra() {
|
||||
pod, err := c.runtime.state.Pod(c.PodID())
|
||||
if err == nil {
|
||||
return pod.Name()
|
||||
}
|
||||
}
|
||||
return c.Name()
|
||||
}
|
||||
|
||||
// Create and configure a new network namespace for a container
|
||||
func (r *Runtime) configureNetNS(ctr *Container, ctrNS *jailNetNS) (status map[string]types.StatusBlock, rerr error) {
|
||||
if err := r.exposeMachinePorts(ctr.config.PortMappings); err != nil {
|
||||
|
@ -555,41 +555,6 @@ func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) {
|
||||
return rootlessNetNS, nil
|
||||
}
|
||||
|
||||
// setUpNetwork will set up the the networks, on error it will also tear down the cni
|
||||
// networks. If rootless it will join/create the rootless network namespace.
|
||||
func (r *Runtime) setUpNetwork(ns string, opts types.NetworkOptions) (map[string]types.StatusBlock, error) {
|
||||
rootlessNetNS, err := r.GetRootlessNetNs(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var results map[string]types.StatusBlock
|
||||
setUpPod := func() error {
|
||||
results, err = r.network.Setup(ns, types.SetupOptions{NetworkOptions: opts})
|
||||
return err
|
||||
}
|
||||
// rootlessNetNS is nil if we are root
|
||||
if rootlessNetNS != nil {
|
||||
// execute the setup in the rootless net ns
|
||||
err = rootlessNetNS.Do(setUpPod)
|
||||
rootlessNetNS.Lock.Unlock()
|
||||
} else {
|
||||
err = setUpPod()
|
||||
}
|
||||
return results, err
|
||||
}
|
||||
|
||||
// getCNIPodName return the pod name (hostname) used by CNI and the dnsname plugin.
|
||||
// If we are in the pod network namespace use the pod name otherwise the container name
|
||||
func getCNIPodName(c *Container) string {
|
||||
if c.config.NetMode.IsPod() || c.IsInfra() {
|
||||
pod, err := c.runtime.state.Pod(c.PodID())
|
||||
if err == nil {
|
||||
return pod.Name()
|
||||
}
|
||||
}
|
||||
return c.Name()
|
||||
}
|
||||
|
||||
// Create and configure a new network namespace for a container
|
||||
func (r *Runtime) configureNetNS(ctr *Container, ctrNS ns.NetNS) (status map[string]types.StatusBlock, rerr error) {
|
||||
if err := r.exposeMachinePorts(ctr.config.PortMappings); err != nil {
|
||||
|
Reference in New Issue
Block a user