Merge pull request #805 from baude/config

Make kpod parse configuration file
This commit is contained in:
Daniel J Walsh 2017-09-01 14:57:14 -04:00 committed by GitHub
commit 553521f03f
3 changed files with 16 additions and 5 deletions

View file

@ -23,8 +23,6 @@ import (
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
) )
const crioConfigPath = "/etc/crio/crio.conf"
func validateConfig(config *server.Config) error { func validateConfig(config *server.Config) error {
switch config.ImageVolumes { switch config.ImageVolumes {
case libkpod.ImageVolumesMkdir: case libkpod.ImageVolumesMkdir:
@ -48,7 +46,7 @@ func mergeConfig(config *server.Config, ctx *cli.Context) error {
// We don't error out if --config wasn't explicitly set and the // We don't error out if --config wasn't explicitly set and the
// default doesn't exist. But we will log a warning about it, so // default doesn't exist. But we will log a warning about it, so
// the user doesn't miss it. // the user doesn't miss it.
logrus.Warnf("default configuration file does not exist: %s", crioConfigPath) logrus.Warnf("default configuration file does not exist: %s", server.CrioConfigPath)
} }
} }
@ -164,7 +162,7 @@ func main() {
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "config", Name: "config",
Value: crioConfigPath, Value: server.CrioConfigPath,
Usage: "path to configuration file", Usage: "path to configuration file",
}, },
cli.StringFlag{ cli.StringFlag{

View file

@ -1,12 +1,14 @@
package main package main
import ( import (
"os"
"strings" "strings"
is "github.com/containers/image/storage" is "github.com/containers/image/storage"
"github.com/containers/storage" "github.com/containers/storage"
"github.com/fatih/camelcase" "github.com/fatih/camelcase"
"github.com/kubernetes-incubator/cri-o/libkpod" "github.com/kubernetes-incubator/cri-o/libkpod"
"github.com/kubernetes-incubator/cri-o/server"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -40,8 +42,16 @@ func shutdownStores() {
func getConfig(c *cli.Context) (*libkpod.Config, error) { func getConfig(c *cli.Context) (*libkpod.Config, error) {
config := libkpod.DefaultConfig() config := libkpod.DefaultConfig()
var configFile string
if c.GlobalIsSet("config") { if c.GlobalIsSet("config") {
err := config.UpdateFromFile(c.String("config")) 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)
if err != nil { if err != nil {
return config, err return config, err
} }

View file

@ -8,6 +8,9 @@ import (
"github.com/kubernetes-incubator/cri-o/libkpod" "github.com/kubernetes-incubator/cri-o/libkpod"
) )
//CrioConfigPath is the default location for the conf file
const CrioConfigPath = "/etc/crio/crio.conf"
// Config represents the entire set of configuration values that can be set for // Config represents the entire set of configuration values that can be set for
// the server. This is intended to be loaded from a toml-encoded config file. // the server. This is intended to be loaded from a toml-encoded config file.
type Config struct { type Config struct {