mirror of
https://github.com/containers/podman.git
synced 2025-07-15 03:02:52 +08:00
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>
This commit is contained in:
@ -1163,6 +1163,13 @@ func AutocompleteEventBackend(cmd *cobra.Command, args []string, toComplete stri
|
|||||||
return types, cobra.ShellCompDirectiveNoFileComp
|
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.
|
// AutocompleteLogLevel - Autocomplete log level options.
|
||||||
// -> "trace", "debug", "info", "warn", "error", "fatal", "panic"
|
// -> "trace", "debug", "info", "warn", "error", "fatal", "panic"
|
||||||
func AutocompleteLogLevel(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func AutocompleteLogLevel(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
@ -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")
|
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)
|
_ = 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"
|
rootFlagName := "root"
|
||||||
pFlags.StringVar(&cfg.Engine.StaticDir, rootFlagName, "", "Path to the root directory in which data, including images, is stored")
|
pFlags.StringVar(&cfg.Engine.StaticDir, rootFlagName, "", "Path to the root directory in which data, including images, is stored")
|
||||||
_ = cmd.RegisterFlagCompletionFunc(rootFlagName, completion.AutocompleteDefault)
|
_ = cmd.RegisterFlagCompletionFunc(rootFlagName, completion.AutocompleteDefault)
|
||||||
|
@ -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
|
// WithCgroupManager specifies the manager implementation name which is used to
|
||||||
// handle cgroups for containers.
|
// handle cgroups for containers.
|
||||||
// Current valid values are "cgroupfs" and "systemd".
|
// Current valid values are "cgroupfs" and "systemd".
|
||||||
|
@ -499,6 +499,10 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not create network interface")
|
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":
|
case "netavark":
|
||||||
netavarkBin, err := runtime.config.FindHelperBinary("netavark", false)
|
netavarkBin, err := runtime.config.FindHelperBinary("netavark", false)
|
||||||
|
@ -200,6 +200,9 @@ func getRuntime(ctx context.Context, fs *flag.FlagSet, opts *engineOpts) (*libpo
|
|||||||
if fs.Changed("network-cmd-path") {
|
if fs.Changed("network-cmd-path") {
|
||||||
options = append(options, libpod.WithNetworkCmdPath(cfg.Engine.NetworkCmdPath))
|
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") {
|
if fs.Changed("events-backend") {
|
||||||
options = append(options, libpod.WithEventsLogger(cfg.Engine.EventsLogger))
|
options = append(options, libpod.WithEventsLogger(cfg.Engine.EventsLogger))
|
||||||
|
Reference in New Issue
Block a user