Skip to content

Commit

Permalink
cleaning up deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Jul 17, 2022
1 parent e268773 commit ee07b98
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 66 deletions.
2 changes: 1 addition & 1 deletion internal/model/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions internal/render/ev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 0 additions & 11 deletions internal/render/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package render

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -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
}
4 changes: 0 additions & 4 deletions internal/render/row_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 0 additions & 11 deletions internal/ui/padding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
}
8 changes: 4 additions & 4 deletions internal/ui/padding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down
4 changes: 3 additions & 1 deletion internal/ui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/view/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion internal/view/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions internal/view/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions internal/view/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
15 changes: 8 additions & 7 deletions internal/view/pulse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"image"
"strings"

"github.com/derailed/k9s/internal"
"github.com/derailed/k9s/internal/client"
Expand All @@ -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.
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions internal/view/sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions internal/view/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ee07b98

Please sign in to comment.