mirror of
https://github.com/containers/podman.git
synced 2025-10-17 03:04:21 +08:00
Add ability to retrieve runtime configuration from DB
When we create a Libpod database, we store a number of runtime configuration fields in it. If we can retrieve those, we can use them to configure the runtime to match the DB instead of inbuilt defaults, helping to ensure that we don't error in cases where our compiled-in defaults changed. Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
@ -240,6 +240,48 @@ func (s *BoltState) Refresh() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// GetDBConfig retrieves runtime configuration fields that were created when
|
||||
// the database was first initialized
|
||||
func (s *BoltState) GetDBConfig() (*DBConfig, error) {
|
||||
cfg := new(DBConfig)
|
||||
|
||||
db, err := s.getDBCon()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer s.closeDBCon(db)
|
||||
|
||||
err = db.View(func(tx *bolt.Tx) error {
|
||||
configBucket, err := getRuntimeConfigBucket(tx)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Some of these may be nil
|
||||
// When we convert to string, Go will coerce them to ""
|
||||
// That's probably fine - we could raise an error if the key is
|
||||
// missing, but just not including it is also OK.
|
||||
libpodRoot := configBucket.Get(staticDirKey)
|
||||
libpodTmp := configBucket.Get(tmpDirKey)
|
||||
storageRoot := configBucket.Get(graphRootKey)
|
||||
storageTmp := configBucket.Get(runRootKey)
|
||||
graphDriver := configBucket.Get(graphDriverKey)
|
||||
|
||||
cfg.LibpodRoot = string(libpodRoot)
|
||||
cfg.LibpodTmp = string(libpodTmp)
|
||||
cfg.StorageRoot = string(storageRoot)
|
||||
cfg.StorageTmp = string(storageTmp)
|
||||
cfg.GraphDriver = string(graphDriver)
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
// SetNamespace sets the namespace that will be used for container and pod
|
||||
// retrieval
|
||||
func (s *BoltState) SetNamespace(ns string) error {
|
||||
|
Reference in New Issue
Block a user