Skip to content

Commit

Permalink
Merge pull request #184 from nan-yu/master
Browse files Browse the repository at this point in the history
Mark aggregated condition ready only when No error happened
  • Loading branch information
k8s-ci-robot committed Mar 6, 2020
2 parents a3b16d8 + 7714cd6 commit f10d9ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
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

0 comments on commit f10d9ca

Please sign in to comment.