Skip to content

Commit

Permalink
pkg/ansible: Update the running condition when reconcile happens
Browse files Browse the repository at this point in the history
* will alert the user to when reconcile is happening
* will show the user the last results from ansible
* handles the case when the operator is failing.
  • Loading branch information
Shawn Hurley committed Feb 6, 2019
1 parent 1d3aa60 commit 5cc4cac
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions pkg/ansible/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
if exit, err := determineReturn(err); exit {
return reconcileResult, err
}
return reconcileResult, nil
}
if r.ManageStatus {
err = r.markDone(u, request.NamespacedName, statusEvent, failureMessages)
Expand All @@ -218,26 +217,26 @@ func (r *AnsibleOperatorReconciler) markRunning(u *unstructured.Unstructured, na

// If there is no current status add that we are working on this resource.
errCond := ansiblestatus.GetCondition(crStatus, ansiblestatus.FailureConditionType)
succCond := ansiblestatus.GetCondition(crStatus, ansiblestatus.RunningConditionType)

if errCond != nil {
errCond.Status = v1.ConditionFalse
ansiblestatus.SetCondition(&crStatus, *errCond)
}
// If the condition is currently running, making sure that the values are correct.
// If they are the same a no-op, if they are different then it is a good thing we
// are updating it.
if (errCond == nil && succCond == nil) || (succCond != nil && succCond.Reason != ansiblestatus.SuccessfulReason) {
c := ansiblestatus.NewCondition(
ansiblestatus.RunningConditionType,
v1.ConditionTrue,
nil,
ansiblestatus.RunningReason,
ansiblestatus.RunningMessage,
)
ansiblestatus.SetCondition(&crStatus, *c)
u.Object["status"] = crStatus.GetJSONMap()
err := r.Client.Status().Update(context.TODO(), u)
if err != nil {
return err
}

c := ansiblestatus.NewCondition(
ansiblestatus.RunningConditionType,
v1.ConditionTrue,
nil,
ansiblestatus.RunningReason,
ansiblestatus.RunningMessage,
)
ansiblestatus.SetCondition(&crStatus, *c)
u.Object["status"] = crStatus.GetJSONMap()
err = r.Client.Status().Update(context.TODO(), u)
if err != nil {
return err
}
return nil
}
Expand Down

0 comments on commit 5cc4cac

Please sign in to comment.