Skip to content

Commit 32ec104

Browse files
author
Evan Lezar
committed
Merge branch 'lookup-functional-options' into 'main'
Use functional options when creating Symlink and Directory locators See merge request nvidia/container-toolkit/container-toolkit!452
2 parents 99cc0ae + ce7d5f7 commit 32ec104

File tree

7 files changed

+25
-21
lines changed

7 files changed

+25
-21
lines changed

cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ func (m command) run(c *cli.Context, cfg *config) error {
101101

102102
csvFiles := cfg.filenames.Value()
103103

104-
chainLocator := lookup.NewSymlinkChainLocator(m.logger, cfg.hostRoot)
104+
chainLocator := lookup.NewSymlinkChainLocator(
105+
lookup.WithLogger(m.logger),
106+
lookup.WithRoot(cfg.hostRoot),
107+
)
105108

106109
var candidates []string
107110
for _, file := range csvFiles {

internal/discover/csv.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string)
3333
return None{}, nil
3434
}
3535

36-
symlinkLocator := lookup.NewSymlinkLocator(logger, driverRoot)
36+
symlinkLocator := lookup.NewSymlinkLocator(
37+
lookup.WithLogger(logger),
38+
lookup.WithRoot(driverRoot),
39+
)
3740
locators := map[csv.MountSpecType]lookup.Locator{
3841
csv.MountSpecDev: lookup.NewCharDeviceLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)),
39-
csv.MountSpecDir: lookup.NewDirectoryLocator(logger, driverRoot),
42+
csv.MountSpecDir: lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)),
4043
// Libraries and symlinks are handled in the same way
4144
csv.MountSpecLib: symlinkLocator,
4245
csv.MountSpecSym: symlinkLocator,

internal/discover/gds.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewGDSDiscoverer(logger logger.Interface, root string) (Discover, error) {
3838

3939
udev := NewMounts(
4040
logger,
41-
lookup.NewDirectoryLocator(logger, root),
41+
lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(root)),
4242
root,
4343
[]string{"/run/udev"},
4444
)

internal/discover/symlinks.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ func (d symlinkHook) getSpecificLinks() ([]string, error) {
113113
}
114114

115115
func (d symlinkHook) getCSVFileSymlinks() []string {
116-
chainLocator := lookup.NewSymlinkChainLocator(d.logger, d.driverRoot)
116+
chainLocator := lookup.NewSymlinkChainLocator(
117+
lookup.WithLogger(d.logger),
118+
lookup.WithRoot(d.driverRoot),
119+
)
117120

118121
var candidates []string
119122
for _, file := range d.csvFiles {

internal/lookup/dir.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ package lookup
1919
import (
2020
"fmt"
2121
"os"
22-
23-
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
2422
)
2523

26-
// NewDirectoryLocator creates a Locator that can be used to find directories at the specified root. A logger
27-
// is also specified.
28-
func NewDirectoryLocator(logger logger.Interface, root string) Locator {
24+
// NewDirectoryLocator creates a Locator that can be used to find directories at the specified root.
25+
func NewDirectoryLocator(opts ...Option) Locator {
2926
return NewFileLocator(
30-
WithLogger(logger),
31-
WithRoot(root),
32-
WithFilter(assertDirectory),
27+
append(
28+
opts,
29+
WithFilter(assertDirectory),
30+
)...,
3331
)
3432
}
3533

internal/lookup/library.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewLibraryLocator(logger logger.Interface, root string) (Locator, error) {
4141

4242
l := library{
4343
logger: logger,
44-
symlink: NewSymlinkLocator(logger, root),
44+
symlink: NewSymlinkLocator(WithLogger(logger), WithRoot(root)),
4545
cache: cache,
4646
}
4747

internal/lookup/symlinks.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"path/filepath"
2222

23-
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
2423
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
2524
)
2625

@@ -33,9 +32,8 @@ type symlink struct {
3332
}
3433

3534
// NewSymlinkChainLocator creats a locator that can be used for locating files through symlinks.
36-
// A logger can also be specified.
37-
func NewSymlinkChainLocator(logger logger.Interface, root string) Locator {
38-
f := newFileLocator(WithLogger(logger), WithRoot(root))
35+
func NewSymlinkChainLocator(opts ...Option) Locator {
36+
f := newFileLocator(opts...)
3937
l := symlinkChain{
4038
file: *f,
4139
}
@@ -44,9 +42,8 @@ func NewSymlinkChainLocator(logger logger.Interface, root string) Locator {
4442
}
4543

4644
// NewSymlinkLocator creats a locator that can be used for locating files through symlinks.
47-
// A logger can also be specified.
48-
func NewSymlinkLocator(logger logger.Interface, root string) Locator {
49-
f := newFileLocator(WithLogger(logger), WithRoot(root))
45+
func NewSymlinkLocator(opts ...Option) Locator {
46+
f := newFileLocator(opts...)
5047
l := symlink{
5148
file: *f,
5249
}

0 commit comments

Comments
 (0)