cleaning up deprecation

mine
derailed 2022-07-17 09:56:16 -06:00
parent e2687730bc
commit ee07b98755
14 changed files with 30 additions and 66 deletions

View File

@ -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

View File

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

View File

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

View File

@ -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 {

View File

@ -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))
}

View File

@ -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{

View File

@ -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

View File

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

View File

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

View File

@ -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 {

View File

@ -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 == "" {

View File

@ -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)

View File

@ -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

View File

@ -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