From e77f370f868dce6dd5b1457d70bf1d367f24e26c Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Thu, 2 Mar 2023 11:41:36 +0100 Subject: [PATCH] sqlite: add a hidden --db-backend flag Add a hidden flag to set the database backend and plumb it into podman-info. Further add a system test to make sure the flag and the info output are working properly. Note that the test may need to be changed once we settled on how to test the sqlite backend in CI. Signed-off-by: Valentin Rothberg --- cmd/podman/root.go | 4 ++++ libpod/define/info.go | 1 + libpod/info.go | 33 +++++++++++++++--------------- libpod/options.go | 10 +++++++++ pkg/domain/entities/engine.go | 1 + pkg/domain/infra/runtime_libpod.go | 4 ++++ test/system/005-info.bats | 12 +++++++++++ 7 files changed, 49 insertions(+), 16 deletions(-) diff --git a/cmd/podman/root.go b/cmd/podman/root.go index d01b1eb6db..d4de64f4b5 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -423,6 +423,9 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { } podmanConfig.Remote = true } else { + // A *hidden* flag to change the database backend. + pFlags.StringVar(&podmanConfig.ContainersConf.Engine.DBBackend, "db-backend", podmanConfig.ContainersConfDefaultsRO.Engine.DBBackend, "Database backend to use") + cgroupManagerFlagName := "cgroup-manager" pFlags.StringVar(&podmanConfig.ContainersConf.Engine.CgroupManager, cgroupManagerFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")") _ = cmd.RegisterFlagCompletionFunc(cgroupManagerFlagName, common.AutocompleteCgroupManager) @@ -498,6 +501,7 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { // Hide these flags for both ABI and Tunneling for _, f := range []string{ "cpu-profile", + "db-backend", "default-mounts-file", "max-workers", "memory-profile", diff --git a/libpod/define/info.go b/libpod/define/info.go index 28260918b5..559006e9ba 100644 --- a/libpod/define/info.go +++ b/libpod/define/info.go @@ -34,6 +34,7 @@ type HostInfo struct { Conmon *ConmonInfo `json:"conmon"` CPUs int `json:"cpus"` CPUUtilization *CPUUsage `json:"cpuUtilization"` + DatabaseBackend string `json:"databaseBackend"` Distribution DistributionInfo `json:"distribution"` EventLogger string `json:"eventLogger"` Hostname string `json:"hostname"` diff --git a/libpod/info.go b/libpod/info.go index 953ca0539e..82047b123c 100644 --- a/libpod/info.go +++ b/libpod/info.go @@ -100,22 +100,23 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) { return nil, err } info := define.HostInfo{ - Arch: runtime.GOARCH, - BuildahVersion: buildah.Version, - Linkmode: linkmode.Linkmode(), - CPUs: runtime.NumCPU(), - CPUUtilization: cpuUtil, - Distribution: hostDistributionInfo, - LogDriver: r.config.Containers.LogDriver, - EventLogger: r.eventer.String(), - Hostname: host, - Kernel: kv, - MemFree: mi.MemFree, - MemTotal: mi.MemTotal, - NetworkBackend: r.config.Network.NetworkBackend, - OS: runtime.GOOS, - SwapFree: mi.SwapFree, - SwapTotal: mi.SwapTotal, + Arch: runtime.GOARCH, + BuildahVersion: buildah.Version, + DatabaseBackend: r.config.Engine.DBBackend, + Linkmode: linkmode.Linkmode(), + CPUs: runtime.NumCPU(), + CPUUtilization: cpuUtil, + Distribution: hostDistributionInfo, + LogDriver: r.config.Containers.LogDriver, + EventLogger: r.eventer.String(), + Hostname: host, + Kernel: kv, + MemFree: mi.MemFree, + MemTotal: mi.MemTotal, + NetworkBackend: r.config.Network.NetworkBackend, + OS: runtime.GOOS, + SwapFree: mi.SwapFree, + SwapTotal: mi.SwapTotal, } if err := r.setPlatformHostInfo(&info); err != nil { return nil, err diff --git a/libpod/options.go b/libpod/options.go index 56086edd4d..d6b170e408 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -282,6 +282,16 @@ func WithRegistriesConf(path string) RuntimeOption { } } +// WithDatabaseBackend configures the runtime's database backend. +func WithDatabaseBackend(value string) RuntimeOption { + logrus.Debugf("Setting custom database backend: %q", value) + return func(rt *Runtime) error { + // The value will be parsed later on. + rt.config.Engine.DBBackend = value + return nil + } +} + // WithHooksDir sets the directories to look for OCI runtime hook configuration. func WithHooksDir(hooksDirs ...string) RuntimeOption { return func(rt *Runtime) error { diff --git a/pkg/domain/entities/engine.go b/pkg/domain/entities/engine.go index aa5ad69260..984c69f5c1 100644 --- a/pkg/domain/entities/engine.go +++ b/pkg/domain/entities/engine.go @@ -34,6 +34,7 @@ type PodmanConfig struct { ContainersConf *config.Config ContainersConfDefaultsRO *config.Config // The read-only! defaults from containers.conf. + DBBackend string // Hidden: change the database backend DockerConfig string // Used for Docker compatibility CgroupUsage string // rootless code determines Usage message ConmonPath string // --conmon flag will set Engine.ConmonPath diff --git a/pkg/domain/infra/runtime_libpod.go b/pkg/domain/infra/runtime_libpod.go index bd73d20f96..a2cf003bcf 100644 --- a/pkg/domain/infra/runtime_libpod.go +++ b/pkg/domain/infra/runtime_libpod.go @@ -265,6 +265,10 @@ func getRuntime(ctx context.Context, fs *flag.FlagSet, opts *engineOpts) (*libpo options = append(options, libpod.WithRegistriesConf(cfg.RegistriesConf)) } + if fs.Changed("db-backend") { + options = append(options, libpod.WithDatabaseBackend(cfg.ContainersConf.Engine.DBBackend)) + } + // no need to handle the error, it will return false anyway if syslog, _ := fs.GetBool("syslog"); syslog { options = append(options, libpod.WithSyslog()) diff --git a/test/system/005-info.bats b/test/system/005-info.bats index 8cf5eabb23..8561a873c7 100644 --- a/test/system/005-info.bats +++ b/test/system/005-info.bats @@ -150,4 +150,16 @@ host.slirp4netns.executable | $expr_path fi } +@test "podman --db-backend info - basic output" { + # TODO: this tests needs to change once sqlite is being tested in the system tests + skip_if_remote "--db-backend does not work on a remote client" + for backend in boltdb sqlite; do + run_podman --db-backend=$backend info --format "{{ .Host.DatabaseBackend }}" + is "$output" "$backend" + done + + run_podman 125 --db-backend=bogus info --format "{{ .Host.DatabaseBackend }}" + is "$output" "Error: unsupported database backend: \"bogus\"" +} + # vim: filetype=sh