mirror of
https://github.com/rancher/os.git
synced 2025-09-02 23:34:57 +00:00
Use a map to configure Docker arguments
This commit is contained in:
@@ -96,19 +96,9 @@ func applyDebugFlags(rawCfg map[interface{}]interface{}) map[interface{}]interfa
|
||||
}
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
if !util.Contains(cfg.Rancher.Docker.Args, "-D") {
|
||||
cfg.Rancher.Docker.Args = append(cfg.Rancher.Docker.Args, "-D")
|
||||
}
|
||||
if !util.Contains(cfg.Rancher.SystemDocker.Args, "-D") {
|
||||
cfg.Rancher.SystemDocker.Args = append(cfg.Rancher.SystemDocker.Args, "-D")
|
||||
}
|
||||
if !util.Contains(cfg.Rancher.BootstrapDocker.Args, "-D") {
|
||||
cfg.Rancher.BootstrapDocker.Args = append(cfg.Rancher.BootstrapDocker.Args, "-D")
|
||||
}
|
||||
|
||||
_, rawCfg = getOrSetVal("rancher.docker.args", rawCfg, cfg.Rancher.Docker.Args)
|
||||
_, rawCfg = getOrSetVal("rancher.system_docker.args", rawCfg, cfg.Rancher.SystemDocker.Args)
|
||||
_, rawCfg = getOrSetVal("rancher.bootstrap_docker.args", rawCfg, cfg.Rancher.BootstrapDocker.Args)
|
||||
_, rawCfg = getOrSetVal("rancher.docker.debug", rawCfg, true)
|
||||
_, rawCfg = getOrSetVal("rancher.system_docker.debug", rawCfg, true)
|
||||
_, rawCfg = getOrSetVal("rancher.bootstrap_docker.debug", rawCfg, true)
|
||||
_, rawCfg = getOrSetVal("rancher.log", rawCfg, true)
|
||||
|
||||
return rawCfg
|
||||
|
@@ -1,17 +1,52 @@
|
||||
package config
|
||||
|
||||
import "os"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
)
|
||||
|
||||
func (d *DockerConfig) FullArgs() []string {
|
||||
args := append(d.Args, d.ExtraArgs...)
|
||||
|
||||
args := []string{"daemon"}
|
||||
args = append(args, generateEngineOptsSlice(d.EngineOpts)...)
|
||||
args = append(args, d.ExtraArgs...)
|
||||
if d.TLS {
|
||||
args = append(args, d.TLSArgs...)
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
func (d *DockerConfig) AppendEnv() []string {
|
||||
return append(os.Environ(), d.Environment...)
|
||||
}
|
||||
|
||||
func generateEngineOptsSlice(opts EngineOpts) []string {
|
||||
optsStruct := structs.New(opts)
|
||||
|
||||
var optsSlice []string
|
||||
for k, v := range optsStruct.Map() {
|
||||
optTag := optsStruct.Field(k).Tag("opt")
|
||||
|
||||
switch value := v.(type) {
|
||||
case string:
|
||||
if value != "" {
|
||||
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag), value)
|
||||
}
|
||||
case *bool:
|
||||
if value != nil {
|
||||
if *value {
|
||||
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag))
|
||||
} else {
|
||||
optsSlice = append(optsSlice, fmt.Sprintf("--%s=false", optTag))
|
||||
}
|
||||
}
|
||||
case map[string]string:
|
||||
for k, v := range value {
|
||||
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag), fmt.Sprintf("%s=%s", k, v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return optsSlice
|
||||
}
|
||||
|
48
config/docker_config_test.go
Normal file
48
config/docker_config_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testContains(t *testing.T, s string, substrs ...string) {
|
||||
for _, substr := range substrs {
|
||||
if !strings.Contains(s, substr) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateEngineOptsString(t *testing.T) {
|
||||
if len(generateEngineOptsSlice(EngineOpts{})) != 0 {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
|
||||
Bridge: "bridge",
|
||||
})), "--bridge bridge")
|
||||
|
||||
testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
|
||||
SelinuxEnabled: &[]bool{true}[0],
|
||||
})), "--selinux-enabled")
|
||||
testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
|
||||
SelinuxEnabled: &[]bool{false}[0],
|
||||
})), "--selinux-enabled=false")
|
||||
|
||||
testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
|
||||
LogOpts: map[string]string{
|
||||
"max-size": "25m",
|
||||
"max-file": "2",
|
||||
},
|
||||
})), "--log-opt max-size=25m", "--log-opt max-file=2")
|
||||
|
||||
testContains(t, fmt.Sprint(generateEngineOptsSlice(EngineOpts{
|
||||
Bridge: "bridge",
|
||||
SelinuxEnabled: &[]bool{true}[0],
|
||||
LogOpts: map[string]string{
|
||||
"max-size": "25m",
|
||||
"max-file": "2",
|
||||
},
|
||||
})), "--bridge bridge", "--selinux-enabled", "--log-opt max-size=25m", "--log-opt max-file=2")
|
||||
}
|
@@ -134,11 +134,31 @@ type UpgradeConfig struct {
|
||||
Rollback string `yaml:"rollback,omitempty"`
|
||||
}
|
||||
|
||||
type EngineOpts struct {
|
||||
Bridge string `yaml:"bridge" opt:"bridge"`
|
||||
ConfigFile string `yaml:"config_file" opt:"config-file"`
|
||||
Containerd string `yaml:"containerd" opt:"containerd"`
|
||||
Debug *bool `yaml:"debug" opt:"debug"`
|
||||
ExecRoot string `yaml:"exec_root" opt:"exec-root"`
|
||||
Group string `yaml:"group" opt:"group"`
|
||||
Graph string `yaml:"graph" opt:"graph"`
|
||||
Host string `yaml:"host" opt:"host"`
|
||||
LiveRestore *bool `yaml:"live_restore" opt:"live-restore"`
|
||||
LogDriver string `yaml:"log_driver" opt:"log-driver"`
|
||||
LogOpts map[string]string `yaml:"log_opts" opt:"log-opt"`
|
||||
PidFile string `yaml:"pid_file" opt:"pidfile"`
|
||||
RegistryMirror string `yaml:"registry_mirror" opt:"registry-mirror"`
|
||||
Restart *bool `yaml:"restart" opt:"restart"`
|
||||
SelinuxEnabled *bool `yaml:"selinux_enabled" opt:"selinux-enabled"`
|
||||
StorageDriver string `yaml:"storage_driver" opt:"storage-driver"`
|
||||
UserlandProxy *bool `yaml:"userland_proxy" opt:"userland-proxy"`
|
||||
}
|
||||
|
||||
type DockerConfig struct {
|
||||
EngineOpts
|
||||
Engine string `yaml:"engine,omitempty"`
|
||||
TLS bool `yaml:"tls,omitempty"`
|
||||
TLSArgs []string `yaml:"tls_args,flow,omitempty"`
|
||||
Args []string `yaml:"args,flow,omitempty"`
|
||||
ExtraArgs []string `yaml:"extra_args,flow,omitempty"`
|
||||
ServerCert string `yaml:"server_cert,omitempty"`
|
||||
ServerKey string `yaml:"server_key,omitempty"`
|
||||
|
@@ -165,7 +165,7 @@ func tryMountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, error)
|
||||
func getLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*dockerlaunch.Config, []string) {
|
||||
var launchConfig dockerlaunch.Config
|
||||
|
||||
args := dockerlaunch.ParseConfig(&launchConfig, append(dockerCfg.Args, dockerCfg.ExtraArgs...)...)
|
||||
args := dockerlaunch.ParseConfig(&launchConfig, dockerCfg.FullArgs()...)
|
||||
|
||||
launchConfig.DnsConfig.Nameservers = cfg.Rancher.Defaults.Network.Dns.Nameservers
|
||||
launchConfig.DnsConfig.Search = cfg.Rancher.Defaults.Network.Dns.Search
|
||||
|
@@ -72,8 +72,13 @@ rancher:
|
||||
- /lib/firmware:/lib/firmware
|
||||
- /usr/bin/ros:/usr/bin/ros:ro
|
||||
bootstrap_docker:
|
||||
args: [daemon, -s, overlay, -b, none, --restart=false, -g, /var/lib/system-docker,
|
||||
-G, root, -H, 'unix:///var/run/system-docker.sock', --userland-proxy=false]
|
||||
bridge: none
|
||||
storage_driver: overlay
|
||||
restart: false
|
||||
graph: /var/lib/system-docker
|
||||
group: root
|
||||
host: "unix:///var/run/system-docker.sock"
|
||||
userland_proxy: false
|
||||
console: default
|
||||
cloud_init:
|
||||
datasources:
|
||||
@@ -391,10 +396,18 @@ rancher:
|
||||
- /var/lib/system-docker:/var/lib/system-docker:shared
|
||||
system_docker:
|
||||
exec: true
|
||||
args: [daemon, --log-opt, max-size=25m, --log-opt, max-file=2, -s, overlay,
|
||||
--restart=false, -g, /var/lib/system-docker, -G, root,
|
||||
-p, /var/run/system-docker.pid, --exec-root=/var/run/system-docker, --config-file=/etc/docker/system-daemon.json,
|
||||
-H, 'unix:///var/run/system-docker.sock', --userland-proxy=false]
|
||||
storage_driver: overlay
|
||||
restart: false
|
||||
graph: /var/lib/system-docker
|
||||
group: root
|
||||
host: "unix:///var/run/system-docker.sock"
|
||||
pid_file: /var/run/system-docker.pid
|
||||
exec_root: /var/run/system-docker
|
||||
config_file: /etc/docker/system-docker.json
|
||||
userland_proxy: false
|
||||
log_opts:
|
||||
max-size: 25m
|
||||
max-file: 2
|
||||
upgrade:
|
||||
url: {{.OS_RELEASES_YML}}/releases{{.SUFFIX}}.yml
|
||||
image: {{.OS_REPO}}/os
|
||||
@@ -404,6 +417,11 @@ rancher:
|
||||
{{else -}}
|
||||
engine: docker-1.11.2
|
||||
{{end -}}
|
||||
storage_driver: overlay
|
||||
group: docker
|
||||
host: "unix:///var/run/docker.sock"
|
||||
log_opts:
|
||||
max-size: 25m
|
||||
max-file: 2
|
||||
tls_args: [--tlsverify, --tlscacert=/etc/docker/tls/ca.pem, --tlscert=/etc/docker/tls/server-cert.pem, --tlskey=/etc/docker/tls/server-key.pem,
|
||||
'-H=0.0.0.0:2376']
|
||||
args: [daemon, --log-opt, max-size=25m, --log-opt, max-file=2, -s, overlay, -G, docker, -H, 'unix:///var/run/docker.sock']
|
||||
|
@@ -11,7 +11,5 @@ rancher:
|
||||
address: 10.10.2.17/24
|
||||
gateway: 10.10.2.2
|
||||
mtu: 1500
|
||||
docker:
|
||||
args: [daemon, --log-opt, max-file=2, --log-opt, max-size=25m, -s, overlay, -G, docker, -H, 'unix:///var/run/docker.sock', --userland-proxy=false]
|
||||
ssh_authorized_keys:
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF
|
||||
|
@@ -8,7 +8,6 @@ func (s *QemuSuite) TestMisc(c *C) {
|
||||
|
||||
s.CheckCall(c, "sudo ros env printenv FLANNEL_NETWORK | grep '10.244.0.0/16'")
|
||||
|
||||
s.CheckCall(c, "ps -ef | grep 'daemon --log-opt max-file=2 --log-opt max-size=25m -s overlay -G docker -H unix:///var/run/docker.sock --userland-proxy=false'")
|
||||
s.CheckCall(c, "ps -ef | grep 'dhcpcd -M'")
|
||||
|
||||
s.CheckCall(c, `
|
||||
|
Reference in New Issue
Block a user