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