Add engine.Config to encapsulate writing

This change adds an engine.Config type to encapsulate the writing
of config files for container engines.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar
2023-07-03 15:14:22 +02:00
parent bbe9742c46
commit baf94181aa
8 changed files with 82 additions and 103 deletions

View File

@@ -108,26 +108,23 @@ func (b *builder) build() (engine.Interface, error) {
// loadConfig loads the containerd config from disk
func (b *builder) loadConfig(config string) (*Config, error) {
b.logger.Infof("Loading config: %v", config)
info, err := os.Stat(config)
if os.IsExist(err) && info.IsDir() {
return nil, fmt.Errorf("config file is a directory")
}
configFile := config
if os.IsNotExist(err) {
configFile = "/dev/null"
b.logger.Infof("Config file does not exist, creating new one")
b.logger.Infof("Config file does not exist; using empty config")
config = "/dev/null"
} else {
b.logger.Infof("Loading config from %v", config)
}
tomlConfig, err := toml.LoadFile(configFile)
tomlConfig, err := toml.LoadFile(config)
if err != nil {
return nil, err
}
b.logger.Infof("Successfully loaded config")
cfg := Config{
Tree: tomlConfig,
}