2017-06-27 13:45:25 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-08-28 18:05:03 +00:00
|
|
|
"os"
|
2017-08-15 20:53:17 +00:00
|
|
|
"strings"
|
|
|
|
|
2017-06-27 13:45:25 +00:00
|
|
|
is "github.com/containers/image/storage"
|
|
|
|
"github.com/containers/storage"
|
2017-08-15 20:53:17 +00:00
|
|
|
"github.com/fatih/camelcase"
|
2017-07-25 19:16:43 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/libkpod"
|
2017-09-06 14:28:59 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/libpod"
|
2017-08-28 18:05:03 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/server"
|
2017-09-06 14:28:59 +00:00
|
|
|
"github.com/pkg/errors"
|
2017-06-27 13:45:25 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2017-08-17 14:23:54 +00:00
|
|
|
var (
|
|
|
|
stores = make(map[storage.Store]struct{})
|
|
|
|
)
|
|
|
|
|
2017-07-27 17:18:07 +00:00
|
|
|
func getStore(c *libkpod.Config) (storage.Store, error) {
|
2017-06-27 13:45:25 +00:00
|
|
|
options := storage.DefaultStoreOptions
|
2017-07-27 17:18:07 +00:00
|
|
|
options.GraphRoot = c.Root
|
|
|
|
options.RunRoot = c.RunRoot
|
|
|
|
options.GraphDriverName = c.Storage
|
|
|
|
options.GraphDriverOptions = c.StorageOptions
|
2017-06-30 19:10:57 +00:00
|
|
|
|
2017-06-27 13:45:25 +00:00
|
|
|
store, err := storage.GetStore(options)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
is.Transport.SetStore(store)
|
2017-08-17 14:23:54 +00:00
|
|
|
stores[store] = struct{}{}
|
2017-06-27 13:45:25 +00:00
|
|
|
return store, nil
|
|
|
|
}
|
2017-07-25 19:16:43 +00:00
|
|
|
|
2017-09-06 14:28:59 +00:00
|
|
|
func getRuntime(c *cli.Context) (*libpod.Runtime, error) {
|
|
|
|
|
|
|
|
config, err := getConfig(c)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "could not get config")
|
|
|
|
}
|
|
|
|
|
|
|
|
options := storage.DefaultStoreOptions
|
|
|
|
options.GraphRoot = config.Root
|
|
|
|
options.RunRoot = config.RunRoot
|
|
|
|
options.GraphDriverName = config.Storage
|
|
|
|
options.GraphDriverOptions = config.StorageOptions
|
|
|
|
|
|
|
|
return libpod.NewRuntime(libpod.WithStorageConfig(options))
|
|
|
|
}
|
|
|
|
|
2017-08-17 14:23:54 +00:00
|
|
|
func shutdownStores() {
|
|
|
|
for store := range stores {
|
|
|
|
if _, err := store.Shutdown(false); err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 19:16:43 +00:00
|
|
|
func getConfig(c *cli.Context) (*libkpod.Config, error) {
|
|
|
|
config := libkpod.DefaultConfig()
|
2017-08-28 18:05:03 +00:00
|
|
|
var configFile string
|
2017-07-25 19:16:43 +00:00
|
|
|
if c.GlobalIsSet("config") {
|
2017-08-28 18:05:03 +00:00
|
|
|
configFile = c.GlobalString("config")
|
|
|
|
} else if _, err := os.Stat(server.CrioConfigPath); err == nil {
|
|
|
|
configFile = server.CrioConfigPath
|
|
|
|
}
|
|
|
|
// load and merge the configfile from the commandline or use
|
|
|
|
// the default crio config file
|
|
|
|
if configFile != "" {
|
|
|
|
err := config.UpdateFromFile(configFile)
|
2017-07-25 19:16:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return config, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if c.GlobalIsSet("root") {
|
|
|
|
config.Root = c.GlobalString("root")
|
|
|
|
}
|
|
|
|
if c.GlobalIsSet("runroot") {
|
|
|
|
config.RunRoot = c.GlobalString("runroot")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.GlobalIsSet("storage-driver") {
|
|
|
|
config.Storage = c.GlobalString("storage-driver")
|
|
|
|
}
|
|
|
|
if c.GlobalIsSet("storage-opt") {
|
|
|
|
opts := c.GlobalStringSlice("storage-opt")
|
|
|
|
if len(opts) > 0 {
|
|
|
|
config.StorageOptions = opts
|
|
|
|
}
|
|
|
|
}
|
2017-08-14 17:30:24 +00:00
|
|
|
if c.GlobalIsSet("runtime") {
|
|
|
|
config.Runtime = c.GlobalString("runtime")
|
|
|
|
}
|
2017-07-25 19:16:43 +00:00
|
|
|
return config, nil
|
|
|
|
}
|
2017-08-15 20:53:17 +00:00
|
|
|
|
|
|
|
func splitCamelCase(src string) string {
|
|
|
|
entries := camelcase.Split(src)
|
|
|
|
return strings.Join(entries, " ")
|
|
|
|
}
|