Skip to content

Commit d7235f5

Browse files
fix: (ansible) - Errors in the event have not been re-trigging the reconcile. (#2375)
* fix: (ansible) -Errors in the event have not been re-trigging the reconcile * Add a new test to check it with ManageStatus == false as well * Add changelog Closes #2372
1 parent 33f4b6f commit d7235f5

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
- Fix `operator-sdk build`'s `--image-build-args` to support spaces within quotes like `--label some.name="First Last"`. ([#2312](https://github.com/operator-framework/operator-sdk/pull/2312))
4141
- Fix misleading Helm operator "release not found" errors during CR deletion. ([#2359](https://github.com/operator-framework/operator-sdk/pull/2359))
42+
- Fix Ansible based image in order to re-trigger reconcile when playbooks are runner with error. ([#2375](https://github.com/operator-framework/operator-sdk/pull/2375))
4243

4344
## v0.13.0
4445

pkg/ansible/controller/reconcile.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
213213
// We only want to update the CustomResource once, so we'll track changes
214214
// and do it at the end
215215
runSuccessful := len(failureMessages) == 0
216+
216217
// The finalizer has run successfully, time to remove it
217218
if deleted && finalizerExists && runSuccessful {
218219
finalizers := []string{}
@@ -233,8 +234,17 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
233234
if errmark != nil {
234235
logger.Error(errmark, "Failed to mark status done")
235236
}
237+
// re-trigger reconcile because of failures
238+
if !runSuccessful {
239+
return reconcileResult, errors.New("event runner on failed")
240+
}
236241
return reconcileResult, errmark
237242
}
243+
244+
// re-trigger reconcile because of failures
245+
if !runSuccessful {
246+
return reconcileResult, errors.New("received failed task event")
247+
}
238248
return reconcileResult, nil
239249
}
240250

pkg/ansible/controller/reconcile_test.go

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ func TestReconcile(t *testing.T) {
133133
},
134134
},
135135
{
136-
Name: "Failure message reconcile",
137-
GVK: gvk,
138-
ReconcilePeriod: 5 * time.Second,
139-
ManageStatus: true,
136+
Name: "Failure event runner on failed with manageStatus == true",
137+
GVK: gvk,
138+
ManageStatus: true,
140139
Runner: &fake.Runner{
141140
JobEvents: []eventapi.JobEvent{
142141
eventapi.JobEvent{
@@ -165,9 +164,6 @@ func TestReconcile(t *testing.T) {
165164
"spec": map[string]interface{}{},
166165
},
167166
}),
168-
Result: reconcile.Result{
169-
RequeueAfter: 5 * time.Second,
170-
},
171167
Request: reconcile.Request{
172168
NamespacedName: types.NamespacedName{
173169
Name: "reconcile",
@@ -185,6 +181,12 @@ func TestReconcile(t *testing.T) {
185181
"spec": map[string]interface{}{},
186182
"status": map[string]interface{}{
187183
"conditions": []interface{}{
184+
map[string]interface{}{
185+
"status": "False",
186+
"type": "Running",
187+
"message": "Running reconciliation",
188+
"reason": "Running",
189+
},
188190
map[string]interface{}{
189191
"status": "True",
190192
"type": "Failure",
@@ -198,16 +200,51 @@ func TestReconcile(t *testing.T) {
198200
"message": "new failure message",
199201
"reason": "Failed",
200202
},
201-
map[string]interface{}{
202-
"status": "False",
203-
"type": "Running",
204-
"message": "Running reconciliation",
205-
"reason": "Running",
203+
},
204+
},
205+
},
206+
},
207+
ShouldError: true,
208+
},
209+
{
210+
Name: "Failure event runner on failed",
211+
GVK: gvk,
212+
ManageStatus: false,
213+
Runner: &fake.Runner{
214+
JobEvents: []eventapi.JobEvent{
215+
eventapi.JobEvent{
216+
Event: eventapi.EventRunnerOnFailed,
217+
Created: eventapi.EventTime{Time: eventTime},
218+
EventData: map[string]interface{}{
219+
"res": map[string]interface{}{
220+
"msg": "new failure message",
206221
},
207222
},
208223
},
224+
eventapi.JobEvent{
225+
Event: eventapi.EventPlaybookOnStats,
226+
Created: eventapi.EventTime{Time: eventTime},
227+
},
209228
},
210229
},
230+
Client: fakeclient.NewFakeClient(&unstructured.Unstructured{
231+
Object: map[string]interface{}{
232+
"metadata": map[string]interface{}{
233+
"name": "reconcile",
234+
"namespace": "default",
235+
},
236+
"apiVersion": "operator-sdk/v1beta1",
237+
"kind": "Testing",
238+
"spec": map[string]interface{}{},
239+
},
240+
}),
241+
Request: reconcile.Request{
242+
NamespacedName: types.NamespacedName{
243+
Name: "reconcile",
244+
Namespace: "default",
245+
},
246+
},
247+
ShouldError: true,
211248
},
212249
{
213250
Name: "Finalizer successful reconcile",

0 commit comments

Comments
 (0)