From e2f8d2a15f86e82e71c5d03d8c5cb3f37d7af511 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 22 Jun 2023 14:48:22 +0200 Subject: [PATCH] Set default spec dirs at config level This change sets the default CDI spec dirs at a config level instead of when a CDI runtime modifier is constructed. This makes this setting consistent with other options such as the nvidia-ctk path. Signed-off-by: Evan Lezar --- internal/config/config.go | 1 + internal/config/config_test.go | 11 +++++++++++ internal/modifier/cdi.go | 7 +------ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index c189ac54..576e16d7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -151,6 +151,7 @@ func getDefault() (*Config, error) { CDI: cdiModeConfig{ DefaultKind: "nvidia.com/gpu", AnnotationPrefixes: []string{cdi.AnnotationPrefix}, + SpecDirs: cdi.DefaultSpecDirs, }, }, }, diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 0e709f9b..029a0109 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -77,6 +77,7 @@ func TestGetConfig(t *testing.T) { CDI: cdiModeConfig{ DefaultKind: "nvidia.com/gpu", AnnotationPrefixes: []string{"cdi.k8s.io/"}, + SpecDirs: []string{"/etc/cdi", "/var/run/cdi"}, }, }, }, @@ -102,6 +103,7 @@ func TestGetConfig(t *testing.T) { "nvidia-container-runtime.mode = \"not-auto\"", "nvidia-container-runtime.modes.cdi.default-kind = \"example.vendor.com/device\"", "nvidia-container-runtime.modes.cdi.annotation-prefixes = [\"cdi.k8s.io/\", \"example.vendor.com/\",]", + "nvidia-container-runtime.modes.cdi.spec-dirs = [\"/except/etc/cdi\", \"/not/var/run/cdi\",]", "nvidia-container-runtime.modes.csv.mount-spec-path = \"/not/etc/nvidia-container-runtime/host-files-for-container.d\"", "nvidia-container-runtime-hook.path = \"/foo/bar/nvidia-container-runtime-hook\"", "nvidia-ctk.path = \"/foo/bar/nvidia-ctk\"", @@ -128,6 +130,10 @@ func TestGetConfig(t *testing.T) { "cdi.k8s.io/", "example.vendor.com/", }, + SpecDirs: []string{ + "/except/etc/cdi", + "/not/var/run/cdi", + }, }, }, }, @@ -156,6 +162,7 @@ func TestGetConfig(t *testing.T) { "[nvidia-container-runtime.modes.cdi]", "default-kind = \"example.vendor.com/device\"", "annotation-prefixes = [\"cdi.k8s.io/\", \"example.vendor.com/\",]", + "spec-dirs = [\"/except/etc/cdi\", \"/not/var/run/cdi\",]", "[nvidia-container-runtime.modes.csv]", "mount-spec-path = \"/not/etc/nvidia-container-runtime/host-files-for-container.d\"", "[nvidia-container-runtime-hook]", @@ -185,6 +192,10 @@ func TestGetConfig(t *testing.T) { "cdi.k8s.io/", "example.vendor.com/", }, + SpecDirs: []string{ + "/except/etc/cdi", + "/not/var/run/cdi", + }, }, }, }, diff --git a/internal/modifier/cdi.go b/internal/modifier/cdi.go index 4578534e..a5e0f3d0 100644 --- a/internal/modifier/cdi.go +++ b/internal/modifier/cdi.go @@ -48,14 +48,9 @@ func NewCDIModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Spe } logger.Debugf("Creating CDI modifier for devices: %v", devices) - specDirs := cdi.DefaultSpecDirs - if len(cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.SpecDirs) > 0 { - specDirs = cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.SpecDirs - } - m := cdiModifier{ logger: logger, - specDirs: specDirs, + specDirs: cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.SpecDirs, devices: devices, }