Merge branch 'popeye'

mine
derailed 2020-06-19 17:53:17 -06:00
commit 766bf133da
7 changed files with 18 additions and 15 deletions

4
go.mod
View File

@ -1,11 +1,11 @@
module github.com/derailed/k9s
go 1.13
go 1.14
require (
9fans.net/go v0.0.2
github.com/atotto/clipboard v0.1.2
github.com/derailed/popeye v0.8.4
github.com/derailed/popeye v0.8.6
github.com/derailed/tview v0.3.10
github.com/drone/envsubst v1.0.2 // indirect
github.com/fatih/color v1.9.0

4
go.sum
View File

@ -146,6 +146,10 @@ github.com/derailed/popeye v0.8.3 h1:fsZ+EfFlOzgQCAeerJuajJmSrLZTNEGyLI4LfEdUHJ8
github.com/derailed/popeye v0.8.3/go.mod h1:i4ge2tKHDKXgUq3NzFlIhVIBNHS0zFDMJWXsC2bVe2A=
github.com/derailed/popeye v0.8.4 h1:cvsPYPbrLmFhKfhfH1NtzS46rWsrxRSgX4EhIKLnlGQ=
github.com/derailed/popeye v0.8.4/go.mod h1:+u3tvVxADQQ2o6iJjgAO8cnQFq/GIWEUPXEWa1N6l54=
github.com/derailed/popeye v0.8.5 h1:uk60VlJDjTuaqAs0WcY85ihBfbrsF8mBzDsMo76knw4=
github.com/derailed/popeye v0.8.5/go.mod h1:+u3tvVxADQQ2o6iJjgAO8cnQFq/GIWEUPXEWa1N6l54=
github.com/derailed/popeye v0.8.6 h1:K56ENXB41XVZEQk8nhdEPD90BBfyYClw6akAfEMSOeU=
github.com/derailed/popeye v0.8.6/go.mod h1:+u3tvVxADQQ2o6iJjgAO8cnQFq/GIWEUPXEWa1N6l54=
github.com/derailed/tview v0.3.10 h1:n+iQwYh9Ff9STdR5hBhp+rTJRlu59q2xP2pHvwQbYPw=
github.com/derailed/tview v0.3.10/go.mod h1:GJ3k/TIzEE+sj1L09/usk6HrkjsdadSsb03eHgPbcII=
github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=

View File

@ -47,7 +47,7 @@ func (readWriteCloser) Close() error {
}
// List returns a collection of aliases.
func (p *Popeye) List(ctx context.Context, _ string) ([]runtime.Object, error) {
func (p *Popeye) List(ctx context.Context, ns string) ([]runtime.Object, error) {
defer func(t time.Time) {
log.Debug().Msgf("Popeye -- Elapsed %v", time.Since(t))
if err := recover(); err != nil {
@ -57,10 +57,13 @@ func (p *Popeye) List(ctx context.Context, _ string) ([]runtime.Object, error) {
flags, js := config.NewFlags(), "json"
flags.Output = &js
flags.ActiveNamespace = &ns
if report, ok := ctx.Value(internal.KeyPath).(string); ok && report != "" {
sections := []string{report}
ns, n := client.Namespaced(report)
sections := []string{n}
flags.Sections = &sections
flags.ActiveNamespace = &ns
}
spinach := filepath.Join(cfg.K9sHome(), "spinach.yml")
if c, err := p.Factory.Client().Config().CurrentContextName(); err == nil {

View File

@ -176,6 +176,7 @@ func loadK9s(m ResourceMetas) {
Name: "popeye",
Kind: "Popeye",
SingularName: "popeye",
Namespaced: true,
Verbs: []string{},
Categories: []string{"k9s"},
}

View File

@ -217,11 +217,8 @@ func (t *Tree) reconcile(ctx context.Context) error {
if err := genericTreeHydrate(ctx, ns, table, meta.TreeRenderer); err != nil {
return err
}
} else {
if err := treeHydrate(ctx, ns, oo, meta.TreeRenderer); err != nil {
return err
}
} else if err := treeHydrate(ctx, ns, oo, meta.TreeRenderer); err != nil {
return err
}
root.Sort()

View File

@ -2,6 +2,7 @@ package render
import (
"fmt"
"github.com/derailed/k9s/internal/client"
"math"
"strconv"
"strings"
@ -55,7 +56,7 @@ func (Popeye) Render(o interface{}, ns string, r *Row) error {
return fmt.Errorf("expected Section, but got %T", o)
}
r.ID = s.Title
r.ID = client.FQN(ns, s.Title)
r.Fields = append(r.Fields,
s.Title,
strconv.Itoa(s.Tally.Score()),

View File

@ -38,7 +38,6 @@ func (p *Popeye) Init(ctx context.Context) error {
if err := p.ResourceViewer.Init(ctx); err != nil {
return err
}
p.GetTable().GetModel().SetNamespace("*")
p.GetTable().GetModel().SetRefreshRate(5 * time.Second)
return nil
@ -66,7 +65,7 @@ func (p *Popeye) decorateRows(data render.TableData) render.TableData {
func (p *Popeye) bindKeys(aa ui.KeyActions) {
aa.Delete(ui.KeyShiftA, ui.KeyShiftN, tcell.KeyCtrlS, tcell.KeyCtrlSpace, ui.KeySpace)
aa.Add(ui.KeyActions{
tcell.KeyEnter: ui.NewKeyAction("Goto", p.describeCmd, true),
tcell.KeyEnter: ui.NewKeyAction("Goto", p.gotoCmd, true),
ui.KeyShiftR: ui.NewKeyAction("Sort Resource", p.GetTable().SortColCmd("RESOURCE", true), false),
ui.KeyShiftS: ui.NewKeyAction("Sort Score", p.GetTable().SortColCmd("SCORE%", true), false),
ui.KeyShiftO: ui.NewKeyAction("Sort OK", p.GetTable().SortColCmd("OK", true), false),
@ -76,15 +75,13 @@ func (p *Popeye) bindKeys(aa ui.KeyActions) {
})
}
func (p *Popeye) describeCmd(evt *tcell.EventKey) *tcell.EventKey {
func (p *Popeye) gotoCmd(evt *tcell.EventKey) *tcell.EventKey {
path := p.GetTable().GetSelectedItem()
if path == "" {
return evt
}
v := NewSanitizer(client.NewGVR("sanitizer"))
v.SetContextFn(sanitizerCtx(path))
if err := p.App().inject(v); err != nil {
p.App().Flash().Err(err)
}