Skip to content

pass a single context throughout the device-plugin method call stack#1284

Merged
tariq1890 merged 1 commit intomainfrom
pass-single-ctx
Jun 24, 2025
Merged

pass a single context throughout the device-plugin method call stack#1284
tariq1890 merged 1 commit intomainfrom
pass-single-ctx

Conversation

@tariq1890
Copy link
Contributor

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.

@tariq1890 tariq1890 requested a review from elezar June 12, 2025 17:31
// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a matter of interest, what is the CLI context?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: It seems as if it's using context.Background() in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

}

plugin := nvidiaDevicePlugin{
ctx: o.ctx,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there cases where this MAY be nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question. No, I don't think so. I guess we don't need the WithContext method then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated PR to remove the Option method to set the context

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>
@tariq1890 tariq1890 requested a review from elezar June 16, 2025 19:04
Copy link
Member

@elezar elezar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tariq1890. LGTM.

@tariq1890 tariq1890 merged commit 4579a60 into main Jun 24, 2025
15 of 16 checks passed
@tariq1890 tariq1890 deleted the pass-single-ctx branch June 24, 2025 16:22
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.

2 participants