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
} 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",

View file

@ -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"`

View file

@ -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

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.
func WithHooksDir(hooksDirs ...string) RuntimeOption {
return func(rt *Runtime) error {

View file

@ -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

View file

@ -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())

View file

@ -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