From fe90a45e0d914723b8c26e4e9497f414312b6af0 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 11 Nov 2021 16:37:13 +0100 Subject: Add flag to overwrite network backend from config To make testing easier we can overwrite the network backend with the global `--network-backend` option. Signed-off-by: Paul Holzinger --- libpod/options.go | 13 +++++++++++++ libpod/runtime.go | 4 ++++ 2 files changed, 17 insertions(+) (limited to 'libpod') diff --git a/libpod/options.go b/libpod/options.go index 250b16556..0cc4c784c 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -227,6 +227,19 @@ func WithNetworkCmdPath(path string) RuntimeOption { } } +// WithNetworkBackend specifies the name of the network backend. +func WithNetworkBackend(name string) RuntimeOption { + return func(rt *Runtime) error { + if rt.valid { + return define.ErrRuntimeFinalized + } + + rt.config.Network.NetworkBackend = name + + return nil + } +} + // WithCgroupManager specifies the manager implementation name which is used to // handle cgroups for containers. // Current valid values are "cgroupfs" and "systemd". diff --git a/libpod/runtime.go b/libpod/runtime.go index 71bfaff9a..c751df79b 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -499,6 +499,10 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) { if err != nil { return errors.Wrapf(err, "could not create network interface") } + if runtime.config.Network.NetworkBackend == "" { + // set backend to cni so that podman info can display it + runtime.config.Network.NetworkBackend = "cni" + } case "netavark": netavarkBin, err := runtime.config.FindHelperBinary("netavark", false) -- cgit v1.2.3-54-g00ecf