From 83743e36135a048dbeaac80d87a995bf4990654c Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 11 Jul 2022 15:10:19 +0200 Subject: [PATCH] Add runtime config option for CDI spec dirs This change adds an nvidia-container-runtime.modes.cdi.spec-dirs config option that allows the default spec dirs to be overridden. Signed-off-by: Evan Lezar --- internal/config/runtime.go | 6 ++++++ internal/modifier/cdi.go | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/config/runtime.go b/internal/config/runtime.go index 4526da0c..a4a79d38 100644 --- a/internal/config/runtime.go +++ b/internal/config/runtime.go @@ -44,6 +44,12 @@ type RuntimeConfig struct { // modesConfig defines (optional) per-mode configs type modesConfig struct { CSV csvModeConfig `toml:"csv"` + CDI cdiModeConfig `toml:"cdi"` +} + +type cdiModeConfig struct { + // SpecDirs allows for the default spec dirs for CDI to be overridden + SpecDirs []string `toml:"spec-dirs"` } type csvModeConfig struct { diff --git a/internal/modifier/cdi.go b/internal/modifier/cdi.go index 5d915f32..71c4e00c 100644 --- a/internal/modifier/cdi.go +++ b/internal/modifier/cdi.go @@ -29,8 +29,9 @@ import ( ) type cdiModifier struct { - logger *logrus.Logger - devices []string + logger *logrus.Logger + specDirs []string + devices []string } // NewCDIModifier creates an OCI spec modifier that determines the modifications to make based on the @@ -46,9 +47,15 @@ func NewCDIModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec) return nil, nil } + specDirs := cdi.DefaultSpecDirs + if len(cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.SpecDirs) > 0 { + specDirs = cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.SpecDirs + } + m := cdiModifier{ - logger: logger, - devices: devices, + logger: logger, + specDirs: specDirs, + devices: devices, } return m, nil @@ -91,6 +98,7 @@ func getDevicesFromSpec(ociSpec oci.Spec) ([]string, error) { // Modify loads the CDI registry and injects the specified CDI devices into the OCI runtime specification. func (m cdiModifier) Modify(spec *specs.Spec) error { registry := cdi.GetRegistry( + cdi.WithSpecDirs(m.specDirs...), cdi.WithAutoRefresh(false), ) if errs := registry.GetErrors(); len(errs) > 0 {