mirror of
https://github.com/containers/podman.git
synced 2025-10-19 04:03:23 +08:00
Make DB config validation an explicit step
Previously, we implicitly validated runtime configuration against what was stored in the database as part of database init. Make this an explicit step, so we can call it after the database has been initialized. This will allow us to retrieve paths from the database and use them to overwrite our defaults if they differ. Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
@ -115,11 +115,6 @@ func NewBoltState(path, lockDir string, runtime *Runtime) (State, error) {
|
|||||||
return nil, errors.Wrapf(err, "error creating initial database layout")
|
return nil, errors.Wrapf(err, "error creating initial database layout")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check runtime configuration
|
|
||||||
if err := checkRuntimeConfig(db, runtime); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
state.valid = true
|
state.valid = true
|
||||||
|
|
||||||
return state, nil
|
return state, nil
|
||||||
@ -243,6 +238,10 @@ func (s *BoltState) Refresh() error {
|
|||||||
// GetDBConfig retrieves runtime configuration fields that were created when
|
// GetDBConfig retrieves runtime configuration fields that were created when
|
||||||
// the database was first initialized
|
// the database was first initialized
|
||||||
func (s *BoltState) GetDBConfig() (*DBConfig, error) {
|
func (s *BoltState) GetDBConfig() (*DBConfig, error) {
|
||||||
|
if !s.valid {
|
||||||
|
return nil, ErrDBClosed
|
||||||
|
}
|
||||||
|
|
||||||
cfg := new(DBConfig)
|
cfg := new(DBConfig)
|
||||||
|
|
||||||
db, err := s.getDBCon()
|
db, err := s.getDBCon()
|
||||||
@ -282,6 +281,26 @@ func (s *BoltState) GetDBConfig() (*DBConfig, error) {
|
|||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateDBConfig validates paths in the given runtime against the database
|
||||||
|
func (s *BoltState) ValidateDBConfig(runtime *Runtime) error {
|
||||||
|
if !s.valid {
|
||||||
|
return ErrDBClosed
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := s.getDBCon()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer s.closeDBCon(db)
|
||||||
|
|
||||||
|
// Check runtime configuration
|
||||||
|
if err := checkRuntimeConfig(db, runtime); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SetNamespace sets the namespace that will be used for container and pod
|
// SetNamespace sets the namespace that will be used for container and pod
|
||||||
// retrieval
|
// retrieval
|
||||||
func (s *BoltState) SetNamespace(ns string) error {
|
func (s *BoltState) SetNamespace(ns string) error {
|
||||||
|
@ -78,6 +78,12 @@ func (s *InMemoryState) GetDBConfig() (*DBConfig, error) {
|
|||||||
return nil, ErrNotImplemented
|
return nil, ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateDBConfig is not implemented for the in-memory state.
|
||||||
|
// Since we do nothing just return no error.
|
||||||
|
func (s *InMemoryState) ValidateDBConfig(runtime *Runtime) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SetNamespace sets the namespace for container and pod retrieval.
|
// SetNamespace sets the namespace for container and pod retrieval.
|
||||||
func (s *InMemoryState) SetNamespace(ns string) error {
|
func (s *InMemoryState) SetNamespace(ns string) error {
|
||||||
s.namespace = ns
|
s.namespace = ns
|
||||||
|
@ -448,6 +448,11 @@ func makeRuntime(runtime *Runtime) (err error) {
|
|||||||
return errors.Wrapf(ErrInvalidArg, "unrecognized state type passed")
|
return errors.Wrapf(ErrInvalidArg, "unrecognized state type passed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate our config against the database
|
||||||
|
if err := runtime.state.ValidateDBConfig(runtime); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := runtime.state.SetNamespace(runtime.config.Namespace); err != nil {
|
if err := runtime.state.SetNamespace(runtime.config.Namespace); err != nil {
|
||||||
return errors.Wrapf(err, "error setting libpod namespace in state")
|
return errors.Wrapf(err, "error setting libpod namespace in state")
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,15 @@ type State interface {
|
|||||||
// validate runtime configuration.
|
// validate runtime configuration.
|
||||||
GetDBConfig() (*DBConfig, error)
|
GetDBConfig() (*DBConfig, error)
|
||||||
|
|
||||||
|
// ValidateDBConfig ralidates the config in the given Runtime struct
|
||||||
|
// against paths stored in the configured database.
|
||||||
|
// Libpod root and tmp dirs and c/storage root and tmp dirs and graph
|
||||||
|
// driver are validated.
|
||||||
|
// This is not implemented by the in-memory state, as it has no need to
|
||||||
|
// validate runtime configuration that may change over multiple runs of
|
||||||
|
// the program.
|
||||||
|
ValidateDBConfig(runtime *Runtime) error
|
||||||
|
|
||||||
// SetNamespace() sets the namespace for the store, and will determine
|
// SetNamespace() sets the namespace for the store, and will determine
|
||||||
// what containers are retrieved with container and pod retrieval calls.
|
// what containers are retrieved with container and pod retrieval calls.
|
||||||
// A namespace of "", the empty string, acts as no namespace, and
|
// A namespace of "", the empty string, acts as no namespace, and
|
||||||
|
Reference in New Issue
Block a user