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

Mark aggregated condition ready only when No error happened #184

Merged
merged 1 commit into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions controllers/application_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ func (r *ApplicationReconciler) getNewApplicationStatus(ctx context.Context, app
Objects: objectStatuses,
}
newApplicationStatus.ComponentsReady = fmt.Sprintf("%d/%d", countReady, len(objectStatuses))
if aggReady && errs != nil {
if errs != nil {
setReadyUnknownCondition(newApplicationStatus, "ComponentsReadyUnknown", "failed to aggregate all components' statuses, check the Error condition for details")
} else if aggReady {
setReadyCondition(newApplicationStatus, "ComponentsReady", "all components ready")
} else {
setNotReadyCondition(newApplicationStatus, "ComponentsNotReady", "some components not ready")
setNotReadyCondition(newApplicationStatus, "ComponentsNotReady", fmt.Sprintf("%d components not ready", len(objectStatuses) - countReady))
}

if errs != nil {
Expand Down
23 changes: 10 additions & 13 deletions controllers/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,30 @@ import (
)

func setReadyCondition(appStatus *appv1beta1.ApplicationStatus, reason, message string) {
setCondition(appStatus, appv1beta1.Ready, reason, message)
setCondition(appStatus, appv1beta1.Ready, corev1.ConditionTrue, reason, message)
}

// NotReady - shortcut to set ready condition to false
func setNotReadyCondition(appStatus *appv1beta1.ApplicationStatus, reason, message string) {
clearCondition(appStatus, appv1beta1.Ready, reason, message)
setCondition(appStatus, appv1beta1.Ready, corev1.ConditionFalse, reason, message)
}

// Unknown - shortcut to set ready condition to unknown
func setReadyUnknownCondition(appStatus *appv1beta1.ApplicationStatus, reason, message string) {
setCondition(appStatus, appv1beta1.Ready, corev1.ConditionUnknown, reason, message)
}

// setErrorCondition - shortcut to set error condition
func setErrorCondition(appStatus *appv1beta1.ApplicationStatus, reason, message string) {
setCondition(appStatus, appv1beta1.Error, reason, message)
setCondition(appStatus, appv1beta1.Error, corev1.ConditionTrue, reason, message)
}

// clearErrorCondition - shortcut to set error condition
func clearErrorCondition(appStatus *appv1beta1.ApplicationStatus) {
clearCondition(appStatus, appv1beta1.Error, "NoError", "No error seen")
}

func setCondition(appStatus *appv1beta1.ApplicationStatus, ctype appv1beta1.ConditionType, reason, message string) {
setConditionValue(appStatus, ctype, corev1.ConditionTrue, reason, message)
}

func clearCondition(appStatus *appv1beta1.ApplicationStatus, ctype appv1beta1.ConditionType, reason, message string) {
setConditionValue(appStatus, ctype, corev1.ConditionFalse, reason, message)
setCondition(appStatus, appv1beta1.Error, corev1.ConditionFalse, "NoError", "No error seen")
}

func setConditionValue(appStatus *appv1beta1.ApplicationStatus, ctype appv1beta1.ConditionType, status corev1.ConditionStatus, reason, message string) {
func setCondition(appStatus *appv1beta1.ApplicationStatus, ctype appv1beta1.ConditionType, status corev1.ConditionStatus, reason, message string) {
var c *appv1beta1.Condition
for i := range appStatus.Conditions {
if appStatus.Conditions[i].Type == ctype {
Expand Down