Add utility function to get config name from struct

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2021-01-22 15:33:23 +01:00
parent f6b1b1afad
commit fc408a32c7
2 changed files with 18 additions and 1 deletions

View File

@ -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
} }

View File

@ -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
}