Skip to content

fix: use idiomatic Go boolean checks in store_valkey.go#317

Open
HarshitPal25 wants to merge 1 commit into
volcano-sh:mainfrom
HarshitPal25:fix/idiomatic-bool-store-valkey
Open

fix: use idiomatic Go boolean checks in store_valkey.go#317
HarshitPal25 wants to merge 1 commit into
volcano-sh:mainfrom
HarshitPal25:fix/idiomatic-bool-store-valkey

Conversation

@HarshitPal25
Copy link
Copy Markdown
Contributor

Description:
What type of PR is this?

/kind cleanup

What this PR does / why we need it:
Replaces explicit boolean comparisons with idiomatic Go style in store_valkey.go:

  • if err == nil && disableCache == trueif err == nil && disableCache
  • if err == nil && forceSingleCache == trueif err == nil && forceSingleCache

The Go Code Review Comments wiki and golint/revive linters recommend against comparing boolean values to true/false explicitly.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Replace `disableCache == true` with `disableCache` and
`forceSingleCache == true` with `forceSingleCache` per Go style
conventions. The Go Code Review Comments wiki recommends against
comparing boolean values to true/false explicitly.

Signed-off-by: HarshitPal25 <harshit13082006@gmail.com>
Copilot AI review requested due to automatic review settings May 11, 2026 10:29
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[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 yaozengzeng for approval. For more information see the Kubernetes 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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors boolean comparisons in pkg/store/store_valkey.go to use idiomatic Go syntax. The reviewer suggests enhancing the error handling for the VALKEY_DISABLE_CACHE and VALKEY_FORCE_SINGLE environment variables, as parsing errors are currently silently ignored, which could lead to unexpected configuration behavior.

Comment thread pkg/store/store_valkey.go
if valkeyDisableCache != "" {
disableCache, err := strconv.ParseBool(valkeyDisableCache)
if err == nil && disableCache == true {
if err == nil && disableCache {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While refactoring for idiomatic boolean checks, it's a good opportunity to improve error handling. Currently, if VALKEY_DISABLE_CACHE contains an invalid boolean string, strconv.ParseBool returns an error which is silently ignored. Given that other configuration errors in this function (like missing VALKEY_ADDR) cause a failure, it would be more consistent and robust to return an error here as well.

		if err != nil {
			return nil, fmt.Errorf("invalid VALKEY_DISABLE_CACHE %q: %w", valkeyDisableCache, err)
		}
		if disableCache {

Comment thread pkg/store/store_valkey.go
if valkeyForceSingle != "" {
forceSingleCache, err := strconv.ParseBool(valkeyForceSingle)
if err == nil && forceSingleCache == true {
if err == nil && forceSingleCache {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the VALKEY_DISABLE_CACHE check, handling the error from strconv.ParseBool for VALKEY_FORCE_SINGLE prevents silent configuration failures and maintains consistency with how other environment variables are processed in this function.

		if err != nil {
			return nil, fmt.Errorf("invalid VALKEY_FORCE_SINGLE %q: %w", valkeyForceSingle, err)
		}
		if forceSingleCache {

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR performs a small cleanup in the Valkey store configuration path (pkg/store/store_valkey.go) by replacing explicit boolean comparisons (== true) with idiomatic Go boolean checks when applying options from environment variables.

Changes:

  • Simplified ParseBool result checks for VALKEY_DISABLE_CACHE and VALKEY_FORCE_SINGLE to use idiomatic if err == nil && flag style.
  • Kept behavior the same while aligning with common Go lint recommendations.

Comment thread pkg/store/store_valkey.go
Comment on lines 80 to 85
if valkeyDisableCache != "" {
disableCache, err := strconv.ParseBool(valkeyDisableCache)
if err == nil && disableCache == true {
if err == nil && disableCache {
valkeyClientOptions.DisableCache = true
klog.Info("valkeyClientOptions DisableCache is set to true")
}
Comment thread pkg/store/store_valkey.go
Comment on lines 88 to 91
if valkeyForceSingle != "" {
forceSingleCache, err := strconv.ParseBool(valkeyForceSingle)
if err == nil && forceSingleCache == true {
if err == nil && forceSingleCache {
valkeyClientOptions.ForceSingleClient = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants