diff --git a/go.mod b/go.mod index bd6cc4164..e1ae232fe 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/NVIDIA/go-gpuallocator v0.3.2 github.com/NVIDIA/go-nvlib v0.2.0 github.com/NVIDIA/go-nvml v0.12.0-3 - github.com/NVIDIA/nvidia-container-toolkit v1.15.0-rc.4 + github.com/NVIDIA/nvidia-container-toolkit v1.15.0 github.com/fsnotify/fsnotify v1.7.0 github.com/google/uuid v1.6.0 github.com/mittwald/go-helm-client v0.12.9 diff --git a/go.sum b/go.sum index 5caff11f7..27e403b4f 100644 --- a/go.sum +++ b/go.sum @@ -27,8 +27,8 @@ github.com/NVIDIA/go-nvlib v0.2.0 h1:roq+SDstbP1fcy2XVH7wB2Gz2/Ud7Q+NGQYOcVITVrA github.com/NVIDIA/go-nvlib v0.2.0/go.mod h1:kFuLNTyD1tF6FbRFlk+/EdUW5BrkE+v1Y3A3/9zKSjA= github.com/NVIDIA/go-nvml v0.12.0-3 h1:QwfjYxEqIQVRhl8327g2Y3ZvKResPydpGSKtCIIK9jE= github.com/NVIDIA/go-nvml v0.12.0-3/go.mod h1:SOufGc5Wql+cxrIZ8RyJwVKDYxfbs4WPkHXqadcbfvA= -github.com/NVIDIA/nvidia-container-toolkit v1.15.0-rc.4 h1:KTOeNTXe9+4rPGGtMpL7k9XuySvHdKs7muOWQA29mcY= -github.com/NVIDIA/nvidia-container-toolkit v1.15.0-rc.4/go.mod h1:juaXgtJwwtT/Ap+lZdWI9dcrAeYeoNY3r4b8jl10sFI= +github.com/NVIDIA/nvidia-container-toolkit v1.15.0 h1:YmYZUKJzhz/lJSVH6k1mk5IUCHpt8HwRtwMrtBoCzhQ= +github.com/NVIDIA/nvidia-container-toolkit v1.15.0/go.mod h1:SUwxfwi+dl1LtVlpAnJEolxuZfCtAVmOKRGWhJYsiJI= github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/OJnIp5u0s1SbQ8dVfLCZJsnvazdBP5hS4iRs= github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/discover/graphics.go b/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/discover/graphics.go index 0a8ff8d24..35b51982b 100644 --- a/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/discover/graphics.go +++ b/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/discover/graphics.go @@ -61,11 +61,7 @@ func NewGraphicsMountsDiscoverer(logger logger.Interface, driver *root.Driver, n jsonMounts := NewMounts( logger, - lookup.NewFileLocator( - lookup.WithLogger(logger), - lookup.WithRoot(driver.Root), - lookup.WithSearchPaths("/etc", "/usr/share"), - ), + driver.Configs(), driver.Root, []string{ "glvnd/egl_vendor.d/10_nvidia.json", @@ -292,11 +288,7 @@ func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPa xorgConfig := NewMounts( logger, - lookup.NewFileLocator( - lookup.WithLogger(logger), - lookup.WithRoot(driver.Root), - lookup.WithSearchPaths("/usr/share"), - ), + driver.Configs(), driver.Root, []string{"X11/xorg.conf.d/10-nvidia.conf"}, ) diff --git a/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root/options.go b/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root/options.go new file mode 100644 index 000000000..6bffe3d8a --- /dev/null +++ b/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root/options.go @@ -0,0 +1,45 @@ +/** +# Copyright 2024 NVIDIA CORPORATION +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +**/ + +package root + +import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" + +type Option func(*Driver) + +func WithLogger(logger logger.Interface) Option { + return func(d *Driver) { + d.logger = logger + } +} + +func WithDriverRoot(root string) Option { + return func(d *Driver) { + d.Root = root + } +} + +func WithLibrarySearchPaths(paths ...string) Option { + return func(d *Driver) { + d.librarySearchPaths = paths + } +} + +func WithConfigSearchPaths(paths ...string) Option { + return func(d *Driver) { + d.configSearchPaths = paths + } +} diff --git a/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root/root.go b/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root/root.go index f96e6b992..4a475ccd4 100644 --- a/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root/root.go +++ b/vendor/github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root/root.go @@ -17,6 +17,7 @@ package root import ( + "os" "path/filepath" "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" @@ -30,27 +31,55 @@ type Driver struct { Root string // librarySearchPaths specifies explicit search paths for discovering libraries. librarySearchPaths []string + // configSearchPaths specified explicit search paths for discovering driver config files. + configSearchPaths []string } -// New creates a new Driver root at the specified path. -// TODO: Use functional options here. -func New(logger logger.Interface, path string, librarySearchPaths []string) *Driver { - return &Driver{ - logger: logger, - Root: path, - librarySearchPaths: normalizeSearchPaths(librarySearchPaths...), +// New creates a new Driver root using the specified options. +func New(opts ...Option) *Driver { + d := &Driver{} + for _, opt := range opts { + opt(d) } + if d.logger == nil { + d.logger = logger.New() + } + return d } -// Drivers returns a Locator for driver libraries. +// Libraries returns a Locator for driver libraries. func (r *Driver) Libraries() lookup.Locator { return lookup.NewLibraryLocator( lookup.WithLogger(r.logger), lookup.WithRoot(r.Root), - lookup.WithSearchPaths(r.librarySearchPaths...), + lookup.WithSearchPaths(normalizeSearchPaths(r.librarySearchPaths...)...), ) } +// Configs returns a locator for driver configs. +// If configSearchPaths is specified, these paths are used as absolute paths, +// otherwise, /etc and /usr/share are searched. +func (r *Driver) Configs() lookup.Locator { + return lookup.NewFileLocator(r.configSearchOptions()...) +} + +func (r *Driver) configSearchOptions() []lookup.Option { + if len(r.configSearchPaths) > 0 { + return []lookup.Option{ + lookup.WithLogger(r.logger), + lookup.WithRoot("/"), + lookup.WithSearchPaths(normalizeSearchPaths(r.configSearchPaths...)...), + } + } + searchPaths := []string{"/etc"} + searchPaths = append(searchPaths, xdgDataDirs()...) + return []lookup.Option{ + lookup.WithLogger(r.logger), + lookup.WithRoot(r.Root), + lookup.WithSearchPaths(searchPaths...), + } +} + // normalizeSearchPaths takes a list of paths and normalized these. // Each of the elements in the list is expanded if it is a path list and the // resultant list is returned. @@ -63,3 +92,13 @@ func normalizeSearchPaths(paths ...string) []string { } return normalized } + +// xdgDataDirs finds the paths as specified in the environment variable XDG_DATA_DIRS. +// See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html. +func xdgDataDirs() []string { + if dirs, exists := os.LookupEnv("XDG_DATA_DIRS"); exists && dirs != "" { + return normalizeSearchPaths(dirs) + } + + return []string{"/usr/local/share", "/usr/share"} +} diff --git a/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/lib.go b/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/lib.go index bd575249b..ad75a2398 100644 --- a/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/lib.go +++ b/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/lib.go @@ -50,6 +50,7 @@ type nvcdilib struct { devRoot string nvidiaCTKPath string ldconfigPath string + configSearchPaths []string librarySearchPaths []string csvFiles []string @@ -93,8 +94,11 @@ func New(opts ...Option) (Interface, error) { l.infolib = info.New() } - // TODO: We need to improve the construction of this driver root. - l.driver = root.New(l.logger, l.driverRoot, l.librarySearchPaths) + l.driver = root.New( + root.WithLogger(l.logger), + root.WithDriverRoot(l.driverRoot), + root.WithLibrarySearchPaths(l.librarySearchPaths...), + ) var lib Interface switch l.resolveMode() { diff --git a/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/options.go b/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/options.go index 388bb0a2f..a4e49b609 100644 --- a/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/options.go +++ b/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/options.go @@ -126,6 +126,13 @@ func WithCSVIgnorePatterns(csvIgnorePatterns []string) Option { } } +// WithConfigSearchPaths sets the search paths for config files. +func WithConfigSearchPaths(paths []string) Option { + return func(o *nvcdilib) { + o.configSearchPaths = paths + } +} + // WithLibrarySearchPaths sets the library search paths. // This is currently only used for CSV-mode. func WithLibrarySearchPaths(paths []string) Option { diff --git a/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec/spec.go b/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec/spec.go index 6594466e5..c27c4de31 100644 --- a/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec/spec.go +++ b/vendor/github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec/spec.go @@ -47,12 +47,11 @@ func (s *spec) Save(path string) error { } specDir := filepath.Dir(path) - registry := cdi.GetRegistry( + cache, _ := cdi.NewCache( cdi.WithAutoRefresh(false), cdi.WithSpecDirs(specDir), ) - - if err := registry.SpecDB().WriteSpec(s.Raw(), filepath.Base(path)); err != nil { + if err := cache.WriteSpec(s.Raw(), filepath.Base(path)); err != nil { return fmt.Errorf("failed to write spec: %w", err) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 8f5f80032..5e26fc8d9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -40,7 +40,7 @@ github.com/NVIDIA/go-nvlib/pkg/nvml ## explicit; go 1.20 github.com/NVIDIA/go-nvml/pkg/dl github.com/NVIDIA/go-nvml/pkg/nvml -# github.com/NVIDIA/nvidia-container-toolkit v1.15.0-rc.4 +# github.com/NVIDIA/nvidia-container-toolkit v1.15.0 ## explicit; go 1.20 github.com/NVIDIA/nvidia-container-toolkit/internal/config/image github.com/NVIDIA/nvidia-container-toolkit/internal/discover