Skip to content

Commit

Permalink
Fix Toggle Faults filtering (#2509)
Browse files Browse the repository at this point in the history
* Added valid column to workloads for toast filtering

* Removed redundant status func call, changed workload header order
  • Loading branch information
eiachh authored Feb 3, 2024
1 parent 3c20f0d commit cd5522c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 14 additions & 4 deletions internal/dao/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ func (a *Workload) List(ctx context.Context, ns string) ([]runtime.Object, error
ts = m.CreationTimestamp
}
}
stat := status(gvr, r, table.ColumnDefinitions)
oo = append(oo, &render.WorkloadRes{Row: metav1.TableRow{Cells: []interface{}{
gvr.String(),
ns,
r.Cells[indexOf("Name", table.ColumnDefinitions)],
diagnose(gvr, r, table.ColumnDefinitions),
status(gvr, r, table.ColumnDefinitions),
stat,
readiness(gvr, r, table.ColumnDefinitions),
validity(stat),
ts,
}}})
}
Expand All @@ -138,7 +140,7 @@ func (a *Workload) List(ctx context.Context, ns string) ([]runtime.Object, error

// Helpers...

func status(gvr client.GVR, r metav1.TableRow, h []metav1.TableColumnDefinition) string {
func readiness(gvr client.GVR, r metav1.TableRow, h []metav1.TableColumnDefinition) string {
switch gvr {
case PodGVR, DpGVR, StsGVR:
return r.Cells[indexOf("Ready", h)].(string)
Expand All @@ -153,7 +155,7 @@ func status(gvr client.GVR, r metav1.TableRow, h []metav1.TableColumnDefinition)
return render.NAValue
}

func diagnose(gvr client.GVR, r metav1.TableRow, h []metav1.TableColumnDefinition) string {
func status(gvr client.GVR, r metav1.TableRow, h []metav1.TableColumnDefinition) string {
switch gvr {
case PodGVR:
if !isReady(r.Cells[indexOf("Ready", h)].(string)) || r.Cells[indexOf("Status", h)] != render.PhaseRunning {
Expand Down Expand Up @@ -187,6 +189,14 @@ func diagnose(gvr client.GVR, r metav1.TableRow, h []metav1.TableColumnDefinitio
return StatusOK
}

func validity(status string) string {
if status != "DEGRADED" {
return ""
}

return status
}

func isReady(s string) bool {
tt := strings.Split(s, "/")
if len(tt) != 2 {
Expand Down
4 changes: 3 additions & 1 deletion internal/render/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (Workload) Header(string) Header {
HeaderColumn{Name: "NAME"},
HeaderColumn{Name: "STATUS"},
HeaderColumn{Name: "READY"},
HeaderColumn{Name: "VALID", Wide: true},
HeaderColumn{Name: "AGE", Time: true},
}
}
Expand All @@ -62,7 +63,8 @@ func (n Workload) Render(o interface{}, _ string, r *Row) error {
res.Row.Cells[2].(string),
res.Row.Cells[3].(string),
res.Row.Cells[4].(string),
ToAge(res.Row.Cells[5].(metav1.Time)),
res.Row.Cells[5].(string),
ToAge(res.Row.Cells[6].(metav1.Time)),
}

return nil
Expand Down

0 comments on commit cd5522c

Please sign in to comment.