Skip to content
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

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

elezar
Copy link
Member

@elezar elezar commented Feb 1, 2024

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 the nvidia-ctk cdi generate command to allow this to be overridden.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
@elezar elezar force-pushed the add-driver-config branch from 21e8b05 to 8176163 Compare March 25, 2024 18:18
@elezar elezar changed the title Add driver config Add config search path option to driver root Mar 25, 2024
@elezar elezar marked this pull request as ready for review March 25, 2024 18:19
@elezar elezar requested a review from tariq1890 March 25, 2024 18:20
@elezar
Copy link
Member Author

elezar commented Mar 25, 2024

/cc @jmbaur

useRoot := r.Root
searchPaths := []string{"/etc", "/usr/share"}
if len(r.configSearchPaths) > 0 {
useRoot = ""
Copy link
Contributor

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

Copy link
Member Author

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.

@ArangoGutierrez
Copy link
Collaborator

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>
@elezar elezar force-pushed the add-driver-config branch from 8176163 to 2a9e353 Compare April 2, 2024 21:04
@elezar elezar merged commit 29c0f82 into NVIDIA:main Apr 11, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants