diff --git a/internal/model/values.go b/internal/model/values.go index 1d349108..46022bc2 100644 --- a/internal/model/values.go +++ b/internal/model/values.go @@ -182,7 +182,7 @@ func (v *Values) refresh(ctx context.Context) error { return nil } -func (v *Values) reconcile(ctx context.Context) error { +func (v *Values) reconcile(_ context.Context) error { v.fireResourceChanged(v.lines, v.filter(v.query, v.lines)) return nil diff --git a/internal/render/ev.go b/internal/render/ev.go index f4959c87..9c28f13e 100644 --- a/internal/render/ev.go +++ b/internal/render/ev.go @@ -98,13 +98,3 @@ func (e *Event) Render(o interface{}, ns string, r *Row) error { return nil } - -func (e *Event) cellFor(n string, row metav1beta1.TableRow) (string, bool) { - for i, h := range e.table.ColumnDefinitions { - if h.Name == n { - return fmt.Sprintf("%v", row.Cells[i]), true - } - } - - return "", false -} diff --git a/internal/render/helpers_test.go b/internal/render/helpers_test.go index 1ec2e85e..7f8e2c0d 100644 --- a/internal/render/helpers_test.go +++ b/internal/render/helpers_test.go @@ -1,7 +1,6 @@ package render import ( - "fmt" "testing" "time" @@ -470,13 +469,3 @@ func BenchmarkIntToStr(b *testing.B) { IntToStr(v) } } - -// Helpers - -func testTime() time.Time { - t, err := time.Parse(time.RFC3339, "2018-12-14T10:36:43.326972-07:00") - if err != nil { - fmt.Println("TestTime Failed", err) - } - return t -} diff --git a/internal/render/row_event.go b/internal/render/row_event.go index 06015325..cfbb6502 100644 --- a/internal/render/row_event.go +++ b/internal/render/row_event.go @@ -195,10 +195,6 @@ func (r RowEvents) FindIndex(id string) (int, bool) { return 0, false } -type tuple struct { - field, id string -} - // Sort rows based on column index and order. func (r RowEvents) Sort(ns string, sortCol int, isDuration, numCol, asc bool) { if sortCol == -1 { diff --git a/internal/ui/padding.go b/internal/ui/padding.go index 1288eadd..62272da4 100644 --- a/internal/ui/padding.go +++ b/internal/ui/padding.go @@ -2,11 +2,9 @@ package ui import ( "strings" - "time" "unicode" "github.com/derailed/k9s/internal/render" - "k8s.io/apimachinery/pkg/util/duration" ) // MaxyPad tracks uniform column padding. @@ -55,12 +53,3 @@ func Pad(s string, width int) string { } return s + strings.Repeat(" ", width-len(s)) } - -func toAgeHuman(s string) string { - t, err := time.Parse(time.RFC3339Nano, s) - if err != nil { - return render.NAValue - } - - return duration.HumanDuration(time.Since(t)) -} diff --git a/internal/ui/padding_test.go b/internal/ui/padding_test.go index 6090d086..18aa83e5 100644 --- a/internal/ui/padding_test.go +++ b/internal/ui/padding_test.go @@ -9,12 +9,12 @@ import ( func TestMaxColumn(t *testing.T) { uu := map[string]struct { - t render.TableData + t *render.TableData s string e MaxyPad }{ "ascii col 0": { - render.TableData{ + &render.TableData{ Header: render.Header{render.HeaderColumn{Name: "A"}, render.HeaderColumn{Name: "B"}}, RowEvents: render.RowEvents{ render.RowEvent{ @@ -33,7 +33,7 @@ func TestMaxColumn(t *testing.T) { MaxyPad{6, 6}, }, "ascii col 1": { - render.TableData{ + &render.TableData{ Header: render.Header{render.HeaderColumn{Name: "A"}, render.HeaderColumn{Name: "B"}}, RowEvents: render.RowEvents{ render.RowEvent{ @@ -52,7 +52,7 @@ func TestMaxColumn(t *testing.T) { MaxyPad{6, 6}, }, "non_ascii": { - render.TableData{ + &render.TableData{ Header: render.Header{render.HeaderColumn{Name: "A"}, render.HeaderColumn{Name: "B"}}, RowEvents: render.RowEvents{ render.RowEvent{ diff --git a/internal/ui/table.go b/internal/ui/table.go index 00ac7c96..d77c69eb 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -14,6 +14,8 @@ import ( "github.com/derailed/tview" "github.com/gdamore/tcell/v2" "github.com/rs/zerolog/log" + "golang.org/x/text/cases" + "golang.org/x/text/language" ) type ( @@ -421,7 +423,7 @@ func (t *Table) styleTitle() string { rc-- } - base := strings.Title(t.gvr.R()) + base := cases.Title(language.Und, cases.NoLower).String(t.gvr.R()) ns := t.GetModel().GetNamespace() if client.IsClusterWide(ns) || ns == client.NotNamespaced { ns = client.NamespaceAll diff --git a/internal/view/exec.go b/internal/view/exec.go index e7bc2489..da68af5f 100644 --- a/internal/view/exec.go +++ b/internal/view/exec.go @@ -367,7 +367,7 @@ func asResource(r config.Limits) v1.ResourceRequirements { } } -func pipe(ctx context.Context, opts shellOpts, cmds ...*exec.Cmd) error { +func pipe(_ context.Context, opts shellOpts, cmds ...*exec.Cmd) error { if len(cmds) == 0 { return nil } diff --git a/internal/view/helm.go b/internal/view/helm.go index be86f2f1..b15fdbe1 100644 --- a/internal/view/helm.go +++ b/internal/view/helm.go @@ -9,6 +9,7 @@ import ( "github.com/derailed/k9s/internal/render" "github.com/derailed/k9s/internal/ui" "github.com/gdamore/tcell/v2" + "github.com/rs/zerolog/log" ) // Helm represents a helm chart view. @@ -66,7 +67,10 @@ func (c *Helm) getValsCmd() func(evt *tcell.EventKey) *tcell.EventKey { func (c *Helm) toggleValuesCmd(evt *tcell.EventKey) *tcell.EventKey { c.Values.ToggleValues() - c.Values.Refresh(c.defaultCtx()) + if err := c.Values.Refresh(c.defaultCtx()); err != nil { + log.Error().Err(err).Msgf("helm refresh failed") + return nil + } c.App().Flash().Infof("Values toggled") return nil } diff --git a/internal/view/log.go b/internal/view/log.go index 1d809d1a..b0302202 100644 --- a/internal/view/log.go +++ b/internal/view/log.go @@ -58,10 +58,6 @@ func NewLog(gvr client.GVR, opts *dao.LogOptions) *Log { return &l } -func logChan() dao.LogChan { - return make(dao.LogChan, 2) -} - // Init initializes the viewer. func (l *Log) Init(ctx context.Context) (err error) { if l.app, err = extractApp(ctx); err != nil { diff --git a/internal/view/pod.go b/internal/view/pod.go index cef2a766..e996fe87 100644 --- a/internal/view/pod.go +++ b/internal/view/pod.go @@ -154,13 +154,6 @@ func (p *Pod) showNode(evt *tcell.EventKey) *tcell.EventKey { return nil } -func nodeContext(path string) ContextFunc { - return func(ctx context.Context) context.Context { - ctx = context.WithValue(ctx, internal.KeyPath, path) - return ctx - } -} - func (p *Pod) showPFCmd(evt *tcell.EventKey) *tcell.EventKey { path := p.GetTable().GetSelectedItem() if path == "" { diff --git a/internal/view/pulse.go b/internal/view/pulse.go index e7feddf3..0c5699fd 100644 --- a/internal/view/pulse.go +++ b/internal/view/pulse.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "image" - "strings" "github.com/derailed/k9s/internal" "github.com/derailed/k9s/internal/client" @@ -16,6 +15,8 @@ import ( "github.com/derailed/k9s/internal/ui" "github.com/derailed/tview" "github.com/gdamore/tcell/v2" + "golang.org/x/text/cases" + "golang.org/x/text/language" ) // Graphable represents a graphic component. @@ -162,7 +163,7 @@ func (p *Pulse) PulseChanged(c *health.Check) { case "cpu": perc := client.ToPercentage(c.Tally(health.S1), c.Tally(health.S2)) v.SetLegend(fmt.Sprintf(cpuFmt, - strings.Title(gvr.R()), + cases.Title(language.Und, cases.NoLower).String(gvr.R()), p.app.Config.K9s.Thresholds.SeverityColor("cpu", perc), render.PrintPerc(perc), nn[0], @@ -173,7 +174,7 @@ func (p *Pulse) PulseChanged(c *health.Check) { case "mem": perc := client.ToPercentage(c.Tally(health.S1), c.Tally(health.S2)) v.SetLegend(fmt.Sprintf(memFmt, - strings.Title(gvr.R()), + cases.Title(language.Und, cases.NoLower).String(gvr.R()), p.app.Config.K9s.Thresholds.SeverityColor("memory", perc), render.PrintPerc(perc), nn[0], @@ -183,7 +184,7 @@ func (p *Pulse) PulseChanged(c *health.Check) { )) default: v.SetLegend(fmt.Sprintf(genFmat, - strings.Title(gvr.R()), + cases.Title(language.Und, cases.NoLower).String(gvr.R()), nn[0], c.Tally(health.S1), nn[1], @@ -206,7 +207,7 @@ func (p *Pulse) bindKeys() { }) for i, v := range p.charts { - t := strings.Title(client.NewGVR(v.ID()).R()) + t := cases.Title(language.Und, cases.NoLower).String(client.NewGVR(v.ID()).R()) p.actions[tcell.Key(ui.NumKeys[i])] = ui.NewKeyAction(t, p.sparkFocusCmd(i), true) } } @@ -340,7 +341,7 @@ func (p *Pulse) makeSP(loc image.Point, span image.Point, gvr string) *tchart.Sp } else { s.SetSeriesColors(p.app.Styles.Charts().DefaultChartColors.Colors()...) } - s.SetLegend(fmt.Sprintf(" %s ", strings.Title(client.NewGVR(gvr).R()))) + s.SetLegend(fmt.Sprintf(" %s ", cases.Title(language.Und, cases.NoLower).String(client.NewGVR(gvr).R()))) s.SetInputCapture(p.keyboard) s.SetMultiSeries(true) p.AddItem(s, loc.X, loc.Y, span.X, span.Y, 0, 0, true) @@ -358,7 +359,7 @@ func (p *Pulse) makeGA(loc image.Point, span image.Point, gvr string) *tchart.Ga } else { g.SetSeriesColors(p.app.Styles.Charts().DefaultDialColors.Colors()...) } - g.SetLegend(fmt.Sprintf(" %s ", strings.Title(client.NewGVR(gvr).R()))) + g.SetLegend(fmt.Sprintf(" %s ", cases.Title(language.Und, cases.NoLower).String(client.NewGVR(gvr).R()))) g.SetInputCapture(p.keyboard) p.AddItem(g, loc.X, loc.Y, span.X, span.Y, 0, 0, true) diff --git a/internal/view/sanitizer.go b/internal/view/sanitizer.go index 3cc4f9ff..c0799604 100644 --- a/internal/view/sanitizer.go +++ b/internal/view/sanitizer.go @@ -14,6 +14,8 @@ import ( "github.com/derailed/tview" "github.com/gdamore/tcell/v2" "github.com/rs/zerolog/log" + "golang.org/x/text/cases" + "golang.org/x/text/language" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -65,7 +67,7 @@ func (s *Sanitizer) Init(ctx context.Context) error { s.SetBorderColor(s.app.Styles.Frame().Border.FgColor.Color()) s.SetBorderFocusColor(s.app.Styles.Frame().Border.FocusColor.Color()) s.SetGraphicsColor(s.app.Styles.Xray().GraphicColor.Color()) - s.SetTitle(strings.Title(s.gvr.R())) + s.SetTitle(cases.Title(language.Und, cases.NoLower).String(s.gvr.R())) s.model.SetNamespace(client.CleanseNamespace(s.app.Config.ActiveNamespace())) s.model.AddListener(s) @@ -401,7 +403,7 @@ func (s *Sanitizer) UpdateTitle() { } func (s *Sanitizer) styleTitle() string { - base := strings.Title(s.gvr.R()) + base := cases.Title(language.Und, cases.NoLower).String(s.gvr.R()) ns := s.model.GetNamespace() if client.IsAllNamespaces(ns) { ns = client.NamespaceAll diff --git a/internal/view/xray.go b/internal/view/xray.go index 96525cd8..6b4f2b52 100644 --- a/internal/view/xray.go +++ b/internal/view/xray.go @@ -20,6 +20,8 @@ import ( "github.com/gdamore/tcell/v2" "github.com/rs/zerolog/log" "github.com/sahilm/fuzzy" + "golang.org/x/text/cases" + "golang.org/x/text/language" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -72,7 +74,7 @@ func (x *Xray) Init(ctx context.Context) error { x.SetBorderColor(x.app.Styles.Xray().FgColor.Color()) x.SetBorderFocusColor(x.app.Styles.Frame().Border.FocusColor.Color()) x.SetGraphicsColor(x.app.Styles.Xray().GraphicColor.Color()) - x.SetTitle(fmt.Sprintf(" %s-%s ", xrayTitle, strings.Title(x.gvr.R()))) + x.SetTitle(fmt.Sprintf(" %s-%s ", xrayTitle, cases.Title(language.Und, cases.NoLower).String(x.gvr.R()))) x.model.SetRefreshRate(time.Duration(x.app.Config.K9s.GetRefreshRate()) * time.Second) x.model.SetNamespace(client.CleanseNamespace(x.app.Config.ActiveNamespace())) @@ -632,7 +634,7 @@ func (x *Xray) UpdateTitle() { } func (x *Xray) styleTitle() string { - base := fmt.Sprintf("%s-%s", xrayTitle, strings.Title(x.gvr.R())) + base := fmt.Sprintf("%s-%s", xrayTitle, cases.Title(language.Und, cases.NoLower).String(x.gvr.R())) ns := x.model.GetNamespace() if client.IsAllNamespaces(ns) { ns = client.NamespaceAll