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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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)
}
}
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.


synced := !watch.sync || syncStatus == string(argoappv1.SyncStatusCodeSynced)
Expand Down
Loading