Skip to content

Commit cd1aa5c

Browse files
authored
Merge pull request #885 from dtrudg/issue883
feat: `bind-paths` option for `--no-mount` flag
2 parents 702930d + c91b1da commit cd1aa5c

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
specified instance, running within a cgroup.
2222
- Add `--sparse` flag to `overlay create` command to allow generation of a
2323
sparse ext3 overlay image.
24+
- The `--no-mount` flag now accepts the value `bind-paths` to disable mounting of
25+
all `bind path` entries in `singularity.conf.
2426

2527
### Bug Fixes
2628

cmd/internal/cli/action_flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ var actionNoMountFlag = cmdline.Flag{
460460
Value: &NoMount,
461461
DefaultValue: []string{},
462462
Name: "no-mount",
463-
Usage: "disable one or more 'mount xxx' options set in singularity.conf, specify absolute destination path to disable a 'bind path' entry",
463+
Usage: "disable one or more 'mount xxx' options set in singularity.conf, specify absolute destination path to disable a bind path entry, or 'bind-paths' to disable all bind path entries.",
464464
EnvKeys: []string{"NO_MOUNT"},
465465
}
466466

cmd/internal/cli/actions_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ func setNoMountFlags(c *singularityConfig.EngineConfig) {
237237
c.SetNoHostfs(true)
238238
case "cwd":
239239
c.SetNoCwd(true)
240+
// All bind path singularity.conf entries
241+
case "bind-paths":
242+
skipBinds = append(skipBinds, "*")
240243
default:
244+
// Single bind path singularity.conf entry by abs path
241245
if filepath.IsAbs(v) {
242246
skipBinds = append(skipBinds, v)
243247
continue

e2e/actions/actions.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,23 @@ func (c actionTests) actionNoMount(t *testing.T) {
22392239
testContained: true,
22402240
exit: 0,
22412241
},
2242+
// bind-paths should disable all of the bind path mounts - including both defaults
2243+
{
2244+
name: "binds-paths-hosts",
2245+
noMount: "bind-paths",
2246+
noMatch: "on /etc/hosts",
2247+
testDefault: true,
2248+
testContained: true,
2249+
exit: 0,
2250+
},
2251+
{
2252+
name: "bind-paths-localtime",
2253+
noMount: "bind-paths",
2254+
noMatch: "on /etc/localtime",
2255+
testDefault: true,
2256+
testContained: true,
2257+
exit: 0,
2258+
},
22422259
}
22432260

22442261
for _, tt := range tests {

internal/pkg/runtime/engine/singularity/container_linux.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,8 @@ func (c *container) addBindsMount(system *mount.System) error {
15271527
localtimePath = "/etc/localtime"
15281528
)
15291529

1530-
noBinds := c.engine.EngineConfig.GetNoBinds()
1530+
skipBinds := c.engine.EngineConfig.GetSkipBinds()
1531+
skipAllBinds := slice.ContainsString(skipBinds, "*")
15311532

15321533
if c.engine.EngineConfig.GetContain() {
15331534
hosts := hostsPath
@@ -1548,7 +1549,7 @@ func (c *container) addBindsMount(system *mount.System) error {
15481549
hosts, _ = c.session.GetPath(hostsPath)
15491550
}
15501551

1551-
if !slice.ContainsString(noBinds, hostsPath) {
1552+
if !skipAllBinds && !slice.ContainsString(skipBinds, hostsPath) {
15521553
// #5465 If hosts/localtime mount fails, it should not be fatal so skip-on-error
15531554
if err := system.Points.AddBind(mount.BindsTag, hosts, hostsPath, flags, "skip-on-error"); err != nil {
15541555
return fmt.Errorf("unable to add %s to mount list: %s", hosts, err)
@@ -1557,7 +1558,7 @@ func (c *container) addBindsMount(system *mount.System) error {
15571558
return fmt.Errorf("unable to add %s for remount: %s", hostsPath, err)
15581559
}
15591560
}
1560-
if !slice.ContainsString(noBinds, localtimePath) {
1561+
if !skipAllBinds && !slice.ContainsString(skipBinds, localtimePath) {
15611562
if err := system.Points.AddBind(mount.BindsTag, localtimePath, localtimePath, flags, "skip-on-error"); err != nil {
15621563
return fmt.Errorf("unable to add %s to mount list: %s", localtimePath, err)
15631564
}
@@ -1580,7 +1581,7 @@ func (c *container) addBindsMount(system *mount.System) error {
15801581

15811582
sylog.Verbosef("Found 'bind path' = %s, %s", src, dst)
15821583

1583-
if slice.ContainsString(noBinds, dst) {
1584+
if skipAllBinds || slice.ContainsString(skipBinds, dst) {
15841585
sylog.Debugf("Skipping bind to %s at user request", dst)
15851586
continue
15861587
}

pkg/runtime/engine/singularity/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func (e *EngineConfig) SetSkipBinds(val []string) {
484484
}
485485

486486
// GetSkipBinds gets bind paths to skip
487-
func (e *EngineConfig) GetNoBinds() []string {
487+
func (e *EngineConfig) GetSkipBinds() []string {
488488
return e.JSON.SkipBinds
489489
}
490490

0 commit comments

Comments
 (0)