Merge pull request #12253 from calavera/remove_job_from_start_and_create

Remove engine.Job from Start and Create
Upstream-commit: de923f59b3860eba2c87e8a533b385ac5752243b
Component: engine
This commit is contained in:
Brian Goff
2015-04-15 21:49:25 -04:00
23 changed files with 518 additions and 318 deletions
+15 -28
View File
@@ -4,7 +4,6 @@ import (
"fmt"
"strings"
"github.com/docker/docker/engine"
"github.com/docker/docker/graph"
"github.com/docker/docker/image"
"github.com/docker/docker/pkg/parsers"
@@ -12,36 +11,28 @@ import (
"github.com/docker/libcontainer/label"
)
func (daemon *Daemon) ContainerCreate(job *engine.Job) error {
var name string
if len(job.Args) == 1 {
name = job.Args[0]
} else if len(job.Args) > 1 {
return fmt.Errorf("Usage: %s", job.Name)
}
func (daemon *Daemon) ContainerCreate(name string, config *runconfig.Config, hostConfig *runconfig.HostConfig) (string, []string, error) {
var warnings []string
config := runconfig.ContainerConfigFromJob(job)
hostConfig := runconfig.ContainerHostConfigFromJob(job)
if len(hostConfig.LxcConf) > 0 && !strings.Contains(daemon.ExecutionDriver().Name(), "lxc") {
return fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name())
if hostConfig.LxcConf.Len() > 0 && !strings.Contains(daemon.ExecutionDriver().Name(), "lxc") {
return "", warnings, fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name())
}
if hostConfig.Memory != 0 && hostConfig.Memory < 4194304 {
return fmt.Errorf("Minimum memory limit allowed is 4MB")
return "", warnings, fmt.Errorf("Minimum memory limit allowed is 4MB")
}
if hostConfig.Memory > 0 && !daemon.SystemConfig().MemoryLimit {
job.Errorf("Your kernel does not support memory limit capabilities. Limitation discarded.\n")
warnings = append(warnings, "Your kernel does not support memory limit capabilities. Limitation discarded.\n")
hostConfig.Memory = 0
}
if hostConfig.Memory > 0 && hostConfig.MemorySwap != -1 && !daemon.SystemConfig().SwapLimit {
job.Errorf("Your kernel does not support swap limit capabilities. Limitation discarded.\n")
warnings = append(warnings, "Your kernel does not support swap limit capabilities. Limitation discarded.\n")
hostConfig.MemorySwap = -1
}
if hostConfig.Memory > 0 && hostConfig.MemorySwap > 0 && hostConfig.MemorySwap < hostConfig.Memory {
return fmt.Errorf("Minimum memoryswap limit should be larger than memory limit, see usage.\n")
return "", warnings, fmt.Errorf("Minimum memoryswap limit should be larger than memory limit, see usage.\n")
}
if hostConfig.Memory == 0 && hostConfig.MemorySwap > 0 {
return fmt.Errorf("You should always set the Memory limit when using Memoryswap limit, see usage.\n")
return "", warnings, fmt.Errorf("You should always set the Memory limit when using Memoryswap limit, see usage.\n")
}
container, buildWarnings, err := daemon.Create(config, hostConfig, name)
@@ -51,22 +42,18 @@ func (daemon *Daemon) ContainerCreate(job *engine.Job) error {
if tag == "" {
tag = graph.DEFAULTTAG
}
return fmt.Errorf("No such image: %s (tag: %s)", config.Image, tag)
return "", warnings, fmt.Errorf("No such image: %s (tag: %s)", config.Image, tag)
}
return err
return "", warnings, err
}
if !container.Config.NetworkDisabled && daemon.SystemConfig().IPv4ForwardingDisabled {
job.Errorf("IPv4 forwarding is disabled.\n")
warnings = append(warnings, "IPv4 forwarding is disabled.\n")
}
container.LogEvent("create")
warnings = append(warnings, buildWarnings...)
job.Printf("%s\n", container.ID)
for _, warning := range buildWarnings {
job.Errorf("%s\n", warning)
}
return nil
return container.ID, warnings, nil
}
// Create creates a new container from the given configuration with a given name.
+10 -9
View File
@@ -119,10 +119,8 @@ type Daemon struct {
func (daemon *Daemon) Install(eng *engine.Engine) error {
for name, method := range map[string]engine.Handler{
"container_inspect": daemon.ContainerInspect,
"create": daemon.ContainerCreate,
"info": daemon.CmdInfo,
"restart": daemon.ContainerRestart,
"start": daemon.ContainerStart,
"execCreate": daemon.ContainerExecCreate,
"execStart": daemon.ContainerExecStart,
} {
@@ -483,7 +481,7 @@ func (daemon *Daemon) mergeAndVerifyConfig(config *runconfig.Config, img *image.
return nil, err
}
}
if len(config.Entrypoint) == 0 && len(config.Cmd) == 0 {
if config.Entrypoint.Len() == 0 && config.Cmd.Len() == 0 {
return nil, fmt.Errorf("No command specified")
}
return warnings, nil
@@ -575,17 +573,20 @@ func (daemon *Daemon) generateHostname(id string, config *runconfig.Config) {
}
}
func (daemon *Daemon) getEntrypointAndArgs(configEntrypoint, configCmd []string) (string, []string) {
func (daemon *Daemon) getEntrypointAndArgs(configEntrypoint *runconfig.Entrypoint, configCmd *runconfig.Command) (string, []string) {
var (
entrypoint string
args []string
)
if len(configEntrypoint) != 0 {
entrypoint = configEntrypoint[0]
args = append(configEntrypoint[1:], configCmd...)
cmdSlice := configCmd.Slice()
if configEntrypoint.Len() != 0 {
eSlice := configEntrypoint.Slice()
entrypoint = eSlice[0]
args = append(eSlice[1:], cmdSlice...)
} else {
entrypoint = configCmd[0]
args = configCmd[1:]
entrypoint = cmdSlice[0]
args = cmdSlice[1:]
}
return entrypoint, args
}
+2 -1
View File
@@ -132,7 +132,8 @@ func (d *Daemon) ContainerExecCreate(job *engine.Job) error {
return err
}
entrypoint, args := d.getEntrypointAndArgs(nil, config.Cmd)
cmd := runconfig.NewCommand(config.Cmd...)
entrypoint, args := d.getEntrypointAndArgs(runconfig.NewEntrypoint(), cmd)
processConfig := execdriver.ProcessConfig{
Tty: config.Tty,
+3 -12
View File
@@ -3,18 +3,10 @@ package daemon
import (
"fmt"
"github.com/docker/docker/engine"
"github.com/docker/docker/runconfig"
)
func (daemon *Daemon) ContainerStart(job *engine.Job) error {
if len(job.Args) < 1 {
return fmt.Errorf("Usage: %s container_id", job.Name)
}
var (
name = job.Args[0]
)
func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConfig) error {
container, err := daemon.Get(name)
if err != nil {
return err
@@ -28,15 +20,14 @@ func (daemon *Daemon) ContainerStart(job *engine.Job) error {
return fmt.Errorf("Container already started")
}
// If no environment was set, then no hostconfig was passed.
// This is kept for backward compatibility - hostconfig should be passed when
// creating a container, not during start.
if len(job.Environ()) > 0 {
hostConfig := runconfig.ContainerHostConfigFromJob(job)
if hostConfig != nil {
if err := daemon.setHostConfig(container, hostConfig); err != nil {
return err
}
}
if err := container.Start(); err != nil {
container.LogEvent("die")
return fmt.Errorf("Cannot start container %s: %s", name, err)
+2 -1
View File
@@ -42,7 +42,8 @@ func mergeLxcConfIntoOptions(hostConfig *runconfig.HostConfig) ([]string, error)
// merge in the lxc conf options into the generic config map
if lxcConf := hostConfig.LxcConf; lxcConf != nil {
for _, pair := range lxcConf {
lxSlice := lxcConf.Slice()
for _, pair := range lxSlice {
// because lxc conf gets the driver name lxc.XXXX we need to trim it off
// and let the lxc driver add it back later if needed
if !strings.Contains(pair.Key, ".") {
+4 -3
View File
@@ -7,10 +7,11 @@ import (
)
func TestMergeLxcConfig(t *testing.T) {
kv := []runconfig.KeyValuePair{
{"lxc.cgroups.cpuset", "1,2"},
}
hostConfig := &runconfig.HostConfig{
LxcConf: []runconfig.KeyValuePair{
{Key: "lxc.cgroups.cpuset", Value: "1,2"},
},
LxcConf: runconfig.NewLxcConfig(kv),
}
out, err := mergeLxcConfIntoOptions(hostConfig)