Skip to content

fix: use idiomatic Go boolean check in singleton.go#322

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

fix: use idiomatic Go boolean check in singleton.go#322
HarshitPal25 wants to merge 1 commit into
volcano-sh:mainfrom
HarshitPal25:fix/idiomatic-bool-singleton

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 if exists == false with if !exists in singleton.go. 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 `if exists == false` with `if !exists` per Go style
conventions. The Go Code Review Comments wiki recommends against
comparing boolean values to false explicitly.

Signed-off-by: HarshitPal25 <harshit13082006@gmail.com>
Copilot AI review requested due to automatic review settings May 11, 2026 18:41
@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

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 store singleton initialization logic by using idiomatic Go boolean negation when checking the result of os.LookupEnv, aligning with common Go linting recommendations.

Changes:

  • Replace if exists == false with if !exists in pkg/store/singleton.go.

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 updates the environment variable check in pkg/store/singleton.go to use idiomatic Go boolean syntax. The review feedback suggests further improving this logic by also handling cases where the environment variable is set to an empty string to ensure the default storage provider is correctly initialized. Additionally, the reviewer recommended applying this idiomatic cleanup consistently across other files in the repository.

Comment thread pkg/store/singleton.go
// Setting storage provider type by env STORE_TYPE
providerType, exists := os.LookupEnv("STORE_TYPE")
if exists == false {
if !exists {
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 this change correctly makes the boolean check idiomatic, it is also recommended to handle the case where the environment variable is set but empty (e.g., STORE_TYPE=""). In many deployment scenarios, an empty string is intended to trigger the default behavior. Additionally, please consider applying this same idiomatic boolean check cleanup to other files in this repository to ensure consistency, as several other instances exist (e.g., pkg/store/store_redis.go:210, pkg/store/store_valkey.go:82, and pkg/store/store_valkey.go:90).

Suggested change
if !exists {
if !exists || providerType == "" {
References
  1. The Go Code Review Comments wiki recommends against comparing boolean values to true or false explicitly. It is also a best practice to handle empty environment variables as 'not set' when providing defaults. (link)

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.74%. Comparing base (524e55e) to head (355a5d5).
⚠️ Report is 41 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #322      +/-   ##
==========================================
+ Coverage   47.57%   47.74%   +0.17%     
==========================================
  Files          30       30              
  Lines        2819     2855      +36     
==========================================
+ Hits         1341     1363      +22     
- Misses       1338     1344       +6     
- Partials      140      148       +8     
Flag Coverage Δ
unittests 47.74% <100.00%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

4 participants