Skip to content

Commit

Permalink
fix internal/render/hpa.go merge issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ebisso committed Aug 28, 2024
1 parent 35893ce commit 49671b7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
19 changes: 12 additions & 7 deletions internal/render/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"strings"

"github.com/derailed/k9s/internal/model1"
"github.com/derailed/tcell/v2"
)

Expand All @@ -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
}

Expand All @@ -38,7 +43,7 @@ func (hpa HorizontalPodAutoscaler) ColorerFunc() ColorerFunc {
return c
}
if currentReplicas >= maxPods {
c = ErrColor
c = model1.ErrColor
}
return c
}
Expand Down
53 changes: 27 additions & 26 deletions internal/render/hpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down

0 comments on commit 49671b7

Please sign in to comment.