cleaning up

mine
derailed 2020-05-28 14:02:43 -06:00
parent 26a4100ecf
commit 3cfc4e860c
15 changed files with 32 additions and 11 deletions

View File

@ -72,6 +72,7 @@ func InitConnection(config *Config) (*APIClient, error) {
return &a, err return &a, err
} }
// ConnectionOK returns connection status.
func (a *APIClient) ConnectionOK() bool { func (a *APIClient) ConnectionOK() bool {
return a.connOK return a.connOK
} }
@ -304,7 +305,7 @@ func (a *APIClient) Dial() (kubernetes.Interface, error) {
return a.client, nil return a.client, nil
} }
// RestConfigOrDie returns a rest api client. // RestConfig returns a rest api client.
func (a *APIClient) RestConfig() (*restclient.Config, error) { func (a *APIClient) RestConfig() (*restclient.Config, error) {
cfg, err := a.config.RESTConfig() cfg, err := a.config.RESTConfig()
if err != nil { if err != nil {

View File

@ -132,6 +132,7 @@ func (c *Config) ActiveNamespace() string {
return "default" return "default"
} }
// ValidateFavorites ensure favorite ns are legit.
func (c *Config) ValidateFavorites() { func (c *Config) ValidateFavorites() {
cl := c.K9s.ActiveCluster() cl := c.K9s.ActiveCluster()
if cl == nil { if cl == nil {

View File

@ -5,7 +5,7 @@ type FeatureGates struct {
NodeShell bool `yaml:"nodeShell"` NodeShell bool `yaml:"nodeShell"`
} }
// NewFeatureGate returns a new feature gate. // NewFeatureGates returns a new feature gate.
func NewFeatureGates() *FeatureGates { func NewFeatureGates() *FeatureGates {
return &FeatureGates{} return &FeatureGates{}
} }

View File

@ -49,6 +49,7 @@ func scanners() map[string]RefScanner {
} }
} }
// ScanForRefs scans cluster resources for resource references.
func ScanForRefs(ctx context.Context, f Factory) (Refs, error) { func ScanForRefs(ctx context.Context, f Factory) (Refs, error) {
defer func(t time.Time) { defer func(t time.Time) {
log.Debug().Msgf("Cluster Scan %v", time.Since(t)) log.Debug().Msgf("Cluster Scan %v", time.Since(t))
@ -101,6 +102,7 @@ func ScanForRefs(ctx context.Context, f Factory) (Refs, error) {
return res, nil return res, nil
} }
// ScanForSARefs scans cluster resources for serviceaccount refs.
func ScanForSARefs(ctx context.Context, f Factory) (Refs, error) { func ScanForSARefs(ctx context.Context, f Factory) (Refs, error) {
defer func(t time.Time) { defer func(t time.Time) {
log.Debug().Msgf("Cluster Scan %v", time.Since(t)) log.Debug().Msgf("Cluster Scan %v", time.Since(t))

View File

@ -75,6 +75,7 @@ func (c *CronJob) Run(path string) error {
return err return err
} }
// ScanSA scans for serviceaccount refs.
func (c *CronJob) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) { func (c *CronJob) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := c.Factory.List(c.GVR(), ns, wait, labels.Everything()) oo, err := c.Factory.List(c.GVR(), ns, wait, labels.Everything())
@ -100,6 +101,7 @@ func (c *CronJob) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, erro
return refs, nil return refs, nil
} }
// Scan scans for cluster resource refs.
func (c *CronJob) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) { func (c *CronJob) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := c.Factory.List(c.GVR(), ns, wait, labels.Everything()) oo, err := c.Factory.List(c.GVR(), ns, wait, labels.Everything())

View File

@ -134,6 +134,7 @@ func (*Deployment) Load(f Factory, fqn string) (*appsv1.Deployment, error) {
return &dp, nil return &dp, nil
} }
// ScanSA scans for serviceaccount refs.
func (d *Deployment) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) { func (d *Deployment) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything()) oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything())
@ -159,6 +160,7 @@ func (d *Deployment) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, e
return refs, nil return refs, nil
} }
// Scan scans for resource references.
func (d *Deployment) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) { func (d *Deployment) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything()) oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything())

View File

@ -148,6 +148,7 @@ func (d *DaemonSet) GetInstance(fqn string) (*appsv1.DaemonSet, error) {
return &ds, nil return &ds, nil
} }
// ScanSA scans for serviceaccount refs.
func (d *DaemonSet) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) { func (d *DaemonSet) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything()) oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything())
@ -173,6 +174,7 @@ func (d *DaemonSet) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, er
return refs, nil return refs, nil
} }
// Scan scans for cluster refs.
func (d *DaemonSet) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) { func (d *DaemonSet) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything()) oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything())

View File

@ -44,6 +44,7 @@ func (j *Job) TailLogs(ctx context.Context, c LogChan, opts LogOptions) error {
return podLogs(ctx, c, job.Spec.Selector.MatchLabels, opts) return podLogs(ctx, c, job.Spec.Selector.MatchLabels, opts)
} }
// ScanSA scans for serviceaccount refs.
func (j *Job) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) { func (j *Job) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := j.Factory.List(j.GVR(), ns, wait, labels.Everything()) oo, err := j.Factory.List(j.GVR(), ns, wait, labels.Everything())
@ -69,6 +70,7 @@ func (j *Job) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
return refs, nil return refs, nil
} }
// Scan scans for resource references.
func (j *Job) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) { func (j *Job) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := j.Factory.List(j.GVR(), ns, wait, labels.Everything()) oo, err := j.Factory.List(j.GVR(), ns, wait, labels.Everything())

View File

@ -230,6 +230,7 @@ func (p *Pod) TailLogs(ctx context.Context, c LogChan, opts LogOptions) error {
return nil return nil
} }
// ScanSA scans for serviceaccount refs.
func (p *Pod) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) { func (p *Pod) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := p.Factory.List(p.GVR(), ns, wait, labels.Everything()) oo, err := p.Factory.List(p.GVR(), ns, wait, labels.Everything())
@ -259,6 +260,7 @@ func (p *Pod) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
return refs, nil return refs, nil
} }
// Scan scans for cluster resource refs.
func (p *Pod) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) { func (p *Pod) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := p.Factory.List(p.GVR(), ns, wait, labels.Everything()) oo, err := p.Factory.List(p.GVR(), ns, wait, labels.Everything())

View File

@ -10,14 +10,14 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
) )
var ( var _ Accessor = (*Reference)(nil)
_ Accessor = (*Reference)(nil)
)
// Reference represents cluster resource references.
type Reference struct { type Reference struct {
NonResource NonResource
} }
// List collects all references.
func (r *Reference) List(ctx context.Context, ns string) ([]runtime.Object, error) { func (r *Reference) List(ctx context.Context, ns string) ([]runtime.Object, error) {
gvr, ok := ctx.Value(internal.KeyGVR).(string) gvr, ok := ctx.Value(internal.KeyGVR).(string)
if !ok { if !ok {
@ -31,10 +31,12 @@ func (r *Reference) List(ctx context.Context, ns string) ([]runtime.Object, erro
} }
} }
// Get fetch a given reference.
func (c *Reference) Get(ctx context.Context, path string) (runtime.Object, error) { func (c *Reference) Get(ctx context.Context, path string) (runtime.Object, error) {
panic("NYI") panic("NYI")
} }
// Scan scan cluster resources for references.
func (r *Reference) Scan(ctx context.Context) ([]runtime.Object, error) { func (r *Reference) Scan(ctx context.Context) ([]runtime.Object, error) {
refs, err := ScanForRefs(ctx, r.Factory) refs, err := ScanForRefs(ctx, r.Factory)
if err != nil { if err != nil {
@ -59,6 +61,7 @@ func (r *Reference) Scan(ctx context.Context) ([]runtime.Object, error) {
return oo, nil return oo, nil
} }
// ScanSA scans for serviceaccount refs.
func (r *Reference) ScanSA(ctx context.Context) ([]runtime.Object, error) { func (r *Reference) ScanSA(ctx context.Context) ([]runtime.Object, error) {
refs, err := ScanForSARefs(ctx, r.Factory) refs, err := ScanForSARefs(ctx, r.Factory)
if err != nil { if err != nil {

View File

@ -133,6 +133,7 @@ func (s *StatefulSet) getStatefulSet(fqn string) (*appsv1.StatefulSet, error) {
return &sts, nil return &sts, nil
} }
// ScanSA scans for serviceaccount refs.
func (s *StatefulSet) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) { func (s *StatefulSet) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := s.Factory.List(s.GVR(), ns, wait, labels.Everything()) oo, err := s.Factory.List(s.GVR(), ns, wait, labels.Everything())
@ -158,6 +159,7 @@ func (s *StatefulSet) ScanSA(ctx context.Context, fqn string, wait bool) (Refs,
return refs, nil return refs, nil
} }
// Scan scans for cluster resource refs.
func (s *StatefulSet) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) { func (s *StatefulSet) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn) ns, n := client.Namespaced(fqn)
oo, err := s.Factory.List(s.GVR(), ns, wait, labels.Everything()) oo, err := s.Factory.List(s.GVR(), ns, wait, labels.Everything())

View File

@ -75,6 +75,7 @@ func (r RowEvent) Customize(cols []int) RowEvent {
} }
} }
// ExtractHeaderLabels extract collection of fields into header.
func (r RowEvent) ExtractHeaderLabels(labelCol int) []string { func (r RowEvent) ExtractHeaderLabels(labelCol int) []string {
hh, _ := sortLabels(labelize(r.Row.Fields[labelCol])) hh, _ := sortLabels(labelize(r.Row.Fields[labelCol]))
return hh return hh
@ -105,6 +106,7 @@ func (r RowEvent) Diff(re RowEvent, ageCol int) bool {
// RowEvents a collection of row events. // RowEvents a collection of row events.
type RowEvents []RowEvent type RowEvents []RowEvent
// ExtractHeaderLabels extract header labels.
func (r RowEvents) ExtractHeaderLabels(labelCol int) []string { func (r RowEvents) ExtractHeaderLabels(labelCol int) []string {
ll := make([]string, 0, 10) ll := make([]string, 0, 10)
for _, re := range r { for _, re := range r {
@ -114,6 +116,7 @@ func (r RowEvents) ExtractHeaderLabels(labelCol int) []string {
return ll return ll
} }
// Labelize converts labels into a row event.
func (r RowEvents) Labelize(cols []int, labelCol int, labels []string) RowEvents { func (r RowEvents) Labelize(cols []int, labelCol int, labels []string) RowEvents {
out := make(RowEvents, 0, len(r)) out := make(RowEvents, 0, len(r))
for _, re := range r { for _, re := range r {

View File

@ -50,9 +50,8 @@ func scanRefs(evt *tcell.EventKey, a *App, t *Table, gvr string) *tcell.EventKey
if len(refs) == 0 { if len(refs) == 0 {
a.Flash().Warnf("No references found at this time for %s::%s. Check again later!", gvr, path) a.Flash().Warnf("No references found at this time for %s::%s. Check again later!", gvr, path)
return nil return nil
} else {
a.Flash().Infof("Viewing references for %s::%s", gvr, path)
} }
a.Flash().Infof("Viewing references for %s::%s", gvr, path)
view := NewReference(client.NewGVR("references")) view := NewReference(client.NewGVR("references"))
view.SetContextFn(refContext(gvr, path, false)) view.SetContextFn(refContext(gvr, path, false))
if err := a.inject(view); err != nil { if err := a.inject(view); err != nil {

View File

@ -3,12 +3,13 @@ package view
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"github.com/derailed/k9s/internal/config" "github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/model" "github.com/derailed/k9s/internal/model"
"github.com/derailed/k9s/internal/ui" "github.com/derailed/k9s/internal/ui"
"github.com/derailed/tview" "github.com/derailed/tview"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"strings"
) )
// Meow represents a bomb viewer // Meow represents a bomb viewer
@ -50,7 +51,7 @@ func (m *Meow) Init(_ context.Context) error {
m.bindKeys() m.bindKeys()
m.SetInputCapture(m.keyboard) m.SetInputCapture(m.keyboard)
m.talk() m.talk()
return nil return nil
} }

View File

@ -49,9 +49,8 @@ func scanSARefs(evt *tcell.EventKey, a *App, t *Table, gvr string) *tcell.EventK
if len(refs) == 0 { if len(refs) == 0 {
a.Flash().Warnf("No references found at this time for %s::%s. Check again later!", gvr, path) a.Flash().Warnf("No references found at this time for %s::%s. Check again later!", gvr, path)
return nil return nil
} else {
a.Flash().Infof("Viewing references for %s::%s", gvr, path)
} }
a.Flash().Infof("Viewing references for %s::%s", gvr, path)
view := NewReference(client.NewGVR("references")) view := NewReference(client.NewGVR("references"))
view.SetContextFn(refContext(gvr, path, false)) view.SetContextFn(refContext(gvr, path, false))
if err := a.inject(view); err != nil { if err := a.inject(view); err != nil {