pass a single context throughout the device-plugin method call stack#1284
Merged
pass a single context throughout the device-plugin method call stack#1284
Conversation
elezar
reviewed
Jun 13, 2025
| // Get the set of plugins. | ||
| klog.Info("Retrieving plugins.") | ||
| plugins, err := GetPlugins(infolib, nvmllib, devicelib, config) | ||
| plugins, err := GetPlugins(c.Context, infolib, nvmllib, devicelib, config) |
Member
There was a problem hiding this comment.
As a matter of interest, what is the CLI context?
Member
There was a problem hiding this comment.
Update: It seems as if it's using context.Background() in any case.
Contributor
Author
There was a problem hiding this comment.
Yes. Since this is a CLI "action", we should use the CLI object's context and only that (or a context derived from it) throughout the application.
elezar
reviewed
Jun 13, 2025
internal/plugin/server.go
Outdated
| } | ||
|
|
||
| plugin := nvidiaDevicePlugin{ | ||
| ctx: o.ctx, |
Member
There was a problem hiding this comment.
Are there cases where this MAY be nil?
Contributor
Author
There was a problem hiding this comment.
Great question. No, I don't think so. I guess we don't need the WithContext method then?
Contributor
Author
There was a problem hiding this comment.
I've updated PR to remove the Option method to set the context
f1e2d0e to
b5f951a
Compare
This change follows the Go best practices. With a single ctx reference, we allow for the proper propagation of cancellations and graceful terminations across all goroutines of the device-plugin application. Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com>
b5f951a to
ce1d586
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change follows the Go best practices. With a single ctx reference, we allow for the proper propagation of cancellations and graceful terminations across all goroutines of the device-plugin application.