summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2021-11-11 16:37:13 +0100
committerPaul Holzinger <pholzing@redhat.com>2021-11-11 17:30:27 +0100
commitfe90a45e0d914723b8c26e4e9497f414312b6af0 (patch)
tree883c28f2c52c6a2c6e01848efd7ca763216ddf2c
parent8041d44c93ac46d330325cda849716f5ba2c40d9 (diff)
downloadpodman-fe90a45e0d914723b8c26e4e9497f414312b6af0.tar.gz
podman-fe90a45e0d914723b8c26e4e9497f414312b6af0.tar.bz2
podman-fe90a45e0d914723b8c26e4e9497f414312b6af0.zip
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 <pholzing@redhat.com>
-rw-r--r--cmd/podman/common/completion.go7
-rw-r--r--cmd/podman/root.go5
-rw-r--r--libpod/options.go13
-rw-r--r--libpod/runtime.go4
-rw-r--r--pkg/domain/infra/runtime_libpod.go3
5 files changed, 32 insertions, 0 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index ea453a331..4cb29383a 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -1163,6 +1163,13 @@ func AutocompleteEventBackend(cmd *cobra.Command, args []string, toComplete stri
return types, cobra.ShellCompDirectiveNoFileComp
}
+// AutocompleteNetworkBackend - Autocomplete network backend options.
+// -> "cni", "netavark"
+func AutocompleteNetworkBackend(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+ types := []string{"cni", "netavark"}
+ return types, cobra.ShellCompDirectiveNoFileComp
+}
+
// AutocompleteLogLevel - Autocomplete log level options.
// -> "trace", "debug", "info", "warn", "error", "fatal", "panic"
func AutocompleteLogLevel(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index 6da34050e..418a70e1e 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -357,6 +357,11 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
pFlags.StringVar(&cfg.Engine.Namespace, namespaceFlagName, cfg.Engine.Namespace, "Set the libpod namespace, used to create separate views of the containers and pods on the system")
_ = cmd.RegisterFlagCompletionFunc(namespaceFlagName, completion.AutocompleteNone)
+ networkBackendFlagName := "network-backend"
+ pFlags.StringVar(&cfg.Network.NetworkBackend, networkBackendFlagName, cfg.Network.NetworkBackend, `Network backend to use ("cni"|"netavark")`)
+ _ = cmd.RegisterFlagCompletionFunc(networkBackendFlagName, common.AutocompleteNetworkBackend)
+ pFlags.MarkHidden(networkBackendFlagName)
+
rootFlagName := "root"
pFlags.StringVar(&cfg.Engine.StaticDir, rootFlagName, "", "Path to the root directory in which data, including images, is stored")
_ = cmd.RegisterFlagCompletionFunc(rootFlagName, completion.AutocompleteDefault)
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)
diff --git a/pkg/domain/infra/runtime_libpod.go b/pkg/domain/infra/runtime_libpod.go
index 7ec6135ee..cfb674b6d 100644
--- a/pkg/domain/infra/runtime_libpod.go
+++ b/pkg/domain/infra/runtime_libpod.go
@@ -200,6 +200,9 @@ func getRuntime(ctx context.Context, fs *flag.FlagSet, opts *engineOpts) (*libpo
if fs.Changed("network-cmd-path") {
options = append(options, libpod.WithNetworkCmdPath(cfg.Engine.NetworkCmdPath))
}
+ if fs.Changed("network-backend") {
+ options = append(options, libpod.WithNetworkBackend(cfg.Network.NetworkBackend))
+ }
if fs.Changed("events-backend") {
options = append(options, libpod.WithEventsLogger(cfg.Engine.EventsLogger))