Skip to content

Commit

Permalink
Overlay mounts supersede image volumes & volumes-from
Browse files Browse the repository at this point in the history
This matches the behavior of other volume and mount types. Image
volumes and volumes/mounts from the `--volumes-from` flag should
be overridden by actual user-specified named volumes and mounts,
but this was not true for overlay mounts. Fortunately, our
duplicate-mount detection logic still works, so we got a good
error message at least.

The fix is simple - extend our supersede logic, which currently
only works with named volumes and mounts, to also work with
overlay mounts.

Fixes containers#24555

Signed-off-by: Matt Heon <[email protected]>
  • Loading branch information
mheon committed Nov 14, 2024
1 parent 5dbb567 commit 4409108
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/specgen/generate/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ func finalizeMounts(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Ru
delete(baseMounts, dest)
}

// Overlays are neither mounts nor volumes but should supercede both.
for dest := range unifiedOverlays {
delete(baseVolumes, dest)
delete(baseMounts, dest)
}

// Supersede volumes-from/image volumes with unified volumes from above.
// This is an unconditional replacement.
for dest, mount := range unifiedMounts {
Expand All @@ -169,16 +175,22 @@ func finalizeMounts(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Ru
// TODO: Investigate moving readonlyTmpfs into here. Would be more
// correct.

// Check for conflicts between named volumes and mounts
// Check for conflicts between named volumes, mounts, and overlays
for dest := range baseMounts {
if _, ok := baseVolumes[dest]; ok {
return nil, nil, nil, fmt.Errorf("baseMounts conflict at mount destination %v: %w", dest, specgen.ErrDuplicateDest)
}
if _, ok := unifiedOverlays[dest]; ok {
return nil, nil, nil, fmt.Errorf("baseMounts conflict with overlay mount at mount destination %v: %w", dest, specgen.ErrDuplicateDest)
}
}
for dest := range baseVolumes {
if _, ok := baseMounts[dest]; ok {
return nil, nil, nil, fmt.Errorf("baseVolumes conflict at mount destination %v: %w", dest, specgen.ErrDuplicateDest)
}
if _, ok := unifiedOverlays[dest]; ok {
return nil, nil, nil, fmt.Errorf("baseVolumes conflict with overlay mount at mount destination %v: %w", dest, specgen.ErrDuplicateDest)
}
}

if s.ReadWriteTmpfs != nil && *s.ReadWriteTmpfs {
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,4 +1089,20 @@ RUN chmod 755 /test1 /test2 /test3`, ALPINE)
Expect(checkCtr.OutputToString()).To(ContainSubstring("foo"))
Expect(checkCtr.OutputToString()).To(ContainSubstring("bar"))
})

It("user-specified overlay supersedes image volume", func() {
err = podmanTest.RestoreArtifact(REDIS_IMAGE)
Expect(err).ToNot(HaveOccurred())
mountPath := filepath.Join(podmanTest.TempDir, "secrets")
err := os.Mkdir(mountPath, 0755)
Expect(err).ToNot(HaveOccurred())
testFile := filepath.Join(mountPath, "test1")
f, err := os.Create(testFile)
Expect(err).ToNot(HaveOccurred(), "os.Create(testfile)")
f.Close()
Expect(err).ToNot(HaveOccurred())
session := podmanTest.Podman([]string{"run", "-v", fmt.Sprintf("%s:/data:O", mountPath), REDIS_IMAGE, "ls", "/data/test1"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
})
})

0 comments on commit 4409108

Please sign in to comment.