diff --git a/cmd/crio/main.go b/cmd/crio/main.go index f277579f..98c7a8e8 100644 --- a/cmd/crio/main.go +++ b/cmd/crio/main.go @@ -38,7 +38,7 @@ func validateConfig(config *server.Config) error { func mergeConfig(config *server.Config, ctx *cli.Context) error { // Don't parse the config if the user explicitly set it to "". if path := ctx.GlobalString("config"); path != "" { - if err := config.FromFile(path); err != nil { + if err := config.UpdateFromFile(path); err != nil { if ctx.GlobalIsSet("config") || !os.IsNotExist(err) { return err } diff --git a/cmd/kpod/common.go b/cmd/kpod/common.go index 7708faf2..0b399c6a 100644 --- a/cmd/kpod/common.go +++ b/cmd/kpod/common.go @@ -7,24 +7,13 @@ import ( "github.com/urfave/cli" ) -func getStore(c *cli.Context) (storage.Store, error) { +func getStore(c *libkpod.Config) (storage.Store, error) { options := storage.DefaultStoreOptions - if c.GlobalIsSet("root") { - options.GraphRoot = c.GlobalString("root") - } - if c.GlobalIsSet("runroot") { - options.RunRoot = c.GlobalString("runroot") - } + options.GraphRoot = c.Root + options.RunRoot = c.RunRoot + options.GraphDriverName = c.Storage + options.GraphDriverOptions = c.StorageOptions - if c.GlobalIsSet("storage-driver") { - options.GraphDriverName = c.GlobalString("storage-driver") - } - if c.GlobalIsSet("storage-opt") { - opts := c.GlobalStringSlice("storage-opt") - if len(opts) > 0 { - options.GraphDriverOptions = opts - } - } store, err := storage.GetStore(options) if err != nil { return nil, err @@ -36,7 +25,7 @@ func getStore(c *cli.Context) (storage.Store, error) { func getConfig(c *cli.Context) (*libkpod.Config, error) { config := libkpod.DefaultConfig() if c.GlobalIsSet("config") { - err := config.FromFile(c.String("config")) + err := config.UpdateFromFile(c.String("config")) if err != nil { return config, err } diff --git a/cmd/kpod/history.go b/cmd/kpod/history.go index ae0a5d3f..a737c342 100644 --- a/cmd/kpod/history.go +++ b/cmd/kpod/history.go @@ -80,7 +80,11 @@ var ( ) func historyCmd(c *cli.Context) error { - store, err := getStore(c) + config, err := getConfig(c) + if err != nil { + return errors.Wrapf(err, "Could not get config") + } + store, err := getStore(config) if err != nil { return err } diff --git a/cmd/kpod/images.go b/cmd/kpod/images.go index 22943043..fd21c41c 100644 --- a/cmd/kpod/images.go +++ b/cmd/kpod/images.go @@ -60,7 +60,11 @@ var ( ) func imagesCmd(c *cli.Context) error { - store, err := getStore(c) + config, err := getConfig(c) + if err != nil { + return errors.Wrapf(err, "Could not get config") + } + store, err := getStore(config) if err != nil { return err } diff --git a/cmd/kpod/info.go b/cmd/kpod/info.go index a094606d..be08f91d 100644 --- a/cmd/kpod/info.go +++ b/cmd/kpod/info.go @@ -10,6 +10,7 @@ import ( "github.com/docker/docker/pkg/system" "github.com/ghodss/yaml" + "github.com/pkg/errors" "github.com/urfave/cli" ) @@ -125,9 +126,14 @@ func hostInfo(c *cli.Context) (string, map[string]interface{}, error) { // top-level "store" info func storeInfo(c *cli.Context) (string, map[string]interface{}, error) { - store, err := getStore(c) + storeStr := "store" + config, err := getConfig(c) if err != nil { - return "store", nil, err + return storeStr, nil, errors.Wrapf(err, "Could not get config") + } + store, err := getStore(config) + if err != nil { + return storeStr, nil, err } // lets say storage driver in use, number of images, number of containers @@ -150,7 +156,7 @@ func storeInfo(c *cli.Context) (string, map[string]interface{}, error) { "number": len(containers), } } - return "store", info, nil + return storeStr, info, nil } func readKernelVersion() (string, error) { diff --git a/cmd/kpod/inspect.go b/cmd/kpod/inspect.go index 63d5c231..7a5188f3 100644 --- a/cmd/kpod/inspect.go +++ b/cmd/kpod/inspect.go @@ -77,7 +77,11 @@ func inspectCmd(c *cli.Context) error { name := args[0] - store, err := getStore(c) + config, err := getConfig(c) + if err != nil { + return errors.Wrapf(err, "Could not get config") + } + store, err := getStore(config) if err != nil { return err } diff --git a/cmd/kpod/pull.go b/cmd/kpod/pull.go index 2c0af7e5..37aa933d 100644 --- a/cmd/kpod/pull.go +++ b/cmd/kpod/pull.go @@ -45,7 +45,11 @@ func pullCmd(c *cli.Context) error { } image := args[0] - store, err := getStore(c) + config, err := getConfig(c) + if err != nil { + return errors.Wrapf(err, "could not get config") + } + store, err := getStore(config) if err != nil { return err } diff --git a/cmd/kpod/push.go b/cmd/kpod/push.go index 32b7cd43..989a9a87 100644 --- a/cmd/kpod/push.go +++ b/cmd/kpod/push.go @@ -93,7 +93,11 @@ func pushCmd(c *cli.Context) error { registryCreds = creds } - store, err := getStore(c) + config, err := getConfig(c) + if err != nil { + return errors.Wrapf(err, "Could not get config") + } + store, err := getStore(config) if err != nil { return err } diff --git a/cmd/kpod/rmi.go b/cmd/kpod/rmi.go index 78740ab8..c7752fc1 100644 --- a/cmd/kpod/rmi.go +++ b/cmd/kpod/rmi.go @@ -39,7 +39,11 @@ func rmiCmd(c *cli.Context) error { return errors.Errorf("image name or ID must be specified") } - store, err := getStore(c) + config, err := getConfig(c) + if err != nil { + return errors.Wrapf(err, "Could not get config") + } + store, err := getStore(config) if err != nil { return err } diff --git a/cmd/kpod/tag.go b/cmd/kpod/tag.go index 435f5072..c691dd0e 100644 --- a/cmd/kpod/tag.go +++ b/cmd/kpod/tag.go @@ -24,7 +24,11 @@ func tagCmd(c *cli.Context) error { if len(args) < 2 { return errors.Errorf("image name and at least one new name must be specified") } - store, err := getStore(c) + config, err := getConfig(c) + if err != nil { + return errors.Wrapf(err, "Could not get config") + } + store, err := getStore(config) if err != nil { return err } diff --git a/libkpod/config.go b/libkpod/config.go index a3a1463b..27fbae8b 100644 --- a/libkpod/config.go +++ b/libkpod/config.go @@ -191,10 +191,10 @@ func (t *tomlConfig) fromConfig(c *Config) { t.Crio.Network.NetworkConfig = c.NetworkConfig } -// FromFile populates the Config from the TOML-encoded file at the given path. +// UpdateFromFile populates the Config from the TOML-encoded file at the given path. // Returns errors encountered when reading or parsing the files, or nil // otherwise. -func (c *Config) FromFile(path string) error { +func (c *Config) UpdateFromFile(path string) error { data, err := ioutil.ReadFile(path) if err != nil { return err diff --git a/server/config.go b/server/config.go index b5fca7a3..53a46ecd 100644 --- a/server/config.go +++ b/server/config.go @@ -58,10 +58,10 @@ func (t *tomlConfig) fromConfig(c *Config) { t.Crio.Network.NetworkConfig = c.NetworkConfig } -// FromFile populates the Config from the TOML-encoded file at the given path. +// UpdateFromFile populates the Config from the TOML-encoded file at the given path. // Returns errors encountered when reading or parsing the files, or nil // otherwise. -func (c *Config) FromFile(path string) error { +func (c *Config) UpdateFromFile(path string) error { data, err := ioutil.ReadFile(path) if err != nil { return err