Add initial SQLite-backed state implementation

This contains the implementation of (most) container functions,
with stubs for all pod and volume functions. Presently accessed
via environment variable only for testing purposes.

Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
Matt Heon
2023-02-20 12:53:56 -05:00
parent d71c341b94
commit 1b968c6074
61 changed files with 265846 additions and 45 deletions

View File

@ -38,10 +38,14 @@ import (
"github.com/containers/storage/pkg/lockfile"
"github.com/containers/storage/pkg/unshare"
"github.com/docker/docker/pkg/namesgenerator"
jsoniter "github.com/json-iterator/go"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
// Set up the JSON library for all of Libpod
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// A RuntimeOption is a functional option which alters the Runtime created by
// NewRuntime
type RuntimeOption func(*Runtime) error
@ -340,17 +344,25 @@ func makeRuntime(runtime *Runtime) (retErr error) {
case config.SQLiteStateStore:
return fmt.Errorf("SQLite state is currently disabled: %w", define.ErrInvalidArg)
case config.BoltDBStateStore:
baseDir := runtime.config.Engine.StaticDir
if runtime.storageConfig.TransientStore {
baseDir = runtime.config.Engine.TmpDir
}
dbPath := filepath.Join(baseDir, "bolt_state.db")
if os.Getenv("PODMANDB") == "sqlite" {
state, err := NewSqliteState(runtime)
if err != nil {
return err
}
runtime.state = state
} else {
baseDir := runtime.config.Engine.StaticDir
if runtime.storageConfig.TransientStore {
baseDir = runtime.config.Engine.TmpDir
}
dbPath := filepath.Join(baseDir, "bolt_state.db")
state, err := NewBoltState(dbPath, runtime)
if err != nil {
return err
state, err := NewBoltState(dbPath, runtime)
if err != nil {
return err
}
runtime.state = state
}
runtime.state = state
default:
return fmt.Errorf("unrecognized state type passed (%v): %w", runtime.config.Engine.StateType, define.ErrInvalidArg)
}
@ -415,10 +427,9 @@ func makeRuntime(runtime *Runtime) (retErr error) {
logrus.Errorf("Runtime paths differ from those stored in database, storage reset may not remove all files")
}
if err := runtime.state.SetNamespace(runtime.config.Engine.Namespace); err != nil {
return fmt.Errorf("setting libpod namespace in state: %w", err)
if runtime.config.Engine.Namespace != "" {
return fmt.Errorf("namespaces are not supported by this version of Libpod: %w", define.ErrNotImplemented)
}
logrus.Debugf("Set libpod namespace to %q", runtime.config.Engine.Namespace)
needsUserns := os.Geteuid() != 0
if !needsUserns {
@ -981,17 +992,15 @@ func (r *Runtime) GraphRoot() string {
return r.store.GraphRoot()
}
// GetName retrieves the name associated with a given full ID.
// This works for both containers and pods, and does not distinguish between the
// two.
// GetPodName retrieves the pod name associated with a given full ID.
// If the given ID does not correspond to any existing Pod or Container,
// ErrNoSuchCtr is returned.
func (r *Runtime) GetName(id string) (string, error) {
// ErrNoSuchPod is returned.
func (r *Runtime) GetPodName(id string) (string, error) {
if !r.valid {
return "", define.ErrRuntimeStopped
}
return r.state.GetName(id)
return r.state.GetPodName(id)
}
// DBConfig is a set of Libpod runtime configuration settings that are saved in