瀏覽代碼

Add initial plugin flag to pass lxc and native driver options
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby 11 年之前
父節點
當前提交
f7b3e879fc

+ 2 - 0
runconfig/hostconfig.go

@@ -13,6 +13,7 @@ type HostConfig struct {
 	PortBindings    nat.PortMap
 	PortBindings    nat.PortMap
 	Links           []string
 	Links           []string
 	PublishAllPorts bool
 	PublishAllPorts bool
+	PluginOptions   map[string][]string
 }
 }
 
 
 type KeyValuePair struct {
 type KeyValuePair struct {
@@ -28,6 +29,7 @@ func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
 	}
 	}
 	job.GetenvJson("LxcConf", &hostConfig.LxcConf)
 	job.GetenvJson("LxcConf", &hostConfig.LxcConf)
 	job.GetenvJson("PortBindings", &hostConfig.PortBindings)
 	job.GetenvJson("PortBindings", &hostConfig.PortBindings)
+	job.GetenvJson("PluginOptions", &hostConfig.PluginOptions)
 	if Binds := job.GetenvList("Binds"); Binds != nil {
 	if Binds := job.GetenvList("Binds"); Binds != nil {
 		hostConfig.Binds = Binds
 		hostConfig.Binds = Binds
 	}
 	}

+ 18 - 0
runconfig/parse.go

@@ -45,6 +45,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
 		flDnsSearch   = opts.NewListOpts(opts.ValidateDomain)
 		flDnsSearch   = opts.NewListOpts(opts.ValidateDomain)
 		flVolumesFrom opts.ListOpts
 		flVolumesFrom opts.ListOpts
 		flLxcOpts     opts.ListOpts
 		flLxcOpts     opts.ListOpts
+		flPluginOpts  opts.ListOpts
 
 
 		flAutoRemove      = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)")
 		flAutoRemove      = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)")
 		flDetach          = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: Run container in the background, print new container id")
 		flDetach          = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: Run container in the background, print new container id")
@@ -77,6 +78,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
 	cmd.Var(&flDnsSearch, []string{"-dns-search"}, "Set custom dns search domains")
 	cmd.Var(&flDnsSearch, []string{"-dns-search"}, "Set custom dns search domains")
 	cmd.Var(&flVolumesFrom, []string{"#volumes-from", "-volumes-from"}, "Mount volumes from the specified container(s)")
 	cmd.Var(&flVolumesFrom, []string{"#volumes-from", "-volumes-from"}, "Mount volumes from the specified container(s)")
 	cmd.Var(&flLxcOpts, []string{"#lxc-conf", "-lxc-conf"}, "Add custom lxc options --lxc-conf=\"lxc.cgroup.cpuset.cpus = 0,1\"")
 	cmd.Var(&flLxcOpts, []string{"#lxc-conf", "-lxc-conf"}, "Add custom lxc options --lxc-conf=\"lxc.cgroup.cpuset.cpus = 0,1\"")
+	cmd.Var(&flPluginOpts, []string{"-plugin"}, "Add custom plugin options")
 
 
 	if err := cmd.Parse(args); err != nil {
 	if err := cmd.Parse(args); err != nil {
 		return nil, nil, cmd, err
 		return nil, nil, cmd, err
@@ -206,6 +208,8 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
 		WorkingDir:      *flWorkingDir,
 		WorkingDir:      *flWorkingDir,
 	}
 	}
 
 
+	pluginOptions := parsePluginOpts(flPluginOpts)
+
 	hostConfig := &HostConfig{
 	hostConfig := &HostConfig{
 		Binds:           binds,
 		Binds:           binds,
 		ContainerIDFile: *flContainerIDFile,
 		ContainerIDFile: *flContainerIDFile,
@@ -214,6 +218,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
 		PortBindings:    portBindings,
 		PortBindings:    portBindings,
 		Links:           flLinks.GetAll(),
 		Links:           flLinks.GetAll(),
 		PublishAllPorts: *flPublishAll,
 		PublishAllPorts: *flPublishAll,
+		PluginOptions:   pluginOptions,
 	}
 	}
 
 
 	if sysInfo != nil && flMemory > 0 && !sysInfo.SwapLimit {
 	if sysInfo != nil && flMemory > 0 && !sysInfo.SwapLimit {
@@ -247,3 +252,16 @@ func parseLxcOpt(opt string) (string, string, error) {
 	}
 	}
 	return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]), nil
 	return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]), nil
 }
 }
+
+func parsePluginOpts(opts opts.ListOpts) map[string][]string {
+	out := make(map[string][]string, len(opts.GetAll()))
+	for _, o := range opts.GetAll() {
+		parts := strings.SplitN(o, " ", 2)
+		values, exists := out[parts[0]]
+		if !exists {
+			values = []string{}
+		}
+		out[parts[0]] = append(values, parts[1])
+	}
+	return out
+}

+ 6 - 2
runtime/container.go

@@ -361,7 +361,7 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s
 func populateCommand(c *Container) {
 func populateCommand(c *Container) {
 	var (
 	var (
 		en           *execdriver.Network
 		en           *execdriver.Network
-		driverConfig []string
+		driverConfig = c.hostConfig.PluginOptions
 	)
 	)
 
 
 	en = &execdriver.Network{
 	en = &execdriver.Network{
@@ -379,11 +379,15 @@ func populateCommand(c *Container) {
 		}
 		}
 	}
 	}
 
 
+	// merge in the lxc conf options into the generic config map
 	if lxcConf := c.hostConfig.LxcConf; lxcConf != nil {
 	if lxcConf := c.hostConfig.LxcConf; lxcConf != nil {
+		lxc := driverConfig["lxc"]
 		for _, pair := range lxcConf {
 		for _, pair := range lxcConf {
-			driverConfig = append(driverConfig, fmt.Sprintf("%s = %s", pair.Key, pair.Value))
+			lxc = append(lxc, fmt.Sprintf("%s = %s", pair.Key, pair.Value))
 		}
 		}
+		driverConfig["lxc"] = lxc
 	}
 	}
+
 	resources := &execdriver.Resources{
 	resources := &execdriver.Resources{
 		Memory:     c.Config.Memory,
 		Memory:     c.Config.Memory,
 		MemorySwap: c.Config.MemorySwap,
 		MemorySwap: c.Config.MemorySwap,

+ 14 - 14
runtime/execdriver/driver.go

@@ -112,20 +112,20 @@ type Mount struct {
 type Command struct {
 type Command struct {
 	exec.Cmd `json:"-"`
 	exec.Cmd `json:"-"`
 
 
-	ID         string     `json:"id"`
-	Privileged bool       `json:"privileged"`
-	User       string     `json:"user"`
-	Rootfs     string     `json:"rootfs"`   // root fs of the container
-	InitPath   string     `json:"initpath"` // dockerinit
-	Entrypoint string     `json:"entrypoint"`
-	Arguments  []string   `json:"arguments"`
-	WorkingDir string     `json:"working_dir"`
-	ConfigPath string     `json:"config_path"` // this should be able to be removed when the lxc template is moved into the driver
-	Tty        bool       `json:"tty"`
-	Network    *Network   `json:"network"`
-	Config     []string   `json:"config"` //  generic values that specific drivers can consume
-	Resources  *Resources `json:"resources"`
-	Mounts     []Mount    `json:"mounts"`
+	ID         string              `json:"id"`
+	Privileged bool                `json:"privileged"`
+	User       string              `json:"user"`
+	Rootfs     string              `json:"rootfs"`   // root fs of the container
+	InitPath   string              `json:"initpath"` // dockerinit
+	Entrypoint string              `json:"entrypoint"`
+	Arguments  []string            `json:"arguments"`
+	WorkingDir string              `json:"working_dir"`
+	ConfigPath string              `json:"config_path"` // this should be able to be removed when the lxc template is moved into the driver
+	Tty        bool                `json:"tty"`
+	Network    *Network            `json:"network"`
+	Config     map[string][]string `json:"config"` //  generic values that specific drivers can consume
+	Resources  *Resources          `json:"resources"`
+	Mounts     []Mount             `json:"mounts"`
 
 
 	Terminal     Terminal `json:"-"`             // standard or tty terminal
 	Terminal     Terminal `json:"-"`             // standard or tty terminal
 	Console      string   `json:"-"`             // dev/console path
 	Console      string   `json:"-"`             // dev/console path

+ 2 - 2
runtime/execdriver/lxc/lxc_template.go

@@ -118,8 +118,8 @@ lxc.cgroup.cpu.shares = {{.Resources.CpuShares}}
 {{end}}
 {{end}}
 {{end}}
 {{end}}
 
 
-{{if .Config}}
-{{range $value := .Config}}
+{{if .Config.lxc}}
+{{range $value := .Config.lxc}}
 {{$value}}
 {{$value}}
 {{end}}
 {{end}}
 {{end}}
 {{end}}

+ 2 - 1
runtime/execdriver/lxc/lxc_template_unit_test.go

@@ -75,10 +75,11 @@ func TestCustomLxcConfig(t *testing.T) {
 	command := &execdriver.Command{
 	command := &execdriver.Command{
 		ID:         "1",
 		ID:         "1",
 		Privileged: false,
 		Privileged: false,
-		Config: []string{
+		Config: map[string][]string{"lxc": {
 			"lxc.utsname = docker",
 			"lxc.utsname = docker",
 			"lxc.cgroup.cpuset.cpus = 0,1",
 			"lxc.cgroup.cpuset.cpus = 0,1",
 		},
 		},
+		},
 		Network: &execdriver.Network{
 		Network: &execdriver.Network{
 			Mtu:       1500,
 			Mtu:       1500,
 			Interface: nil,
 			Interface: nil,

+ 2 - 4
runtime/execdriver/native/driver.go

@@ -184,10 +184,8 @@ func (d *driver) removeContainerRoot(id string) error {
 func (d *driver) validateCommand(c *execdriver.Command) error {
 func (d *driver) validateCommand(c *execdriver.Command) error {
 	// we need to check the Config of the command to make sure that we
 	// we need to check the Config of the command to make sure that we
 	// do not have any of the lxc-conf variables
 	// do not have any of the lxc-conf variables
-	for _, conf := range c.Config {
-		if strings.Contains(conf, "lxc") {
-			return fmt.Errorf("%s is not supported by the native driver", conf)
-		}
+	for _, conf := range c.Config["native"] {
+		log.Println(conf)
 	}
 	}
 	return nil
 	return nil
 }
 }