diff --git a/cmd/server/config.go b/cmd/server/config.go index 11262ba8..ec3c92f7 100644 --- a/cmd/server/config.go +++ b/cmd/server/config.go @@ -2,25 +2,12 @@ package main import ( "os" - "path/filepath" "text/template" "github.com/kubernetes-incubator/cri-o/server" - "github.com/opencontainers/runc/libcontainer/selinux" "github.com/urfave/cli" ) -const ( - ocidRoot = "/var/lib/ocid" - conmonPath = "/usr/libexec/ocid/conmon" - pausePath = "/usr/libexec/ocid/pause" - seccompProfilePath = "/etc/ocid/seccomp.json" - apparmorProfileName = "ocid-default" - cgroupManager = "cgroupfs" - cniConfigDir = "/etc/cni/net.d/" - cniBinDir = "/opt/cni/bin/" -) - var commentedConfigTemplate = template.Must(template.New("config").Parse(` # The "ocid" table contains all of the server options. [ocid] @@ -99,40 +86,6 @@ plugin_dir = "{{ .PluginDir }}" // TODO: Currently ImageDir isn't really used, so we haven't added it to this // template. Add it once the storage code has been merged. -// DefaultConfig returns the default configuration for ocid. -func DefaultConfig() *server.Config { - return &server.Config{ - RootConfig: server.RootConfig{ - Root: ocidRoot, - SandboxDir: filepath.Join(ocidRoot, "sandboxes"), - ContainerDir: filepath.Join(ocidRoot, "containers"), - LogDir: "/var/log/ocid/pods", - }, - APIConfig: server.APIConfig{ - Listen: "/var/run/ocid.sock", - }, - RuntimeConfig: server.RuntimeConfig{ - Runtime: "/usr/bin/runc", - Conmon: conmonPath, - ConmonEnv: []string{ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - }, - SELinux: selinux.SelinuxEnabled(), - SeccompProfile: seccompProfilePath, - ApparmorProfile: apparmorProfileName, - CgroupManager: cgroupManager, - }, - ImageConfig: server.ImageConfig{ - Pause: pausePath, - ImageDir: filepath.Join(ocidRoot, "store"), - }, - NetworkConfig: server.NetworkConfig{ - NetworkDir: cniConfigDir, - PluginDir: cniBinDir, - }, - } -} - var configCommand = cli.Command{ Name: "config", Usage: "generate ocid configuration files", @@ -147,7 +100,7 @@ var configCommand = cli.Command{ // config file. So no need to handle that here. config := c.App.Metadata["config"].(*server.Config) if c.Bool("default") { - config = DefaultConfig() + config = server.DefaultConfig() } // Output the commented config. diff --git a/cmd/server/main.go b/cmd/server/main.go index 6c3eb81f..528d592a 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -84,7 +84,7 @@ func main() { app.Usage = "ocid server" app.Version = "0.0.1" app.Metadata = map[string]interface{}{ - "config": DefaultConfig(), + "config": server.DefaultConfig(), } app.Flags = []cli.Flag{ diff --git a/server/config.go b/server/config.go index b13e42fc..b49462c0 100644 --- a/server/config.go +++ b/server/config.go @@ -3,8 +3,25 @@ package server import ( "bytes" "io/ioutil" + "path/filepath" "github.com/BurntSushi/toml" + "github.com/opencontainers/runc/libcontainer/selinux" +) + +// Default paths if none are specified +const ( + ocidRoot = "/var/lib/ocid" + conmonPath = "/usr/libexec/ocid/conmon" + pausePath = "/usr/libexec/ocid/pause" + seccompProfilePath = "/etc/ocid/seccomp.json" + cniConfigDir = "/etc/cni/net.d/" + cniBinDir = "/opt/cni/bin/" +) + +const ( + apparmorProfileName = "ocid-default" + cgroupManager = "cgroupfs" ) // Config represents the entire set of configuration values that can be set for @@ -169,3 +186,37 @@ func (c *Config) ToFile(path string) error { return ioutil.WriteFile(path, w.Bytes(), 0644) } + +// DefaultConfig returns the default configuration for ocid. +func DefaultConfig() *Config { + return &Config{ + RootConfig: RootConfig{ + Root: ocidRoot, + SandboxDir: filepath.Join(ocidRoot, "sandboxes"), + ContainerDir: filepath.Join(ocidRoot, "containers"), + LogDir: "/var/log/ocid/pods", + }, + APIConfig: APIConfig{ + Listen: "/var/run/ocid.sock", + }, + RuntimeConfig: RuntimeConfig{ + Runtime: "/usr/bin/runc", + Conmon: conmonPath, + ConmonEnv: []string{ + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + }, + SELinux: selinux.SelinuxEnabled(), + SeccompProfile: seccompProfilePath, + ApparmorProfile: apparmorProfileName, + CgroupManager: cgroupManager, + }, + ImageConfig: ImageConfig{ + Pause: pausePath, + ImageDir: filepath.Join(ocidRoot, "store"), + }, + NetworkConfig: NetworkConfig{ + NetworkDir: cniConfigDir, + PluginDir: cniBinDir, + }, + } +}