mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
Add Options to discover.Mount
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
21f5895b5a
commit
3f70521a63
@ -58,7 +58,11 @@ func (d *charDevices) Devices() ([]Device, error) {
|
||||
}
|
||||
var devices []Device
|
||||
for _, mount := range devicesAsMounts {
|
||||
devices = append(devices, Device(mount))
|
||||
device := Device{
|
||||
HostPath: mount.HostPath,
|
||||
Path: mount.Path,
|
||||
}
|
||||
devices = append(devices, device)
|
||||
}
|
||||
|
||||
return devices, nil
|
||||
|
@ -32,6 +32,7 @@ type Device struct {
|
||||
type Mount struct {
|
||||
HostPath string
|
||||
Path string
|
||||
Options []string
|
||||
}
|
||||
|
||||
// Hook represents a discovered hook.
|
||||
|
@ -93,6 +93,12 @@ func (d *mounts) Mounts() ([]Mount, error) {
|
||||
uniqueMounts[p] = Mount{
|
||||
HostPath: p,
|
||||
Path: r,
|
||||
Options: []string{
|
||||
"ro",
|
||||
"nosuid",
|
||||
"nodev",
|
||||
"bind",
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,14 @@ func TestMountsReturnsEmptyDevices(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMounts(t *testing.T) {
|
||||
|
||||
mountOptions := []string{
|
||||
"ro",
|
||||
"nosuid",
|
||||
"nodev",
|
||||
"bind",
|
||||
}
|
||||
|
||||
logger, logHook := testlog.NewNullLogger()
|
||||
|
||||
testCases := []struct {
|
||||
@ -70,7 +78,7 @@ func TestMounts(t *testing.T) {
|
||||
},
|
||||
required: []string{"required"},
|
||||
},
|
||||
expectedMounts: []Mount{{Path: "located", HostPath: "located"}},
|
||||
expectedMounts: []Mount{{Path: "located", HostPath: "located", Options: mountOptions}},
|
||||
},
|
||||
{
|
||||
description: "mounts removes located duplicates",
|
||||
@ -83,7 +91,7 @@ func TestMounts(t *testing.T) {
|
||||
},
|
||||
required: []string{"required0", "required1"},
|
||||
},
|
||||
expectedMounts: []Mount{{Path: "located", HostPath: "located"}},
|
||||
expectedMounts: []Mount{{Path: "located", HostPath: "located", Options: mountOptions}},
|
||||
},
|
||||
{
|
||||
description: "mounts skips located errors",
|
||||
@ -98,7 +106,7 @@ func TestMounts(t *testing.T) {
|
||||
},
|
||||
required: []string{"required0", "error", "required1"},
|
||||
},
|
||||
expectedMounts: []Mount{{Path: "required0", HostPath: "required0"}, {Path: "required1", HostPath: "required1"}},
|
||||
expectedMounts: []Mount{{Path: "required0", HostPath: "required0", Options: mountOptions}, {Path: "required1", HostPath: "required1", Options: mountOptions}},
|
||||
},
|
||||
{
|
||||
description: "mounts skips unlocated",
|
||||
@ -113,7 +121,7 @@ func TestMounts(t *testing.T) {
|
||||
},
|
||||
required: []string{"required0", "empty", "required1"},
|
||||
},
|
||||
expectedMounts: []Mount{{Path: "required0", HostPath: "required0"}, {Path: "required1", HostPath: "required1"}},
|
||||
expectedMounts: []Mount{{Path: "required0", HostPath: "required0", Options: mountOptions}, {Path: "required1", HostPath: "required1", Options: mountOptions}},
|
||||
},
|
||||
{
|
||||
description: "mounts adds multiple",
|
||||
@ -129,10 +137,10 @@ func TestMounts(t *testing.T) {
|
||||
required: []string{"required0", "multiple", "required1"},
|
||||
},
|
||||
expectedMounts: []Mount{
|
||||
{Path: "required0", HostPath: "required0"},
|
||||
{Path: "multiple0", HostPath: "multiple0"},
|
||||
{Path: "multiple1", HostPath: "multiple1"},
|
||||
{Path: "required1", HostPath: "required1"},
|
||||
{Path: "required0", HostPath: "required0", Options: mountOptions},
|
||||
{Path: "multiple0", HostPath: "multiple0", Options: mountOptions},
|
||||
{Path: "multiple1", HostPath: "multiple1", Options: mountOptions},
|
||||
{Path: "required1", HostPath: "required1", Options: mountOptions},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -147,7 +155,7 @@ func TestMounts(t *testing.T) {
|
||||
required: []string{"required0", "multiple", "required1"},
|
||||
},
|
||||
expectedMounts: []Mount{
|
||||
{Path: "/located", HostPath: "/some/root/located"},
|
||||
{Path: "/located", HostPath: "/some/root/located", Options: mountOptions},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -40,12 +40,7 @@ func (d mount) toSpec() *specs.Mount {
|
||||
s := specs.Mount{
|
||||
HostPath: d.HostPath,
|
||||
ContainerPath: d.Path,
|
||||
Options: []string{
|
||||
"ro",
|
||||
"nosuid",
|
||||
"nodev",
|
||||
"bind",
|
||||
},
|
||||
Options: d.Options,
|
||||
}
|
||||
|
||||
return &s
|
||||
|
Loading…
Reference in New Issue
Block a user