diff --git a/internal/render/hpa.go b/internal/render/hpa.go index 064b576f35..e12df95dac 100644 --- a/internal/render/hpa.go +++ b/internal/render/hpa.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" + "github.com/derailed/k9s/internal/model1" "github.com/derailed/tcell/v2" ) @@ -16,13 +17,17 @@ type HorizontalPodAutoscaler struct { } // ColorerFunc colors a resource row. -func (hpa HorizontalPodAutoscaler) ColorerFunc() ColorerFunc { - return func(ns string, h Header, re RowEvent) tcell.Color { - c := DefaultColorer(ns, h, re) +func (hpa HorizontalPodAutoscaler) ColorerFunc() model1.ColorerFunc { + return func(ns string, h model1.Header, re *model1.RowEvent) tcell.Color { + c := model1.DefaultColorer(ns, h, re) - maxPodsIndex := h.IndexOf("MAXPODS", true) - replicasIndex := h.IndexOf("REPLICAS", true) - if (maxPodsIndex < 0 || maxPodsIndex >= len(re.Row.Fields)) || (replicasIndex < 0 || replicasIndex >= len(re.Row.Fields)) { + maxPodsIndex, ok := h.IndexOf("MAXPODS", true) + if !ok || maxPodsIndex >= len(re.Row.Fields) { + return c + } + + replicasIndex, ok := h.IndexOf("REPLICAS", true) + if !ok || replicasIndex >= len(re.Row.Fields) { return c } @@ -38,7 +43,7 @@ func (hpa HorizontalPodAutoscaler) ColorerFunc() ColorerFunc { return c } if currentReplicas >= maxPods { - c = ErrColor + c = model1.ErrColor } return c } diff --git a/internal/render/hpa_test.go b/internal/render/hpa_test.go index 095978ffb8..21bb0855ba 100644 --- a/internal/render/hpa_test.go +++ b/internal/render/hpa_test.go @@ -6,57 +6,58 @@ package render import ( "testing" + "github.com/derailed/k9s/internal/model1" "github.com/derailed/tcell/v2" "github.com/derailed/tview" "github.com/stretchr/testify/assert" ) func TestHorizontalPodAutoscalerColorer(t *testing.T) { - hpaHeader := Header{ - HeaderColumn{Name: "NAMESPACE"}, - HeaderColumn{Name: "NAME"}, - HeaderColumn{Name: "REFERENCE"}, - HeaderColumn{Name: "TARGETS%"}, - HeaderColumn{Name: "MINPODS", Align: tview.AlignRight}, - HeaderColumn{Name: "MAXPODS", Align: tview.AlignRight}, - HeaderColumn{Name: "REPLICAS", Align: tview.AlignRight}, - HeaderColumn{Name: "AGE", Time: true}, + hpaHeader := model1.Header{ + model1.HeaderColumn{Name: "NAMESPACE"}, + model1.HeaderColumn{Name: "NAME"}, + model1.HeaderColumn{Name: "REFERENCE"}, + model1.HeaderColumn{Name: "TARGETS%"}, + model1.HeaderColumn{Name: "MINPODS", Align: tview.AlignRight}, + model1.HeaderColumn{Name: "MAXPODS", Align: tview.AlignRight}, + model1.HeaderColumn{Name: "REPLICAS", Align: tview.AlignRight}, + model1.HeaderColumn{Name: "AGE", Time: true}, } uu := map[string]struct { - h Header - re RowEvent + h model1.Header + re *model1.RowEvent e tcell.Color }{ "when replicas = maxpods": { h: hpaHeader, - re: RowEvent{ - Kind: EventUnchanged, - Row: Row{ - Fields: Fields{"blee", "fred", "fred", "100%", "1", "5", "5", "1d"}, + re: &model1.RowEvent{ + Kind: model1.EventUnchanged, + Row: model1.Row{ + Fields: model1.Fields{"blee", "fred", "fred", "100%", "1", "5", "5", "1d"}, }, }, - e: ErrColor, + e: model1.ErrColor, }, "when replicas > maxpods, for some reason": { h: hpaHeader, - re: RowEvent{ - Kind: EventUnchanged, - Row: Row{ - Fields: Fields{"blee", "fred", "fred", "100%", "1", "5", "6", "1d"}, + re: &model1.RowEvent{ + Kind: model1.EventUnchanged, + Row: model1.Row{ + Fields: model1.Fields{"blee", "fred", "fred", "100%", "1", "5", "6", "1d"}, }, }, - e: ErrColor, + e: model1.ErrColor, }, "when replicas < maxpods": { h: hpaHeader, - re: RowEvent{ - Kind: EventUnchanged, - Row: Row{ - Fields: Fields{"blee", "fred", "fred", "100%", "1", "5", "1", "1d"}, + re: &model1.RowEvent{ + Kind: model1.EventUnchanged, + Row: model1.Row{ + Fields: model1.Fields{"blee", "fred", "fred", "100%", "1", "5", "1", "1d"}, }, }, - e: StdColor, + e: model1.StdColor, }, }