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 <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg 2023-03-02 11:41:36 +01:00
parent 96d439913e
commit e77f370f86
7 changed files with 49 additions and 16 deletions

View File

@ -423,6 +423,9 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) {
} }
podmanConfig.Remote = true podmanConfig.Remote = true
} else { } 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" cgroupManagerFlagName := "cgroup-manager"
pFlags.StringVar(&podmanConfig.ContainersConf.Engine.CgroupManager, cgroupManagerFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")") pFlags.StringVar(&podmanConfig.ContainersConf.Engine.CgroupManager, cgroupManagerFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")")
_ = cmd.RegisterFlagCompletionFunc(cgroupManagerFlagName, common.AutocompleteCgroupManager) _ = 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 // Hide these flags for both ABI and Tunneling
for _, f := range []string{ for _, f := range []string{
"cpu-profile", "cpu-profile",
"db-backend",
"default-mounts-file", "default-mounts-file",
"max-workers", "max-workers",
"memory-profile", "memory-profile",

View File

@ -34,6 +34,7 @@ type HostInfo struct {
Conmon *ConmonInfo `json:"conmon"` Conmon *ConmonInfo `json:"conmon"`
CPUs int `json:"cpus"` CPUs int `json:"cpus"`
CPUUtilization *CPUUsage `json:"cpuUtilization"` CPUUtilization *CPUUsage `json:"cpuUtilization"`
DatabaseBackend string `json:"databaseBackend"`
Distribution DistributionInfo `json:"distribution"` Distribution DistributionInfo `json:"distribution"`
EventLogger string `json:"eventLogger"` EventLogger string `json:"eventLogger"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`

View File

@ -100,22 +100,23 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
return nil, err return nil, err
} }
info := define.HostInfo{ info := define.HostInfo{
Arch: runtime.GOARCH, Arch: runtime.GOARCH,
BuildahVersion: buildah.Version, BuildahVersion: buildah.Version,
Linkmode: linkmode.Linkmode(), DatabaseBackend: r.config.Engine.DBBackend,
CPUs: runtime.NumCPU(), Linkmode: linkmode.Linkmode(),
CPUUtilization: cpuUtil, CPUs: runtime.NumCPU(),
Distribution: hostDistributionInfo, CPUUtilization: cpuUtil,
LogDriver: r.config.Containers.LogDriver, Distribution: hostDistributionInfo,
EventLogger: r.eventer.String(), LogDriver: r.config.Containers.LogDriver,
Hostname: host, EventLogger: r.eventer.String(),
Kernel: kv, Hostname: host,
MemFree: mi.MemFree, Kernel: kv,
MemTotal: mi.MemTotal, MemFree: mi.MemFree,
NetworkBackend: r.config.Network.NetworkBackend, MemTotal: mi.MemTotal,
OS: runtime.GOOS, NetworkBackend: r.config.Network.NetworkBackend,
SwapFree: mi.SwapFree, OS: runtime.GOOS,
SwapTotal: mi.SwapTotal, SwapFree: mi.SwapFree,
SwapTotal: mi.SwapTotal,
} }
if err := r.setPlatformHostInfo(&info); err != nil { if err := r.setPlatformHostInfo(&info); err != nil {
return nil, err return nil, err

View File

@ -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. // WithHooksDir sets the directories to look for OCI runtime hook configuration.
func WithHooksDir(hooksDirs ...string) RuntimeOption { func WithHooksDir(hooksDirs ...string) RuntimeOption {
return func(rt *Runtime) error { return func(rt *Runtime) error {

View File

@ -34,6 +34,7 @@ type PodmanConfig struct {
ContainersConf *config.Config ContainersConf *config.Config
ContainersConfDefaultsRO *config.Config // The read-only! defaults from containers.conf. ContainersConfDefaultsRO *config.Config // The read-only! defaults from containers.conf.
DBBackend string // Hidden: change the database backend
DockerConfig string // Used for Docker compatibility DockerConfig string // Used for Docker compatibility
CgroupUsage string // rootless code determines Usage message CgroupUsage string // rootless code determines Usage message
ConmonPath string // --conmon flag will set Engine.ConmonPath ConmonPath string // --conmon flag will set Engine.ConmonPath

View File

@ -265,6 +265,10 @@ func getRuntime(ctx context.Context, fs *flag.FlagSet, opts *engineOpts) (*libpo
options = append(options, libpod.WithRegistriesConf(cfg.RegistriesConf)) 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 // no need to handle the error, it will return false anyway
if syslog, _ := fs.GetBool("syslog"); syslog { if syslog, _ := fs.GetBool("syslog"); syslog {
options = append(options, libpod.WithSyslog()) options = append(options, libpod.WithSyslog())

View File

@ -150,4 +150,16 @@ host.slirp4netns.executable | $expr_path
fi 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 # vim: filetype=sh