Skip to content

pkg/types/nutanix: warn about unused context#10430

Open
alrs wants to merge 1 commit intoopenshift:mainfrom
alrs:nutanix-context
Open

pkg/types/nutanix: warn about unused context#10430
alrs wants to merge 1 commit intoopenshift:mainfrom
alrs:nutanix-context

Conversation

@alrs
Copy link
Contributor

@alrs alrs commented Mar 24, 2026

CreateNutanixClient() takes a context.Context as its first argument, adds a 60-second timeout, and then never touches the context.Context again. prism-go-client/v3.NewV3Client() does not take a context.Context(), and does not make actual requests to the Nutanix API. Instead, the indivdual functions on prism-go-client/v3.Client.V3 individually take their own context.Context on each request.

I don't want to make a breaking change to CreateNutanixClient(), so instead of removing the context.Context from the function signature I've added a log warning using "logrus", which is the preferred logging library used in other packages beneath pkg/types.

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Walkthrough

Modified 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 time package and adding logrus for warning logging.

Changes

Cohort / File(s) Summary
Nutanix Client Initialization
pkg/types/nutanix/client.go
Removed timeout-scoped context creation with deadline; added logrus warning indicating input context is dropped and has no effect. Updated imports to remove unused time and add logrus.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
The command is terminated due to an 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 24, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 24, 2026

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 24, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign rvanderp3 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot requested review from jcpowermac and rvanderp3 March 24, 2026 18:21
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 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.Once or 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

📥 Commits

Reviewing files that changed from the base of the PR and between 883a6d8 and 9452339.

📒 Files selected for processing (1)
  • pkg/types/nutanix/client.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant