-
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
LXC Support #1699
LXC Support #1699
Conversation
9fb4534
to
be33c11
Compare
return nil, fmt.Errorf("unable to start container: %v", err) | ||
} | ||
// Set the resource limits | ||
if err := c.SetMemoryLimit(lxc.ByteSize(task.Resources.MemoryMB) * lxc.MB); err != nil { |
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.
Should this come before c.Start()
?
Neither of my comments are blockers. LGTM |
2a4c13f
to
27b0774
Compare
@schmichael Addressed all your comments. |
@dadgar I would recommend merging this PR since the basic features have been implemented. We can add support for downloading support of rootfs and MacVLAN in subsequent PRs. Can you please review this? |
6b22537
to
e512245
Compare
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.
The multiple SetConfigItem calls are my only concern. If you've verified it works as expected
if err := c.SetConfigItem("lxc.mount.entry", allocDirMount); err != nil { | ||
return nil, fmt.Errorf("error setting alloc dir bind mounts configuration: %v", err) | ||
} | ||
if err := c.SetConfigItem("lxc.mount.entry", taskDirMount); err != nil { |
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.
Calling SetConfigItem("lxc.mount.entry",...
twice will append the second entry, not overwrite the first?
I couldn't tell from looking at the lxc docs.
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.
No it won't, if you look at lxc configuration there can be multiple lxc.mount.entry
- as many fstab entries you want.
func (h *lxcDriverHandle) Kill() error { | ||
h.logger.Printf("[INFO] driver.lxc: shutting down container %q", h.container.Name()) | ||
if err := h.container.Shutdown(h.killTimeout); err != nil { | ||
h.logger.Printf("[INFO] driver.lxc: shutting down container %q failed: %v", h.container.Name(), err) |
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.
INFO
-> WARN
perhaps?
) | ||
|
||
const ( | ||
|
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.
Extra line?
) | ||
|
||
// Add the lxc driver to the list of builtin drivers | ||
func init() { |
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.
Why is this here, do it like the other drivers?
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.
@dadgar So that we don't have to build the driver on other platforms. This driver needs the lxc-dev package which is unavailable on other platforms.
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.
Ah missed the build tag
if err := mapstructure.WeakDecode(task.Config, &driverConfig); err != nil { | ||
return nil, err | ||
} | ||
lxcPath := lxc.DefaultConfigPath() |
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.
Can we set the path to be the task_dir?
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.
I am not very sure if we can have multiple Config Paths on a machine, usually all the containers live in /var/lib/lxc
. Having it in the task dir is desirable since then we can make use of disk space accounting.
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.
LXC allows unprovileged containers, i.e. I can run nomad as nomad user & without any root privileges to spin LXC containers owned by nomad user. In such setup, generally the containers will stay at /home/nomad/.local/share/lxc (or $HOME/.local/share/lxc).. but this is configurable. I am not aware of any case where the nomad client would be running as different user /or same user with different lxc path.
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.
So the lxc path can be configurable by the operator. I think @dadgar is suggesting using a different path per container.
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.
Yes I was suggesting specific path per container. I was looking at lxc docs and it seems like you can
@diptanu i took this for a spin during the weekend. Its working on my cluster. Could not get to went through all the code. I think you should enable wantdaemonize + close file descriptor by default. |
e512245
to
1566b97
Compare
|
||
const ( | ||
// The option that enables this driver in the Config.Options map. | ||
lxcConfigOption = "driver.lxc.enable" |
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.
Is this documented on the website?
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.
comments should start with the variable/constant/method/struct name
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.
Fixed the comment.
@diptanu did you get a chance to write any docs? If not I don't mind doing it.
return nil, err | ||
} | ||
lxcPath := lxc.DefaultConfigPath() | ||
if path := d.config.Read("lxc.path"); path != "" { |
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.
shouldn't this be driver.lxc.path
and document it
taskLocalDir, ok := ctx.AllocDir.TaskDirs[task.Name] | ||
if !ok { | ||
return nil, fmt.Errorf("failed to find task local directory: %v", task.Name) | ||
} |
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.
This is wrong, see #1830
} | ||
|
||
// Set the resource limits | ||
if err := c.SetMemoryLimit(lxc.ByteSize(task.Resources.MemoryMB) * lxc.MB); err != nil { |
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.
Set resources before starting?
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. |
This PR implements support for the LXC driver. The driver is enabled only in Linux.