Skip to content

Commit fc408a3

Browse files
committed
Add utility function to get config name from struct
Signed-off-by: Evan Lezar <[email protected]>
1 parent f6b1b1a commit fc408a3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pkg/container_config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ func getDevices(hookConfig *HookConfig, env map[string]string, mounts []Mount, p
295295
return devices
296296
}
297297

298-
log.Printf("Ignoring devices specified in NVIDIA_VISIBLE_DEVICES (privileged=%v, config.accept-nvidia-visible-devices-envvar-when-unprivileged=%v) ", privileged, hookConfig.AcceptEnvvarUnprivileged)
298+
configName := hookConfig.getConfigOption("AcceptEnvvarUnprivileged")
299+
log.Printf("Ignoring devices specified in NVIDIA_VISIBLE_DEVICES (privileged=%v, %v=%v) ", privileged, configName, hookConfig.AcceptEnvvarUnprivileged)
299300

300301
return nil
301302
}

pkg/hook_config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"log"
55
"os"
66
"path"
7+
"reflect"
78

89
"github.com/BurntSushi/toml"
910
)
@@ -86,3 +87,18 @@ func getHookConfig() (config HookConfig) {
8687

8788
return config
8889
}
90+
91+
// getConfigOption returns the toml config option associated with the
92+
// specified struct field.
93+
func (c HookConfig) getConfigOption(fieldName string) string {
94+
t := reflect.TypeOf(c)
95+
f, ok := t.FieldByName(fieldName)
96+
if !ok {
97+
return fieldName
98+
}
99+
v, ok := f.Tag.Lookup("toml")
100+
if !ok {
101+
return fieldName
102+
}
103+
return v
104+
}

0 commit comments

Comments
 (0)