Skip to content
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

Enable setting networking mode for docker #184

Merged
merged 1 commit into from
Oct 2, 2015
Merged

Enable setting networking mode for docker #184

merged 1 commit into from
Oct 2, 2015

Conversation

achanda
Copy link
Contributor

@achanda achanda commented Oct 1, 2015

This patch enables setting networking mode for the docker
driver. This does not handle the container mode.
Closes #175

@dimfeld
Copy link
Contributor

dimfeld commented Oct 1, 2015

Thanks for putting this together! How about having NetworkMode specified in the task's Config member instead, since it's driver-specific, and not a resource that is taken up?

@achanda
Copy link
Contributor Author

achanda commented Oct 1, 2015

@dimfeld updated.

@dimfeld
Copy link
Contributor

dimfeld commented Oct 1, 2015

Nice, thanks :)

@dimfeld
Copy link
Contributor

dimfeld commented Oct 1, 2015

An another note, I wonder if you would still want to allow Resources.Networks to have entries, since that could be used to reserve ports and ensure that jobs with conflicting ports aren't scheduled on the same node. Of course this would also then require the docker client to not actually configure those ports in host mode; it would be more an advisory for the scheduler. But I'll have to defer to people who actually work at Hashicorp for this one.

Also, panicking inside the client due to bad user input is probably not the best idea either, since it'll kill the client and possibly be disruptive to the network unless there's some recover up the chain somewhere (I haven't looked).

@achanda
Copy link
Contributor Author

achanda commented Oct 1, 2015

There is no recover afaik. Let's see what the Hashicorp folks suggest.

@@ -118,6 +118,22 @@ 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 := task.Config["network_mode"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check if the value exists in the map using the tupled return type like: if mode, ok := task.Config["network_mode"]. Should make using the default cleaner.

@ryanuber
Copy link
Member

ryanuber commented Oct 1, 2015

Left some comments above. Thanks!

@achanda
Copy link
Contributor Author

achanda commented Oct 1, 2015

@ryanuber all addressed

@zenvdeluca
Copy link

nice job here!

@achanda
Copy link
Contributor Author

achanda commented Oct 1, 2015

Thanks @zenvdeluca Looking forward to getting this merged :)

case "default", "bridge", "none":
logger.Printf("[DEBUG] driver.docker: using %s as network mode", mode)
case "host":
if len(task.Resources.Networks) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect behavior. If tasks bind to ports not given to them by the scheduler then there is the possibility that the scheduler will place a subsequent job with a constraint on a port onto a client that has a task bound to it (this creates a loss of information for the scheduler).

It is okay to bind to the host network namespace but you must only bind to ports specified in the task.Resources.Networks. This goes for all drivers.

So lets remove that warning.

@achanda
Copy link
Contributor Author

achanda commented Oct 2, 2015

@dadgar this is a task config, so I put it in the task section. Two different tasks in the same client can have different modes.

* `network_mode` - (Optional) The network mode to be used for the container.
Valid options are `net`, `bridge`, `host` or `none`. If nothing is
specified, the container will start in `bridge` mode. The `container`
network mode is not suuported right now.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suuported -> currently supported

  • Small typo

This patch enables setting networking mode for the docker
driver. This does not handle the `container` mode.
Closes #175
dadgar added a commit that referenced this pull request Oct 2, 2015
Enable setting networking mode for docker
@dadgar dadgar merged commit 96b6109 into hashicorp:master Oct 2, 2015
@achanda achanda deleted the docker_net branch October 2, 2015 02:34
@github-actions
Copy link

github-actions bot commented May 9, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants