Update kpod commands to use getConfig()

Make getStore() take a config struct from which it pulls the store
options, then update the kpod commands so that they call getConfig()
and pass the config into getStore()

Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
Ryan Cole 2017-07-27 13:18:07 -04:00
parent 0c8f106ee8
commit a8b6f2ad8a
12 changed files with 55 additions and 32 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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) {

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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

View file

@ -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