Merge pull request #318 from jawnsy/promote-config

Promote DefaultConfig() to server package
This commit is contained in:
Antonio Murdaca 2017-01-17 08:23:43 +01:00 committed by GitHub
commit 38acbb4625
3 changed files with 53 additions and 49 deletions

View file

@ -2,25 +2,12 @@ package main
import ( import (
"os" "os"
"path/filepath"
"text/template" "text/template"
"github.com/kubernetes-incubator/cri-o/server" "github.com/kubernetes-incubator/cri-o/server"
"github.com/opencontainers/runc/libcontainer/selinux"
"github.com/urfave/cli" "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(` var commentedConfigTemplate = template.Must(template.New("config").Parse(`
# The "ocid" table contains all of the server options. # The "ocid" table contains all of the server options.
[ocid] [ocid]
@ -99,40 +86,6 @@ plugin_dir = "{{ .PluginDir }}"
// TODO: Currently ImageDir isn't really used, so we haven't added it to this // 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. // 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{ var configCommand = cli.Command{
Name: "config", Name: "config",
Usage: "generate ocid configuration files", Usage: "generate ocid configuration files",
@ -147,7 +100,7 @@ var configCommand = cli.Command{
// config file. So no need to handle that here. // config file. So no need to handle that here.
config := c.App.Metadata["config"].(*server.Config) config := c.App.Metadata["config"].(*server.Config)
if c.Bool("default") { if c.Bool("default") {
config = DefaultConfig() config = server.DefaultConfig()
} }
// Output the commented config. // Output the commented config.

View file

@ -84,7 +84,7 @@ func main() {
app.Usage = "ocid server" app.Usage = "ocid server"
app.Version = "0.0.1" app.Version = "0.0.1"
app.Metadata = map[string]interface{}{ app.Metadata = map[string]interface{}{
"config": DefaultConfig(), "config": server.DefaultConfig(),
} }
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{

View file

@ -3,8 +3,25 @@ package server
import ( import (
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"path/filepath"
"github.com/BurntSushi/toml" "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 // 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) 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,
},
}
}