mirror of https://github.com/fluxcd/cli-utils.git
Support ReconcileFailed status in printers
This commit is contained in:
parent
9e462c333d
commit
6c2de94a5d
|
|
@ -106,6 +106,7 @@ func (d *DeleteStats) incFailed() {
|
|||
type WaitStats struct {
|
||||
Reconciled int
|
||||
Timeout int
|
||||
Failed int
|
||||
Skipped int
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +118,10 @@ func (w *WaitStats) incTimeout() {
|
|||
w.Timeout++
|
||||
}
|
||||
|
||||
func (w *WaitStats) incFailed() {
|
||||
w.Failed++
|
||||
}
|
||||
|
||||
func (w *WaitStats) incSkipped() {
|
||||
w.Skipped++
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ func (jf *formatter) FormatActionGroupEvent(
|
|||
"reconciled": ws.Reconciled,
|
||||
"skipped": ws.Skipped,
|
||||
"timeout": ws.Timeout,
|
||||
"failed": ws.Failed,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue