Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Improve checkResourceStatus readability #21260

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tangboxuan
Copy link

The previous checkResourceStatus function was not very readable as it listed each combination of watch options for health, and this PR aims to simplify and improve the readability of the heath checks in checkResourceStatus function.

@tangboxuan tangboxuan requested a review from a team as a code owner December 19, 2024 16:24
Copy link

bunnyshell bot commented Dec 19, 2024

🔴 Preview Environment stopped on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

Copy link
Member

@terrytangyuan terrytangyuan left a comment

Choose a reason for hiding this comment

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

Can you fix the typo in the PR title?

@tangboxuan tangboxuan changed the title chore: Improve checkResrouceStatus readability chore: Improve checkResourceStatus readability Dec 23, 2024
Signed-off-by: Boxuan Tang <[email protected]>
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.21%. Comparing base (635e592) to head (3bf6ca4).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21260      +/-   ##
==========================================
+ Coverage   55.18%   55.21%   +0.03%     
==========================================
  Files         337      337              
  Lines       57058    57049       -9     
==========================================
+ Hits        31487    31502      +15     
+ Misses      22875    22852      -23     
+ Partials     2696     2695       -1     

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

healthCheckPassed = healthCheckPassed || healthStatus == string(health.HealthStatusDegraded)
}
} else {
healthCheckPassed = true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be more Go-style to init the variable as true and avoid else block this way.

Copy link
Member

@reggie-k reggie-k left a comment

Choose a reason for hiding this comment

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

Thanks for improving this code! LGTM with addressing Andrii's comment.

@@ -2456,28 +2456,21 @@ func checkResourceStatus(watch watchOpts, healthStatus string, syncStatus string
if watch.delete {
return false
}

healthBeingChecked := watch.suspended || watch.health || watch.degraded
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to init the variable and can just put a condition inline. But it's a small thing.

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, I thought it would be more readable that way as it is more obvious that the code is determining if one of the health conditions is being checked. Also happy to inline it if others feel differently.

Copy link
Contributor

Choose a reason for hiding this comment

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

Idk, this way works too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for final review
Development

Successfully merging this pull request may close these issues.

4 participants