Skip to content

Commit 782de3c

Browse files
mhrivnakfabianvf
authored andcommitted
fixes several ansible test failures and flaws
- Fixes bug where reconcile attempted to update status after running finalizer - Stops depending on grepping for a log statement for a test to pass - Disables debug log mode by default - logs cache miss at INFO instead of ERROR - adds commented-out check for errors in logs in e2e tests, which will be enabled after operator-framework#818 gets fixed
1 parent 5c2aaa0 commit 782de3c

File tree

7 files changed

+48
-7
lines changed

7 files changed

+48
-7
lines changed

hack/tests/e2e-ansible.sh

+16-1
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ then
7272
exit 1
7373
fi
7474

75+
# make a configmap that the finalizer should remove
76+
kubectl create configmap deleteme
77+
trap_add 'kubectl delete --ignore-not-found configmap deleteme' EXIT
78+
7579
kubectl delete -f ${DIR2}/deploy/crds/ansible_v1alpha1_memcached_cr.yaml --wait=true
76-
if ! kubectl logs deployment/memcached-operator | grep "this is a finalizer";
80+
# if the finalizer did not delete the configmap...
81+
if kubectl get configmap deleteme;
7782
then
83+
echo FAIL: the finalizer did not delete the configmap
7884
kubectl logs deployment/memcached-operator
7985
exit 1
8086
fi
@@ -86,5 +92,14 @@ then
8692
exit 1
8793
fi
8894

95+
96+
## TODO enable when this is fixed: https://github.com/operator-framework/operator-sdk/issues/818
97+
# if kubectl logs deployment/memcached-operator | grep -i error;
98+
# then
99+
# echo FAIL: the operator log includes errors
100+
# kubectl logs deployment/memcached-operator
101+
# exit 1
102+
# fi
103+
89104
popd
90105
popd

pkg/ansible/controller/reconcile.go

+4
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,13 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
186186
if err != nil {
187187
return reconcileResult, err
188188
}
189+
return reconcileResult, nil
189190
}
190191
if r.ManageStatus {
191192
err = r.markDone(u, statusEvent, failureMessages)
193+
if err != nil {
194+
logger.Error(err, "failed to mark status done")
195+
}
192196
}
193197
return reconcileResult, err
194198
}

pkg/ansible/controller/reconcile_test.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func TestReconcile(t *testing.T) {
318318
},
319319
},
320320
{
321-
Name: "Finalizer successful reconcile",
321+
Name: "Finalizer successful deletion reconcile",
322322
GVK: gvk,
323323
ReconcilePeriod: 5 * time.Second,
324324
ManageStatus: true,
@@ -344,6 +344,23 @@ func TestReconcile(t *testing.T) {
344344
"apiVersion": "operator-sdk/v1beta1",
345345
"kind": "Testing",
346346
"spec": map[string]interface{}{},
347+
"status": map[string]interface{}{
348+
"conditions": []interface{}{
349+
map[string]interface{}{
350+
"status": "True",
351+
"type": "Running",
352+
"ansibleResult": map[string]interface{}{
353+
"changed": int64(0),
354+
"failures": int64(0),
355+
"ok": int64(0),
356+
"skipped": int64(0),
357+
"completion": eventTime.Format("2006-01-02T15:04:05.99999999"),
358+
},
359+
"message": "Awaiting next reconciliation",
360+
"reason": "Successful",
361+
},
362+
},
363+
},
347364
},
348365
}),
349366
Result: reconcile.Result{

pkg/ansible/events/log_events.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (l loggingEventHandler) Handle(ident string, u *unstructured.Unstructured,
7070
return
7171
}
7272
if e.Event == eventapi.EventRunnerOnOk && debugAction {
73-
logger.V(1).Info("[playbook debug]", "EventData.TaskArgs", e.EventData["task_args"])
73+
logger.Info("[playbook debug]", "EventData.TaskArgs", e.EventData["task_args"])
7474
return
7575
}
7676
if e.Event == eventapi.EventRunnerOnFailed {

pkg/ansible/proxy/proxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func CacheResponseHandler(h http.Handler, informerCache cache.Cache, restMapper
9393
if err != nil {
9494
// break here in case resource doesn't exist in cache but exists on APIserver
9595
// This is very unlikely but provides user with expected 404
96-
log.Error(err, "didn't find object in cache")
96+
log.Info(fmt.Sprintf("cache miss: %v, %v", k, obj))
9797
break
9898
}
9999

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
- debug:
2-
msg: "this is a finalizer"
1+
- name: delete configmap for test
2+
k8s:
3+
kind: ConfigMap
4+
api_version: v1
5+
name: deleteme
6+
namespace: default
7+
state: absent

test/ansible-operator/cmd/ansible-operator/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func printVersion() {
3939
func main() {
4040
flag.Parse()
4141

42-
logf.SetLogger(logf.ZapLogger(true))
42+
logf.SetLogger(logf.ZapLogger(false))
4343

4444
namespace, err := k8sutil.GetWatchNamespace()
4545
if err != nil {

0 commit comments

Comments
 (0)