-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add config search path option to driver root #327
Conversation
d8ff7c6
to
11b2c22
Compare
0460bcd
to
21e8b05
Compare
Signed-off-by: Evan Lezar <elezar@nvidia.com>
21e8b05
to
8176163
Compare
/cc @jmbaur |
internal/lookup/root/root.go
Outdated
useRoot := r.Root | ||
searchPaths := []string{"/etc", "/usr/share"} | ||
if len(r.configSearchPaths) > 0 { | ||
useRoot = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of setting this as an empty string, I would prefer if we added the with .WithRoot()
to the Options list when configSearchPaths is not set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a stab at reworking this as:
diff --git a/internal/lookup/root/root.go b/internal/lookup/root/root.go
index bfd3ace4..f3176744 100644
--- a/internal/lookup/root/root.go
+++ b/internal/lookup/root/root.go
@@ -59,17 +59,22 @@ func (r *Driver) Libraries() lookup.Locator {
// If configSearchPaths is specified, these paths are used as absolute paths,
// otherwise, /etc and /usr/share are searched.
func (r *Driver) Configs() lookup.Locator {
- useRoot := r.Root
- searchPaths := []string{"/etc", "/usr/share"}
- if len(r.configSearchPaths) > 0 {
- useRoot = ""
- searchPaths = normalizeSearchPaths(r.configSearchPaths...)
+ options := []lookup.Option{
+ lookup.WithLogger(r.logger),
}
+ if len(r.configSearchPaths) == 0 {
+ options = append(options,
+ lookup.WithRoot(r.Root),
+ lookup.WithSearchPaths("/etc", "/usr/share"),
+ )
+ } else {
+ options = append(options,
+ lookup.WithSearchPaths(normalizeSearchPaths(r.configSearchPaths...)...),
+ )
+ }
return lookup.NewFileLocator(
- lookup.WithLogger(r.logger),
- lookup.WithRoot(useRoot),
- lookup.WithSearchPaths(searchPaths...),
+ options...,
)
}
but I find this more verbose and unclear as to what is actually being done here. If you don't mind, I will leave this as is -- possibly renaming some local variables.
Aside from @tariq1890 , I don't have comments, once his comments are addressed we can move forward |
Signed-off-by: Evan Lezar <elezar@nvidia.com>
8176163
to
2a9e353
Compare
This changes adds a
Configs()
method to the Driver root abstraction that can be used to locate config files.In addition a
--config-search-path
option is added to thenvidia-ctk cdi generate
command to allow this to be overridden.