Skip to content

Commit fd29031

Browse files
author
Shawn Hurley
committed
pkg/ansible: Adding unit tests for the ansible operator reconcile loop
* Adding fakes for runner, and runner result. * Updating status object to be ouput as a map for deep copy functions.
1 parent 25c0819 commit fd29031

File tree

6 files changed

+590
-13
lines changed

6 files changed

+590
-13
lines changed

Gopkg.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ansible/controller/reconcile.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
9999
}
100100
}
101101
if !contains(pendingFinalizers, finalizer) && deleted {
102-
logger.Info("Resource is terminated, skipping reconcilation")
103-
return reconcileResult, nil
102+
logrus.Info("Resource is terminated, skipping reconcilation")
103+
return reconcile.Result{}, nil
104104
}
105105

106106
spec := u.Object["spec"]
@@ -133,7 +133,7 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
133133
ansiblestatus.RunningMessage,
134134
)
135135
ansiblestatus.SetCondition(&crStatus, *c)
136-
u.Object["status"] = crStatus
136+
u.Object["status"] = crStatus.GetJSONMap()
137137
err = r.Client.Update(context.TODO(), u)
138138
if err != nil {
139139
return reconcileResult, err
@@ -160,7 +160,7 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
160160
// iterate events from ansible, looking for the final one
161161
statusEvent := eventapi.StatusJobEvent{}
162162
failureMessages := eventapi.FailureMessages{}
163-
for event := range result.Events {
163+
for event := range result.Events() {
164164
for _, eHandler := range r.EventHandlers {
165165
go eHandler.Handle(ident, u, event)
166166
}
@@ -234,7 +234,7 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
234234
ansiblestatus.SetCondition(&crStatus, *c)
235235
}
236236
// This needs the status subresource to be enabled by default.
237-
u.Object["status"] = crStatus
237+
u.Object["status"] = crStatus.GetJSONMap()
238238
err = r.Client.Update(context.TODO(), u)
239239
return reconcileResult, err
240240

0 commit comments

Comments
 (0)