Skip to content

Commit

Permalink
criocli: Avoid parsing the config twice
Browse files Browse the repository at this point in the history
This splits out the config file loading and commandline argument
processing from GetConfigFromContext() so that subcommand like `crio
config' and `crio wipe` are able to fetch the configuration from the
context without reloading the config files. Apart from being inefficient
this also caused issues with StringSlice values being handled wrong.

Closes #3862

Signed-off-by: Ralf Haferkamp <rhafer@suse.com>
  • Loading branch information
rhafer committed Jun 15, 2020
1 parent 35a8caf commit 6b9dfc6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/crio/main.go
Expand Up @@ -144,7 +144,7 @@ func main() {
}...)

app.Before = func(c *cli.Context) (err error) {
config, err := criocli.GetConfigFromContext(c)
config, err := criocli.GetAndMergeConfigFromContext(c)
if err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions internal/criocli/criocli.go
Expand Up @@ -27,6 +27,14 @@ func GetConfigFromContext(c *cli.Context) (*libconfig.Config, error) {
if !ok {
return nil, fmt.Errorf("type assertion error when accessing server config")
}
return config, nil
}

func GetAndMergeConfigFromContext(c *cli.Context) (*libconfig.Config, error) {
config, err := GetConfigFromContext(c)
if err != nil {
return nil, err
}
if err := mergeConfig(config, c); err != nil {
return nil, err
}
Expand Down

0 comments on commit 6b9dfc6

Please sign in to comment.