From fc408a32c7feb86247eecbd0e7c5f04f7583be05 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 22 Jan 2021 15:33:23 +0100 Subject: [PATCH] Add utility function to get config name from struct Signed-off-by: Evan Lezar --- pkg/container_config.go | 3 ++- pkg/hook_config.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/container_config.go b/pkg/container_config.go index c6901974..25861d52 100644 --- a/pkg/container_config.go +++ b/pkg/container_config.go @@ -295,7 +295,8 @@ func getDevices(hookConfig *HookConfig, env map[string]string, mounts []Mount, p 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 } diff --git a/pkg/hook_config.go b/pkg/hook_config.go index 0f809c74..8d35cb19 100644 --- a/pkg/hook_config.go +++ b/pkg/hook_config.go @@ -4,6 +4,7 @@ import ( "log" "os" "path" + "reflect" "github.com/BurntSushi/toml" ) @@ -86,3 +87,18 @@ func getHookConfig() (config HookConfig) { 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 +}