NetworkBackend returns the network backend name and interface It returns either the CNI or netavark backend depending on what is set in the config. If the the backend is set to "" we will automatically assign the backend on the following conditions: 1. read ${graphroot}/defaultNetworkBackend 2. find
(store storage.Store, conf *config.Config, syslog bool)
| 45 | // 2. find netavark binary (if not installed use CNI) |
| 46 | // 3. check containers, images and CNI networks and if there are some we have an existing install and should continue to use CNI |
| 47 | func NetworkBackend(store storage.Store, conf *config.Config, syslog bool) (types.NetworkBackend, types.ContainerNetwork, error) { |
| 48 | backend := types.NetworkBackend(conf.Network.NetworkBackend) |
| 49 | if backend == "" { |
| 50 | var err error |
| 51 | backend, err = defaultNetworkBackend(store, conf) |
| 52 | if err != nil { |
| 53 | return "", nil, fmt.Errorf("failed to get default network backend: %w", err) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | switch backend { |
| 58 | case types.Netavark: |
| 59 | netavarkBin, err := conf.FindHelperBinary(netavarkBinary, false) |
| 60 | if err != nil { |
| 61 | return "", nil, err |
| 62 | } |
| 63 | |
| 64 | aardvarkBin, err := conf.FindHelperBinary(aardvarkBinary, false) |
| 65 | if err != nil { |
| 66 | // this is not a fatal error we can still use netavark without dns |
| 67 | logrus.Warnf("%s binary not found, container dns will not be enabled", aardvarkBin) |
| 68 | } |
| 69 | |
| 70 | confDir := conf.Network.NetworkConfigDir |
| 71 | if confDir == "" { |
| 72 | confDir = getDefaultNetavarkConfigDir(store) |
| 73 | } |
| 74 | |
| 75 | // We cannot use the runroot for rootful since the network namespace is shared for all |
| 76 | // libpod instances they also have to share the same ipam db. |
| 77 | // For rootless we have our own network namespace per libpod instances, |
| 78 | // so this is not a problem there. |
| 79 | runDir := netavarkRunDir |
| 80 | if unshare.IsRootless() { |
| 81 | runDir = filepath.Join(store.RunRoot(), "networks") |
| 82 | } |
| 83 | |
| 84 | netInt, err := netavark.NewNetworkInterface(&netavark.InitConfig{ |
| 85 | NetworkConfigDir: confDir, |
| 86 | NetworkRunDir: runDir, |
| 87 | NetavarkBinary: netavarkBin, |
| 88 | AardvarkBinary: aardvarkBin, |
| 89 | DefaultNetwork: conf.Network.DefaultNetwork, |
| 90 | DefaultSubnet: conf.Network.DefaultSubnet, |
| 91 | Syslog: syslog, |
| 92 | }) |
| 93 | return types.Netavark, netInt, err |
| 94 | case types.CNI: |
| 95 | netInt, err := getCniInterface(conf) |
| 96 | return types.CNI, netInt, err |
| 97 | |
| 98 | default: |
| 99 | return "", nil, fmt.Errorf("unsupported network backend %q, check network_backend in containers.conf", backend) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func defaultNetworkBackend(store storage.Store, conf *config.Config) (backend types.NetworkBackend, err error) { |
| 104 | // read defaultNetworkBackend file |
nothing calls this directly
no test coverage detected
searching dependent graphs…