Skip to content

Commit 03b1213

Browse files
Add event stats output to the operator logs for Ansible based-operators. (#2580)
1 parent a082052 commit 03b1213

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- On `generate csv`, populate a CSV manifest’s `spec.icon`, `spec.keywords`, and `spec.mantainers` fields with empty values to better inform users how to add data. ([#2521](https://github.com/operator-framework/operator-sdk/pull/2521))
1010
- Scaffold code in `cmd/manager/main.go` for Go operators and add logic to Ansible/Helm operators to handle [multinamespace caching](https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder) if `WATCH_NAMESPACE` contains multiple namespaces. ([#2522](https://github.com/operator-framework/operator-sdk/pull/2522))
1111
- Add a new flag option (`--skip-cleanup-error`) to the test framework to allow skip the function which will remove all artefacts when an error be faced to perform this operation. ([#2512](https://github.com/operator-framework/operator-sdk/pull/2512))
12+
- Add event stats output to the operator logs for Ansible based-operators. ([2580](https://github.com/operator-framework/operator-sdk/pull/2580))
1213

1314
### Changed
1415
- Ansible scaffolding has been rewritten to be simpler and make use of newer features of Ansible and Molecule.

pkg/ansible/controller/reconcile.go

+12
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,23 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
176176
// convert to StatusJobEvent; would love a better way to do this
177177
data, err := json.Marshal(event)
178178
if err != nil {
179+
printEventStats(statusEvent)
179180
return reconcile.Result{}, err
180181
}
181182
err = json.Unmarshal(data, &statusEvent)
182183
if err != nil {
184+
printEventStats(statusEvent)
183185
return reconcile.Result{}, err
184186
}
185187
}
186188
if event.Event == eventapi.EventRunnerOnFailed && !event.IgnoreError() {
187189
failureMessages = append(failureMessages, event.GetFailedPlaybookMessage())
188190
}
189191
}
192+
193+
// To print the stats of the task
194+
printEventStats(statusEvent)
195+
190196
if statusEvent.Event == "" {
191197
eventErr := errors.New("did not receive playbook_on_stats event")
192198
stdout, err := result.Stdout()
@@ -249,6 +255,12 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
249255
return reconcileResult, nil
250256
}
251257

258+
func printEventStats(statusEvent eventapi.StatusJobEvent) {
259+
fmt.Printf("\n--------------------------- Ansible Task Status Event StdOut -----------------\n")
260+
fmt.Println(statusEvent.StdOut)
261+
fmt.Printf("\n-------------------------------------------------------------------------------\n")
262+
}
263+
252264
func (r *AnsibleOperatorReconciler) markRunning(u *unstructured.Unstructured,
253265
namespacedName types.NamespacedName) error {
254266
// Get the latest resource to prevent updating a stale status.

0 commit comments

Comments
 (0)