-
Notifications
You must be signed in to change notification settings - Fork 24
Add support for a platform override file #79
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,13 @@ | |
|
|
||
| package info | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Platform represents a supported plaform. | ||
| type Platform string | ||
|
|
||
|
|
@@ -62,3 +69,35 @@ func (p platformResolver) ResolvePlatform() Platform { | |
| return PlatformUnknown | ||
| } | ||
| } | ||
|
|
||
| // getPlatformOverride checks the system for a platform override file. | ||
| // This allows system administrators to force the detection of a specific | ||
| // platform. | ||
| // | ||
| // The first non-empty and non-comment line (starting with #) in the file is | ||
| // returned. | ||
| // | ||
| // Note that no checks are performed for a valid platform value. | ||
| // | ||
| // This function can be overridden for testing purposes. | ||
| var getPlaformOverride = func() (string, string) { | ||
| platformOverrideFile, err := os.Open("/etc/nvidia-container-toolkit/platform-override") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be pulled out to a constant.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we instead just have
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or instead of a raw string -- it takes the path to the override file
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, the path to file should come from the entity importing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point of having this defined directly here (or at least the default) is that we want consistency across all our components that use this platform detection logic. These are currently:
In the longer term, I could also see the DRA driver for GPUs also pulling this in if we wanted to support Tegra-based systems. |
||
| if os.IsNotExist(err) { | ||
| return "", "platform-override file does not exist" | ||
| } | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to open platform-override file: %w", err).Error() | ||
| } | ||
| defer platformOverrideFile.Close() | ||
|
|
||
| scanner := bufio.NewScanner(platformOverrideFile) | ||
| for scanner.Scan() { | ||
| line := strings.TrimSpace(scanner.Text()) | ||
| if line == "" || strings.HasPrefix(line, "#") { | ||
| continue | ||
| } | ||
| return line, "read from platform-override file" | ||
| } | ||
|
|
||
| return "", "empty platform-override file" | ||
| } | ||
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.
:)