Skip to content

Commit

Permalink
Support ReconcileFailed status in printers
Browse files Browse the repository at this point in the history
  • Loading branch information
mortent committed Dec 7, 2021
1 parent 9e462c3 commit 6c2de94
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkg/print/list/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (d *DeleteStats) incFailed() {
type WaitStats struct {
Reconciled int
Timeout int
Failed int
Skipped int
}

Expand All @@ -117,6 +118,10 @@ func (w *WaitStats) incTimeout() {
w.Timeout++
}

func (w *WaitStats) incFailed() {
w.Failed++
}

func (w *WaitStats) incSkipped() {
w.Skipped++
}
Expand Down Expand Up @@ -208,6 +213,8 @@ func (b *BaseListPrinter) Print(ch <-chan event.Event, previewStrategy common.Dr
waitStats.incSkipped()
case event.ReconcileTimeout:
waitStats.incTimeout()
case event.ReconcileFailed:
waitStats.incFailed()
}
if err := formatter.FormatWaitEvent(e.WaitEvent); err != nil {
return err
Expand All @@ -226,16 +233,17 @@ func (b *BaseListPrinter) Print(ch <-chan event.Event, previewStrategy common.Dr
}
}
}
failedSum := applyStats.Failed + pruneStats.Failed + deleteStats.Failed
failedActuateSum := applyStats.Failed + pruneStats.Failed + deleteStats.Failed
failedReconcileSum := waitStats.Timeout + waitStats.Failed
switch {
case failedSum > 0 && waitStats.Timeout > 0:
case failedActuateSum > 0 && failedReconcileSum > 0:
return fmt.Errorf("%d resources failed, %d resources failed to reconcile before timeout",
failedSum, waitStats.Timeout)
case failedSum > 0:
return fmt.Errorf("%d resources failed", failedSum)
case waitStats.Timeout > 0:
failedActuateSum, failedReconcileSum)
case failedActuateSum > 0:
return fmt.Errorf("%d resources failed", failedActuateSum)
case failedReconcileSum > 0:
return fmt.Errorf("%d resources failed to reconcile before timeout",
waitStats.Timeout)
failedReconcileSum)
default:
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/printers/events/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func (ef *formatter) FormatWaitEvent(we event.WaitEvent) error {
ef.print("%s reconcile skipped", resourceIDToString(gk, name))
case event.ReconcileTimeout:
ef.print("%s reconcile timeout", resourceIDToString(gk, name))
case event.ReconcileFailed:
ef.print("%s reconcile failed", resourceIDToString(gk, name))
}
return nil
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/printers/events/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ func TestFormatter_FormatWaitEvent(t *testing.T) {
},
expected: "deployment.apps/my-dep reconcile skipped (preview-server)",
},
"resource reconcile failed": {
previewStrategy: common.DryRunNone,
event: event.WaitEvent{
GroupName: "wait-1",
Operation: event.ReconcileFailed,
Identifier: createIdentifier("apps", "Deployment", "default", "my-dep"),
},
expected: "deployment.apps/my-dep reconcile failed",
},
}

for tn, tc := range testCases {
Expand Down
1 change: 1 addition & 0 deletions pkg/printers/json/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (jf *formatter) FormatActionGroupEvent(
"reconciled": ws.Reconciled,
"skipped": ws.Skipped,
"timeout": ws.Timeout,
"failed": ws.Failed,
})
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/printers/json/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,24 @@ func TestFormatter_FormatWaitEvent(t *testing.T) {
"type": "wait",
},
},
"resource reconcile failed": {
previewStrategy: common.DryRunNone,
event: event.WaitEvent{
GroupName: "wait-1",
Operation: event.ReconcileFailed,
Identifier: createIdentifier("apps", "Deployment", "default", "my-dep"),
},
expected: map[string]interface{}{
"eventType": "resourceReconciled",
"group": "apps",
"kind": "Deployment",
"name": "my-dep",
"namespace": "default",
"operation": "Failed",
"timestamp": "",
"type": "wait",
},
},
}

for tn, tc := range testCases {
Expand Down

0 comments on commit 6c2de94

Please sign in to comment.