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