karmadactl: set default 5s timeout for resource completion#7315
karmadactl: set default 5s timeout for resource completion#7315manmathbh wants to merge 1 commit intokarmada-io:masterfrom
Conversation
|
Welcome @manmathbh! It looks like this is your first PR to karmada-io/karmada 🎉 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the reliability and user experience of Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent karmadactl shell completion (resource discovery via apiresources) from hanging by applying a default 5s timeout when listing resources.
Changes:
- Adds logic in
compGetResourceListto default the REST client timeout to5swhen none is set.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if configFlags, ok := restClientGetter.(*genericclioptions.ConfigFlags); ok { | ||
| if configFlags.Timeout == nil || len(*configFlags.Timeout) == 0 { | ||
| configFlags.Timeout = ptr.To("5s") | ||
| } | ||
| } |
There was a problem hiding this comment.
restClientGetter is typically a util.Factory/cmdutil.Factory here (see callers passing f), so the type assertion to *genericclioptions.ConfigFlags will fail and the default timeout will never be applied. Consider wrapping the provided genericclioptions.RESTClientGetter with a small delegating implementation that overrides ToRESTConfig() to set rest.Config.Timeout to 5s when it is zero (or otherwise ensure you can access/mutate the underlying ConfigFlags used by the factory).
There was a problem hiding this comment.
Agree, how about:
config, err := restClientGetter.ToRawKubeConfigLoader().ClientConfig()
if err != nil {
return nil
}
config.Timeout = 5 * time.SecondThere was a problem hiding this comment.
Code Review
This pull request introduces a default 5-second timeout for resource completion lookups to prevent them from hanging. The implementation modifies the ConfigFlags to set the timeout. My review includes a suggestion to avoid side effects by restoring the original timeout value after the operation, improving the code's robustness.
| // TODO: Should set --request-timeout=5s | ||
| if configFlags, ok := restClientGetter.(*genericclioptions.ConfigFlags); ok { | ||
| if configFlags.Timeout == nil || len(*configFlags.Timeout) == 0 { | ||
| configFlags.Timeout = ptr.To("5s") |
There was a problem hiding this comment.
While this change correctly sets a default timeout, it modifies the configFlags object in place. This creates a side effect that could potentially affect other parts of the code using the same restClientGetter instance within the same process execution. To avoid this, it's better to restore the original timeout value before the function returns. You can achieve this by using a defer statement.
originalTimeout := configFlags.Timeout
configFlags.Timeout = ptr.To("5s")
defer func() { configFlags.Timeout = originalTimeout }()Signed-off-by: manmathbh <manmathcode@gmail.com>
9444460 to
379e04e
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7315 +/- ##
==========================================
- Coverage 42.03% 42.03% -0.01%
==========================================
Files 874 874
Lines 53551 53554 +3
==========================================
Hits 22511 22511
- Misses 29349 29353 +4
+ Partials 1691 1690 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/cc @zhzhuang-zju |
|
Thanks |
| if configFlags, ok := restClientGetter.(*genericclioptions.ConfigFlags); ok { | ||
| if configFlags.Timeout == nil || len(*configFlags.Timeout) == 0 { | ||
| configFlags.Timeout = ptr.To("5s") | ||
| } | ||
| } |
There was a problem hiding this comment.
Agree, how about:
config, err := restClientGetter.ToRawKubeConfigLoader().ClientConfig()
if err != nil {
return nil
}
config.Timeout = 5 * time.Second
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: