-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
tangboxuan
wants to merge
5
commits into
argoproj:master
Choose a base branch
from
tangboxuan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+13
−20
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48c5f2d
Improve checkResrouceStatus readability
tangboxuan 2e68568
gofumpt lint
tangboxuan c487783
Merge branch 'master' into master
tangboxuan 0e2257b
Merge branch 'argoproj:master' into master
tangboxuan 3bf6ca4
Init healthCheckPassed as true
tangboxuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2456,28 +2456,21 @@ func checkResourceStatus(watch watchOpts, healthStatus string, syncStatus string | |
if watch.delete { | ||
return false | ||
} | ||
|
||
healthBeingChecked := watch.suspended || watch.health || watch.degraded | ||
healthCheckPassed := true | ||
|
||
if watch.suspended && watch.health && watch.degraded { | ||
healthCheckPassed = healthStatus == string(health.HealthStatusHealthy) || | ||
healthStatus == string(health.HealthStatusSuspended) || | ||
healthStatus == string(health.HealthStatusDegraded) | ||
} else if watch.suspended && watch.degraded { | ||
healthCheckPassed = healthStatus == string(health.HealthStatusDegraded) || | ||
healthStatus == string(health.HealthStatusSuspended) | ||
} else if watch.degraded && watch.health { | ||
healthCheckPassed = healthStatus == string(health.HealthStatusHealthy) || | ||
healthStatus == string(health.HealthStatusDegraded) | ||
// below are good | ||
} else if watch.suspended && watch.health { | ||
healthCheckPassed = healthStatus == string(health.HealthStatusHealthy) || | ||
healthStatus == string(health.HealthStatusSuspended) | ||
} else if watch.suspended { | ||
healthCheckPassed = healthStatus == string(health.HealthStatusSuspended) | ||
} else if watch.health { | ||
healthCheckPassed = healthStatus == string(health.HealthStatusHealthy) | ||
} else if watch.degraded { | ||
healthCheckPassed = healthStatus == string(health.HealthStatusDegraded) | ||
if healthBeingChecked { | ||
healthCheckPassed = false | ||
if watch.health { | ||
healthCheckPassed = healthCheckPassed || healthStatus == string(health.HealthStatusHealthy) | ||
} | ||
if watch.suspended { | ||
healthCheckPassed = healthCheckPassed || healthStatus == string(health.HealthStatusSuspended) | ||
} | ||
if watch.degraded { | ||
healthCheckPassed = healthCheckPassed || healthStatus == string(health.HealthStatusDegraded) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
synced := !watch.sync || syncStatus == string(argoappv1.SyncStatusCodeSynced) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.