-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Allow mounting a sub-directory of a named volume #39041
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
Conversation
|
This feature also needs PRs on docker/swarmkit and docker/cli. I will follow up with PRs for this feature against those 2 repos if this PR is approved as a first draft. |
thaJeztah
left a comment
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.
Thank you! I only had a quick look at the changes, but left some comments
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 should work on a remote daemon as well?
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.
Thank you for the review. Yes. This was because I was starting a daemon directly, which was not needed. I will update the test to only use a client from the test environment.
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.
We might need some more test-cases (probably good to combine them in a single test, using subtests). Thinking of;
- A container using the same volume twice but with different sub-paths (also to make sure reference-counting works correctly (although I'm not sure if that makes a difference - just a quick thought)
- A test where a non-existing sub-path is used (i.e., make sure if produces an error)
- Multiple containers using the same volume + sub-paths? (not sure if needed; just thinking out loud; is reference-counting the same?)
- What happens if the volume is used twice (either the same container or different containers), and the chosen sub-paths lead to "nested mounts"? (i.e. mount sub-path
/foo/bar/bazand/foo/bar?)- does this lead to problems, such as "unable to unmount" if one container is stopped?
- what happens with
NoCopy=falseif the container that uses/foo/barhappens to have a subdirectory (or file) named/foo/bar/baz?
Perhaps there's more/other (corner) cases that we should check for.
edit: I just noticed you have a test for the non-existent path below; still might be worth looking for some additional cases 😅
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.
Thanks, I will look into adding more test cases (looks like most of these cases need integration tests), while waiting for more review comments.
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 have added a test for one container mounting the same volume twice, with different sub-paths. I think a single container will count as 1 reference to the volume, regardless of how many times it mounts the volume using different sub-paths, since the reference counting for each volume is based on container ID.
-
Non-existent sub-path test, as you mentioned in the comment, is covered by unit tests (I added an integration test too, but perhaps it can be removed once it has served its purpose of verifying the propagation of non-existent sub-path error)
-
With the current implementation proposed by this PR, the sub-path logic is in the
MountPointlayer, and thus will not affect the reference counting (volume name + container id combination), i.e. mounting the same volume in different containers will have the same effect on reference counts with or without sub-path option (please let me know if this requires an explicit integration test).
Regarding overlap of sub-paths:
-
With one or multiple containers mounting a single volume, I could not find a scenario where overlap of sub-paths would affect ability to un-mount the volume, as the the reference count remains the same. (unless there is another mechanism/aspect that I have missed). The PR now includes an integration test for verifying.
-
Copying contents from the FS of a container’s image into a volume currently requires the to-be-populated volume to be empty, i.e. there won’t be an overlap between the image’s FS and the specified sub-dir. The checks performed on mounts, prior to any copying to volumes, includes verifying the existence of the specified sub-path. (I have added an integration test to warn against possible changes to this behaviour).
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.
Wondering; does container.Run not fail by itself already? (i.e., do we need the poll.WaitOn to check manually?) 🤔
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.
Looking at the code (and running a few quick tests), container.Run does not fail if the command running in the container exits with non-zero error code, which is what this test uses to make sure the mounting of the sub-dir was done correctly in the second container.
volume/mounts/windows_parser.go
Outdated
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 see there's other lines like this in this file, so probably this is correct (just thinking about the LCOW situation, but not sure if we hit this part of the code for that)
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.
It seems the LCOW parser uses the windows parser, except for a different regular expression for the destination:
moby/volume/mounts/lcow_parser.go
Lines 20 to 22 in 6d18c6a
| type lcowParser struct { | |
| windowsParser | |
| } |
moby/volume/mounts/lcow_parser.go
Lines 32 to 33 in 6d18c6a
| func (p *lcowParser) ParseMountSpec(cfg mount.Mount) (*MountPoint, error) { | |
| return p.parseMountSpec(cfg, rxLCOWDestination, false, lcowSpecificValidators) |
I will update the test case in parser_test.go to cover the conversion of the path separator.
|
@cpuguy83 @kolyshkin ptal |
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
cfdcd8b to
b51c044
Compare
Codecov Report
@@ Coverage Diff @@
## master #39041 +/- ##
=========================================
Coverage ? 37.04%
=========================================
Files ? 612
Lines ? 45421
Branches ? 0
=========================================
Hits ? 16828
Misses ? 26306
Partials ? 2287 |
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
b51c044 to
f65a159
Compare
|
Other than the expected failure on |
|
needs rebase |
| err = client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) | ||
| assert.NilError(t, err) | ||
| return volumeName | ||
| } |
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.
We should have tests for SubPath: "../../../../../../../../../.."
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 we use something like https://github.com/cyphar/filepath-securejoin ?
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
| } | ||
|
|
||
| if !strings.HasPrefix(realPath, volumePath) { | ||
| return "", errors.Errorf("directory %s outside of the volume root %s", realPath, volumePath) |
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.
Let's prohibit all .. symbols statically before calling filepath.Join
- What I did
Added ability to mount a subdir of a volume. Part of the work required to address #32582
- How I did it
Added the required support to api,
volume/mountspackage, and thedaemon/cluster.- How to verify it
An integration test has been added under
integration/container/mounts_linux_test.go- Description for the changelog
Allow mounting a sub-directory of a named volume
- A picture of a cute animal (not mandatory but encouraged)