mirror of
https://github.com/containers/podman.git
synced 2025-07-15 03:02:52 +08:00
select network backend based on config
You can change the network backendend in containers.conf supported values are "cni" and "netavark". Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -110,6 +110,10 @@ func NewNetworkInterface(conf InitConfig) (types.ContainerNetwork, error) {
|
||||
ipamdbPath = filepath.Join(ipamdbPath, "ipam.db")
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(conf.NetworkConfigDir, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
n := &netavarkNetwork{
|
||||
networkConfigDir: conf.NetworkConfigDir,
|
||||
netavarkBinary: conf.NetavarkBinary,
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"github.com/containers/podman/v3/libpod/events"
|
||||
"github.com/containers/podman/v3/libpod/lock"
|
||||
"github.com/containers/podman/v3/libpod/network/cni"
|
||||
"github.com/containers/podman/v3/libpod/network/netavark"
|
||||
nettypes "github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/libpod/plugin"
|
||||
"github.com/containers/podman/v3/libpod/shutdown"
|
||||
@ -483,16 +484,41 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
|
||||
}
|
||||
}
|
||||
|
||||
netInterface, err := cni.NewCNINetworkInterface(cni.InitConfig{
|
||||
CNIConfigDir: runtime.config.Network.NetworkConfigDir,
|
||||
CNIPluginDirs: runtime.config.Network.CNIPluginDirs,
|
||||
DefaultNetwork: runtime.config.Network.DefaultNetwork,
|
||||
DefaultSubnet: runtime.config.Network.DefaultSubnet,
|
||||
IsMachine: runtime.config.Engine.MachineEnabled,
|
||||
LockFile: filepath.Join(runtime.config.Network.NetworkConfigDir, "cni.lock"),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create network interface")
|
||||
var netInterface nettypes.ContainerNetwork
|
||||
|
||||
switch runtime.config.Network.NetworkBackend {
|
||||
case "", "cni":
|
||||
netInterface, err = cni.NewCNINetworkInterface(cni.InitConfig{
|
||||
CNIConfigDir: runtime.config.Network.NetworkConfigDir,
|
||||
CNIPluginDirs: runtime.config.Network.CNIPluginDirs,
|
||||
DefaultNetwork: runtime.config.Network.DefaultNetwork,
|
||||
DefaultSubnet: runtime.config.Network.DefaultSubnet,
|
||||
IsMachine: runtime.config.Engine.MachineEnabled,
|
||||
LockFile: filepath.Join(runtime.config.Network.NetworkConfigDir, "cni.lock"),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create network interface")
|
||||
}
|
||||
|
||||
case "netavark":
|
||||
netavarkBin, err := runtime.config.FindHelperBinary("netavark", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
netInterface, err = netavark.NewNetworkInterface(netavark.InitConfig{
|
||||
NetavarkBinary: netavarkBin,
|
||||
NetworkConfigDir: filepath.Join(runtime.config.Engine.StaticDir, "networks"),
|
||||
DefaultNetwork: runtime.config.Network.DefaultNetwork,
|
||||
DefaultSubnet: runtime.config.Network.DefaultSubnet,
|
||||
IsMachine: runtime.config.Engine.MachineEnabled,
|
||||
LockFile: filepath.Join(runtime.config.Network.NetworkConfigDir, "netavark.lock"),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create network interface")
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unsupported network backend %q, check network_backend in containers.conf", runtime.config.Network.NetworkBackend)
|
||||
}
|
||||
|
||||
runtime.network = netInterface
|
||||
|
Reference in New Issue
Block a user