mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
Add utility function to get config name from struct
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
f6b1b1afad
commit
fc408a32c7
@ -295,7 +295,8 @@ func getDevices(hookConfig *HookConfig, env map[string]string, mounts []Mount, p
|
|||||||
return devices
|
return devices
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Ignoring devices specified in NVIDIA_VISIBLE_DEVICES (privileged=%v, config.accept-nvidia-visible-devices-envvar-when-unprivileged=%v) ", privileged, hookConfig.AcceptEnvvarUnprivileged)
|
configName := hookConfig.getConfigOption("AcceptEnvvarUnprivileged")
|
||||||
|
log.Printf("Ignoring devices specified in NVIDIA_VISIBLE_DEVICES (privileged=%v, %v=%v) ", privileged, configName, hookConfig.AcceptEnvvarUnprivileged)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
)
|
)
|
||||||
@ -86,3 +87,18 @@ func getHookConfig() (config HookConfig) {
|
|||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getConfigOption returns the toml config option associated with the
|
||||||
|
// specified struct field.
|
||||||
|
func (c HookConfig) getConfigOption(fieldName string) string {
|
||||||
|
t := reflect.TypeOf(c)
|
||||||
|
f, ok := t.FieldByName(fieldName)
|
||||||
|
if !ok {
|
||||||
|
return fieldName
|
||||||
|
}
|
||||||
|
v, ok := f.Tag.Lookup("toml")
|
||||||
|
if !ok {
|
||||||
|
return fieldName
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user