Repository navigation
fix mount propagation causing repeated runs - #3602
Conversation
fixes dagger#3551 propagate mounts from the result of running the command with every mount, rather than one at a time as we iterate, which meant each mount technically had a different llb state. Signed-off-by: Alex Suraci <[email protected]>
"Stacking" in this commit means mounting over a path rather than replacing it. On Linux this is allowed and unmounting the upper mount will reveal the lower one. Buildkit however currently assumes mounts have unique paths: * GetMount returns the first one listed, rather than the last, which is what you'd want for stacked mounts as it's the mount that was actually visible to the process. * Many APIs (e.g. Marshal) internally sort the mounts by the target name, implying that they don't expect collisions and marshaling may become nondeterministic without stable sorting. So instead we'll just replace any mounts at the exact same target path. It is no longer possible to unmount it to reveal the prior mount. We could change Buildkit to not do this sorting and to have GetMount return the upper mount, but for now this seems like the safest step assuming this is not a common use case. We can always re-introduce stacking if/when Buildkit supports it. Signed-off-by: Alex Suraci <[email protected]>
| var replaced bool | ||
| for i, mnt := range mntsCp { | ||
| if mnt.Target == newMnt.Target { | ||
| mntsCp[i] = newMnt |
There was a problem hiding this comment.
Might be better to remove from the found index and append to the end instead to match stacking semantics, i.e. so later mounts to subpaths of the target don't mount "over" it. Not sure if that's what'll actually happen though.
There was a problem hiding this comment.
AFAICT this is handled on our behalf by the sorting of mount targets in the LLB code, so I think we're fine? Could add a test case that does something like:
- Mount A at /foo/bar
- Mount B at /foo (blocks out previous mount)
- Mount C at /foo/bar
Where the expected behavior should be that C is actually visible.
There was a problem hiding this comment.
Oh right, so it doesn't really matter where we insert.
Added a test that checks that when adding mount B above, mount A is removed and we can still add mount C after. I think this is more correct than the current behavior which allows it to stick around. But we're really splitting hairs, I'd be equally happy to remove this and leave the behavior undefined until someone has a use case. 🤷
sipsma
left a comment
There was a problem hiding this comment.
LGTM, one comment about a possible test to add to verify behavior.
It seems like if we modified upstream client/llb to instead call sort.SliceStable on exec state mounts then we could probably retain the stacking behavior (?), but this case of stacked vs. non-stacked is obscure enough that I don't think it matters right now.
| var replaced bool | ||
| for i, mnt := range mntsCp { | ||
| if mnt.Target == newMnt.Target { | ||
| mntsCp[i] = newMnt |
There was a problem hiding this comment.
AFAICT this is handled on our behalf by the sorting of mount targets in the LLB code, so I think we're fine? Could add a test case that does something like:
- Mount A at /foo/bar
- Mount B at /foo (blocks out previous mount)
- Mount C at /foo/bar
Where the expected behavior should be that C is actually visible.
clobbering in this PR means mounting in this order: * /mnt/foo * /mnt * /mnt/bar In this case we should expect /mnt/foo to disappear when /mnt is mounted, and for /mnt/bar to be visible with new content since it was mounted over the clobberer. (/mnt/bar could also be /mnt/foo but it's easier to explain this way.) Signed-off-by: Alex Suraci <[email protected]>
@sipsma Yeah, I think so, but at this point I'm a little worried about any other areas in Buildkit that assume mounts are unique. Agree that it seems sufficiently edge-casey to not worry about going above and beyond. This is ready for another look, I tweaked the replacing semantics to simulate more aspects of stacking (basically remove /mnt/foo when mounting over /mnt). |
fixes #3551