-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix an issue where settings were not taking effect #197
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,22 @@ func (d *DockerDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool | |
func createHostConfig(task *structs.Task) *docker.HostConfig { | ||
// hostConfig holds options for the docker container that are unique to this | ||
// machine, such as resource limits and port mappings | ||
|
||
mode, ok := task.Config["network_mode"] | ||
if !ok || mode == "" { | ||
// docker default | ||
logger.Printf("[WARN] driver.docker: no mode specified for networking, using Docker default") | ||
mode = "default" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just get rid of this block since we do almost the same thing below in the |
||
} | ||
|
||
// Ignore the container mode for now | ||
switch mode { | ||
case "default", "bridge", "none", "host": | ||
logger.Printf("[DEBUG] driver.docker: using %s as network mode", mode) | ||
default: | ||
logger.Printf("[WARN] invalid setting for network mode %s, defaulting to bridge mode on docker0", mode) | ||
mode = "default" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should either set the mode to "bridge", or change the message to say "using default network mode on docker0". |
||
} | ||
return &docker.HostConfig{ | ||
// Convert MB to bytes. This is an absolute value. | ||
// | ||
|
@@ -105,6 +121,7 @@ func createHostConfig(task *structs.Task) *docker.HostConfig { | |
// - https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt | ||
// - https://www.kernel.org/doc/Documentation/scheduler/sched-design-CFS.txt | ||
CPUShares: int64(task.Resources.CPU), | ||
NetworkMode: mode, | ||
} | ||
} | ||
|
||
|
@@ -118,23 +135,6 @@ func createContainer(ctx *ExecContext, task *structs.Task, logger *log.Logger) d | |
logger.Printf("[DEBUG] driver.docker: using %d bytes memory for %s", hostConfig.Memory, task.Config["image"]) | ||
logger.Printf("[DEBUG] driver.docker: using %d cpu shares for %s", hostConfig.CPUShares, task.Config["image"]) | ||
|
||
mode, ok := task.Config["network_mode"] | ||
if !ok || mode == "" { | ||
// docker default | ||
logger.Printf("[WARN] driver.docker: no mode specified for networking, defaulting to bridge") | ||
mode = "bridge" | ||
} | ||
|
||
// Ignore the container mode for now | ||
switch mode { | ||
case "default", "bridge", "none", "host": | ||
logger.Printf("[DEBUG] driver.docker: using %s as network mode", mode) | ||
default: | ||
logger.Printf("[WARN] invalid setting for network mode %s, defaulting to bridge mode on docker0", mode) | ||
mode = "bridge" | ||
} | ||
hostConfig.NetworkMode = mode | ||
|
||
// Setup port mapping (equivalent to -p on docker CLI). Ports must already be | ||
// exposed in the container. | ||
if len(task.Resources.Networks) == 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the logger into this method.