pkg/types/nutanix: warn about unused context#10430
pkg/types/nutanix: warn about unused context#10430alrs wants to merge 1 commit intoopenshift:mainfrom
Conversation
WalkthroughModified Nutanix client creation function to remove context timeout handling and add a warning log when the input context is ignored. Import statements were updated accordingly, removing the unused Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.11.3)Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @alrs. Thanks for your PR. I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/types/nutanix/client.go (1)
15-17: Warning on every call creates log noise.This warning fires unconditionally on every invocation. Based on the relevant snippets, at least three call sites (destroy, validation, manifests paths) will trigger this warning during normal workflows. Consider logging once using
sync.Onceor moving this to documentation-only.♻️ Suggested approach: log once
import ( "context" "fmt" "strconv" + "sync" nutanixclient "github.com/nutanix-cloud-native/prism-go-client" nutanixclientv3 "github.com/nutanix-cloud-native/prism-go-client/v3" "github.com/sirupsen/logrus" ) +var warnOnce sync.Once + // CreateNutanixClient creates a Nutanix V3 Client. func CreateNutanixClient(ctx context.Context, prismCentral, port, username, password string) (*nutanixclientv3.Client, error) { - - // This function previously took a context that went unused. - logrus.Warn("context passed to CreateNutanixClient is dropped with no effect") + // The ctx parameter is unused because prism-go-client/v3.NewV3Client does not accept a context. + // Individual request methods on the returned client accept their own context. + warnOnce.Do(func() { + logrus.Warn("context passed to CreateNutanixClient is unused; prism-go-client does not propagate it") + })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/types/nutanix/client.go` around lines 15 - 17, The unconditional log in CreateNutanixClient causes noise; replace it with a one-time warning by introducing a package-level sync.Once (e.g., nutanixClientWarnOnce) and wrap the logrus.Warn("context passed to CreateNutanixClient is dropped with no effect") call inside nutanixClientWarnOnce.Do(...) so the message emits only once, or alternatively remove the log and document the dropped context in the function comment if you prefer no runtime logging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/types/nutanix/client.go`:
- Around line 15-17: The unconditional log in CreateNutanixClient causes noise;
replace it with a one-time warning by introducing a package-level sync.Once
(e.g., nutanixClientWarnOnce) and wrap the logrus.Warn("context passed to
CreateNutanixClient is dropped with no effect") call inside
nutanixClientWarnOnce.Do(...) so the message emits only once, or alternatively
remove the log and document the dropped context in the function comment if you
prefer no runtime logging.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 237f720d-8a22-48c5-af8c-c70c5640ad5f
📒 Files selected for processing (1)
pkg/types/nutanix/client.go
CreateNutanixClient()takes acontext.Contextas its first argument, adds a 60-second timeout, and then never touches thecontext.Contextagain.prism-go-client/v3.NewV3Client()does not take acontext.Context(), and does not make actual requests to the Nutanix API. Instead, the indivdual functions onprism-go-client/v3.Client.V3individually take their owncontext.Contexton each request.I don't want to make a breaking change to
CreateNutanixClient(), so instead of removing thecontext.Contextfrom the function signature I've added a log warning using "logrus", which is the preferred logging library used in other packages beneathpkg/types.