mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-24 21:14:00 +00:00
Add ability to consider container mounts to generate nvidiaConfig
Signed-off-by: Kevin Klues <kklues@nvidia.com>
This commit is contained in:
parent
da36874e91
commit
2ae7cb07cf
@ -73,6 +73,15 @@ type LinuxCapabilities struct {
|
|||||||
Ambient []string `json:"ambient,omitempty" platform:"linux"`
|
Ambient []string `json:"ambient,omitempty" platform:"linux"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mount from OCI runtime spec
|
||||||
|
// https://github.com/opencontainers/runtime-spec/blob/v1.0.0/specs-go/config.go#L103
|
||||||
|
type Mount struct {
|
||||||
|
Destination string `json:"destination"`
|
||||||
|
Type string `json:"type,omitempty" platform:"linux,solaris"`
|
||||||
|
Source string `json:"source,omitempty"`
|
||||||
|
Options []string `json:"options,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Spec from OCI runtime spec
|
// Spec from OCI runtime spec
|
||||||
// We use pointers to structs, similarly to the latest version of runtime-spec:
|
// We use pointers to structs, similarly to the latest version of runtime-spec:
|
||||||
// https://github.com/opencontainers/runtime-spec/blob/v1.0.0/specs-go/config.go#L5-L28
|
// https://github.com/opencontainers/runtime-spec/blob/v1.0.0/specs-go/config.go#L5-L28
|
||||||
@ -80,6 +89,7 @@ type Spec struct {
|
|||||||
Version *string `json:"ociVersion"`
|
Version *string `json:"ociVersion"`
|
||||||
Process *Process `json:"process,omitempty"`
|
Process *Process `json:"process,omitempty"`
|
||||||
Root *Root `json:"root,omitempty"`
|
Root *Root `json:"root,omitempty"`
|
||||||
|
Mounts []Mount `json:"mounts,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HookState holds state information about the hook
|
// HookState holds state information about the hook
|
||||||
@ -285,7 +295,7 @@ func getRequirements(env map[string]string, legacyImage bool) []string {
|
|||||||
return requirements
|
return requirements
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNvidiaConfig(env map[string]string, privileged bool) *nvidiaConfig {
|
func getNvidiaConfig(env map[string]string, mounts []Mount, privileged bool) *nvidiaConfig {
|
||||||
legacyImage := isLegacyCUDAImage(env)
|
legacyImage := isLegacyCUDAImage(env)
|
||||||
|
|
||||||
var devices string
|
var devices string
|
||||||
@ -353,6 +363,6 @@ func getContainerConfig(hook HookConfig) (config containerConfig) {
|
|||||||
Pid: h.Pid,
|
Pid: h.Pid,
|
||||||
Rootfs: s.Root.Path,
|
Rootfs: s.Root.Path,
|
||||||
Env: env,
|
Env: env,
|
||||||
Nvidia: getNvidiaConfig(env, privileged),
|
Nvidia: getNvidiaConfig(env, s.Mounts, privileged),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetNvidiaConfig(t *testing.T) {
|
func TestGetNvidiaConfigEnvvar(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
description string
|
description string
|
||||||
env map[string]string
|
env map[string]string
|
||||||
@ -407,7 +407,7 @@ func TestGetNvidiaConfig(t *testing.T) {
|
|||||||
// Wrap the call to getNvidiaConfig() in a closure.
|
// Wrap the call to getNvidiaConfig() in a closure.
|
||||||
var config *nvidiaConfig
|
var config *nvidiaConfig
|
||||||
getConfig := func() {
|
getConfig := func() {
|
||||||
config = getNvidiaConfig(tc.env, tc.privileged)
|
config = getNvidiaConfig(tc.env, nil, tc.privileged)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For any tests that are expected to panic, make sure they do.
|
// For any tests that are expected to panic, make sure they do.
|
||||||
|
Loading…
Reference in New Issue
Block a user