2016-10-10 09:57:40 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
2017-07-25 19:16:43 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/libkpod"
|
2016-10-10 09:57:40 +00:00
|
|
|
)
|
|
|
|
|
2017-08-28 18:05:03 +00:00
|
|
|
//CrioConfigPath is the default location for the conf file
|
|
|
|
const CrioConfigPath = "/etc/crio/crio.conf"
|
|
|
|
|
2016-10-10 09:57:40 +00:00
|
|
|
// 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.
|
|
|
|
type Config struct {
|
2017-07-25 19:16:43 +00:00
|
|
|
libkpod.Config
|
2016-10-10 09:57:40 +00:00
|
|
|
APIConfig
|
|
|
|
}
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
// APIConfig represents the "crio.api" TOML config table.
|
2016-10-10 09:57:40 +00:00
|
|
|
type APIConfig struct {
|
|
|
|
// Listen is the path to the AF_LOCAL socket on which cri-o will listen.
|
|
|
|
// This may support proto://addr formats later, but currently this is just
|
|
|
|
// a path.
|
|
|
|
Listen string `toml:"listen"`
|
2017-06-12 22:31:16 +00:00
|
|
|
|
|
|
|
// StreamAddress is the IP address on which the stream server will listen.
|
|
|
|
StreamAddress string `toml:"stream_address"`
|
|
|
|
|
|
|
|
// StreamPort is the port on which the stream server will listen.
|
|
|
|
StreamPort string `toml:"stream_port"`
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// tomlConfig is another way of looking at a Config, which is
|
|
|
|
// TOML-friendly (it has all of the explicit tables). It's just used for
|
|
|
|
// conversions.
|
|
|
|
type tomlConfig struct {
|
2017-07-11 23:19:18 +00:00
|
|
|
Crio struct {
|
2017-07-25 19:16:43 +00:00
|
|
|
libkpod.RootConfig
|
|
|
|
API struct{ APIConfig } `toml:"api"`
|
|
|
|
Runtime struct{ libkpod.RuntimeConfig } `toml:"runtime"`
|
|
|
|
Image struct{ libkpod.ImageConfig } `toml:"image"`
|
|
|
|
Network struct{ libkpod.NetworkConfig } `toml:"network"`
|
2017-05-12 13:36:15 +00:00
|
|
|
} `toml:"crio"`
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tomlConfig) toConfig(c *Config) {
|
2017-07-11 23:19:18 +00:00
|
|
|
c.RootConfig = t.Crio.RootConfig
|
|
|
|
c.APIConfig = t.Crio.API.APIConfig
|
|
|
|
c.RuntimeConfig = t.Crio.Runtime.RuntimeConfig
|
|
|
|
c.ImageConfig = t.Crio.Image.ImageConfig
|
|
|
|
c.NetworkConfig = t.Crio.Network.NetworkConfig
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tomlConfig) fromConfig(c *Config) {
|
2017-07-11 23:19:18 +00:00
|
|
|
t.Crio.RootConfig = c.RootConfig
|
|
|
|
t.Crio.API.APIConfig = c.APIConfig
|
|
|
|
t.Crio.Runtime.RuntimeConfig = c.RuntimeConfig
|
|
|
|
t.Crio.Image.ImageConfig = c.ImageConfig
|
|
|
|
t.Crio.Network.NetworkConfig = c.NetworkConfig
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 17:18:07 +00:00
|
|
|
// UpdateFromFile populates the Config from the TOML-encoded file at the given path.
|
2016-10-10 09:57:40 +00:00
|
|
|
// Returns errors encountered when reading or parsing the files, or nil
|
|
|
|
// otherwise.
|
2017-07-27 17:18:07 +00:00
|
|
|
func (c *Config) UpdateFromFile(path string) error {
|
2016-10-10 09:57:40 +00:00
|
|
|
data, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t := new(tomlConfig)
|
|
|
|
t.fromConfig(c)
|
|
|
|
|
|
|
|
_, err = toml.Decode(string(data), t)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t.toConfig(c)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToFile outputs the given Config as a TOML-encoded file at the given path.
|
|
|
|
// Returns errors encountered when generating or writing the file, or nil
|
|
|
|
// otherwise.
|
|
|
|
func (c *Config) ToFile(path string) error {
|
|
|
|
var w bytes.Buffer
|
|
|
|
e := toml.NewEncoder(&w)
|
|
|
|
|
|
|
|
t := new(tomlConfig)
|
|
|
|
t.fromConfig(c)
|
|
|
|
|
|
|
|
if err := e.Encode(*t); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ioutil.WriteFile(path, w.Bytes(), 0644)
|
|
|
|
}
|
2017-01-17 00:20:35 +00:00
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
// DefaultConfig returns the default configuration for crio.
|
2017-01-17 00:20:35 +00:00
|
|
|
func DefaultConfig() *Config {
|
|
|
|
return &Config{
|
2017-07-25 19:16:43 +00:00
|
|
|
Config: *libkpod.DefaultConfig(),
|
2017-01-17 00:20:35 +00:00
|
|
|
APIConfig: APIConfig{
|
2017-10-18 23:33:58 +00:00
|
|
|
Listen: "/var/run/crio.sock",
|
2017-06-12 22:31:16 +00:00
|
|
|
StreamAddress: "",
|
|
|
|
StreamPort: "10010",
|
2017-01-17 00:20:35 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|