Skip to content

Commit ecdc8ef

Browse files
author
Zhou Hao
authored
Merge pull request #544 from rhatdan/mounts
Add interface to remove mounts.
2 parents 9c39ab5 + 8397b70 commit ecdc8ef

5 files changed

Lines changed: 41 additions & 0 deletions

File tree

cmd/oci-runtime-tool/generate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var generateFlags = []cli.Flag{
8888
cli.StringSliceFlag{Name: "linux-sysctl", Usage: "add sysctl settings e.g net.ipv4.forward=1"},
8989
cli.StringSliceFlag{Name: "linux-uidmappings", Usage: "add UIDMappings e.g HostID:ContainerID:Size"},
9090
cli.StringSliceFlag{Name: "mounts-add", Usage: "configures additional mounts inside container"},
91+
cli.StringSliceFlag{Name: "mounts-remove", Usage: "remove destination mountpoints from inside container"},
9192
cli.BoolFlag{Name: "mounts-remove-all", Usage: "remove all mounts inside container"},
9293
cli.StringFlag{Name: "output", Usage: "output file (defaults to stdout)"},
9394
cli.BoolFlag{Name: "privileged", Usage: "enable privileged container settings"},
@@ -432,6 +433,13 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
432433
g.ClearMounts()
433434
}
434435

436+
if context.IsSet("mounts-remove") {
437+
mounts := context.StringSlice("mounts-remove")
438+
for _, mount := range mounts {
439+
g.RemoveMount(mount)
440+
}
441+
}
442+
435443
if context.IsSet("mounts-add") {
436444
mounts := context.StringSlice("mounts-add")
437445
for _, mount := range mounts {

completions/bash/oci-runtime-tool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ _oci-runtime-tool_generate() {
364364
--linux-sysctl
365365
--linux-uidmappings
366366
--mounts-add
367+
--mounts-remove
367368
--output
368369
--process-cap-add-ambient
369370
--process-cap-add-bounding

generate/generate.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,25 @@ func (g *Generator) AddMount(mnt rspec.Mount) {
988988
g.spec.Mounts = append(g.spec.Mounts, mnt)
989989
}
990990

991+
// RemoveMount removes a mount point on the dest directory
992+
func (g *Generator) RemoveMount(dest string) {
993+
g.initSpec()
994+
995+
for index, mount := range g.spec.Mounts {
996+
if mount.Destination == dest {
997+
g.spec.Mounts = append(g.spec.Mounts[:index], g.spec.Mounts[index+1:]...)
998+
return
999+
}
1000+
}
1001+
}
1002+
1003+
// Mounts returns the list of mounts
1004+
func (g *Generator) Mounts() []rspec.Mount {
1005+
g.initSpec()
1006+
1007+
return g.spec.Mounts
1008+
}
1009+
9911010
// ClearMounts clear g.spec.Mounts
9921011
func (g *Generator) ClearMounts() {
9931012
if g.spec == nil {

generate/generate_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,12 @@ func TestGenerateValid(t *testing.T) {
5454
}
5555
}
5656
}
57+
58+
func TestRemoveMount(t *testing.T) {
59+
g := generate.New()
60+
size := len(g.Mounts())
61+
g.RemoveMount("/dev/shm")
62+
if size-1 != len(g.Mounts()) {
63+
t.Errorf("Unable to remove /dev/shm from mounts")
64+
}
65+
}

man/oci-runtime-tool-generate.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ read the configuration from `config.json`.
348348
C. mount for windows platform
349349
--mount-add '{"destination": "C:\\folder-inside-container","source": "C:\\folder-on-host","options": ["ro"]}'
350350

351+
**--mounts-remove**=[]
352+
Remove mounts to destination path from inside container.
353+
This option can be specified multiple times.
354+
351355
**--mounts-remove-all**=true|false
352356
Remove all mounts inside the container. The default is *false*.
353357
When specified with --mount-add, this option will be parsed first.

0 commit comments

Comments
 (0)