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

Add support for passing device into docker driver #3512

Merged
merged 5 commits into from
Nov 13, 2017

Conversation

preetapan
Copy link
Contributor

Fixes #2938

Copy link
Member

@schmichael schmichael left a comment

Choose a reason for hiding this comment

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

Looks good! Maybe just add some sort of integration test to make sure Docker doesn't fail when creating a container with devices set like we talked about.

if len(driverConfig.Devices) > 0 {
var devices []docker.Device
for _, device := range driverConfig.Devices {
if device.HostPath != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to check this since validate will fail if HostPath is empty?

if _, err := driver.Prestart(ctx.ExecCtx, task); err != nil {
t.Fatalf("unexpected error:%v", err)
}

Copy link
Member

Choose a reason for hiding this comment

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

Can we start and stat the file to make sure it exists? A lot of tests do this with the waitForExist helper and then inspecting the created container:

func TestDockerDriver_Labels(t *testing.T) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I validated that the hostConfig from docker inspect output showed the mounted device. Didn't do a stat of the device file. All the existing tests were reading things off the output of docker inspect so I did the same, this should verify that the device mounting did work.

for _, c := range dev.CgroupPermissions {
ch := string(c)
if ch != "r" && ch != "w" && ch != "m" {
return fmt.Errorf("invalid cgroup permission string: %q", dev.CgroupPermissions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this validation logic after reading https://docs.docker.com/engine/reference/commandline/run/#add-host-device-to-container-device. Also, note this sentence at the end of that documentation: Note: --device cannot be safely used with ephemeral devices. Block devices that may be removed should not be added to untrusted containers with --device. The documentation you linked above for --device-cgroup-rule for dynamic devices, which looks like something else. I could be missing something though.

We can create another follow up ticket to add configuration for --device-cgroup-rule without needing --device if this is something people need.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah thanks for clarifying!

@preetapan preetapan merged commit 3756e72 into master Nov 13, 2017
@preetapan preetapan deleted the b-docker-device-option branch November 15, 2017 14:23
@github-actions
Copy link

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 Mar 17, 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

3 participants