Skip to content

Commit 4369d36

Browse files
author
Shawn Hurley
authored
pkg/ansible: Update the running condition when reconcile happens (#966)
* 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.
1 parent 2156077 commit 4369d36

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

pkg/ansible/controller/reconcile.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"github.com/operator-framework/operator-sdk/pkg/ansible/runner"
3131
"github.com/operator-framework/operator-sdk/pkg/ansible/runner/eventapi"
3232

33-
"k8s.io/api/core/v1"
33+
v1 "k8s.io/api/core/v1"
3434
apierrors "k8s.io/apimachinery/pkg/api/errors"
3535
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3636
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -191,7 +191,6 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
191191
if err != nil {
192192
return reconcileResult, err
193193
}
194-
return reconcileResult, nil
195194
}
196195
if r.ManageStatus {
197196
err = r.markDone(u, request.NamespacedName, statusEvent, failureMessages)
@@ -214,25 +213,26 @@ func (r *AnsibleOperatorReconciler) markRunning(u *unstructured.Unstructured, na
214213

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

217+
if errCond != nil {
218+
errCond.Status = v1.ConditionFalse
219+
ansiblestatus.SetCondition(&crStatus, *errCond)
220+
}
219221
// If the condition is currently running, making sure that the values are correct.
220222
// If they are the same a no-op, if they are different then it is a good thing we
221223
// are updating it.
222-
if (errCond == nil && succCond == nil) || (succCond != nil && succCond.Reason != ansiblestatus.SuccessfulReason) {
223-
c := ansiblestatus.NewCondition(
224-
ansiblestatus.RunningConditionType,
225-
v1.ConditionTrue,
226-
nil,
227-
ansiblestatus.RunningReason,
228-
ansiblestatus.RunningMessage,
229-
)
230-
ansiblestatus.SetCondition(&crStatus, *c)
231-
u.Object["status"] = crStatus.GetJSONMap()
232-
err := r.Client.Status().Update(context.TODO(), u)
233-
if err != nil {
234-
return err
235-
}
224+
c := ansiblestatus.NewCondition(
225+
ansiblestatus.RunningConditionType,
226+
v1.ConditionTrue,
227+
nil,
228+
ansiblestatus.RunningReason,
229+
ansiblestatus.RunningMessage,
230+
)
231+
ansiblestatus.SetCondition(&crStatus, *c)
232+
u.Object["status"] = crStatus.GetJSONMap()
233+
err = r.Client.Status().Update(context.TODO(), u)
234+
if err != nil {
235+
return err
236236
}
237237
return nil
238238
}

0 commit comments

Comments
 (0)