cleaning up
parent
26a4100ecf
commit
3cfc4e860c
|
|
@ -72,6 +72,7 @@ func InitConnection(config *Config) (*APIClient, error) {
|
|||
return &a, err
|
||||
}
|
||||
|
||||
// ConnectionOK returns connection status.
|
||||
func (a *APIClient) ConnectionOK() bool {
|
||||
return a.connOK
|
||||
}
|
||||
|
|
@ -304,7 +305,7 @@ func (a *APIClient) Dial() (kubernetes.Interface, error) {
|
|||
return a.client, nil
|
||||
}
|
||||
|
||||
// RestConfigOrDie returns a rest api client.
|
||||
// RestConfig returns a rest api client.
|
||||
func (a *APIClient) RestConfig() (*restclient.Config, error) {
|
||||
cfg, err := a.config.RESTConfig()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ func (c *Config) ActiveNamespace() string {
|
|||
return "default"
|
||||
}
|
||||
|
||||
// ValidateFavorites ensure favorite ns are legit.
|
||||
func (c *Config) ValidateFavorites() {
|
||||
cl := c.K9s.ActiveCluster()
|
||||
if cl == nil {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ type FeatureGates struct {
|
|||
NodeShell bool `yaml:"nodeShell"`
|
||||
}
|
||||
|
||||
// NewFeatureGate returns a new feature gate.
|
||||
// NewFeatureGates returns a new feature gate.
|
||||
func NewFeatureGates() *FeatureGates {
|
||||
return &FeatureGates{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
defer func(t time.Time) {
|
||||
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
|
||||
}
|
||||
|
||||
// ScanForSARefs scans cluster resources for serviceaccount refs.
|
||||
func ScanForSARefs(ctx context.Context, f Factory) (Refs, error) {
|
||||
defer func(t time.Time) {
|
||||
log.Debug().Msgf("Cluster Scan %v", time.Since(t))
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ func (c *CronJob) Run(path string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// ScanSA scans for serviceaccount refs.
|
||||
func (c *CronJob) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
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
|
||||
}
|
||||
|
||||
// Scan scans for cluster resource refs.
|
||||
func (c *CronJob) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
oo, err := c.Factory.List(c.GVR(), ns, wait, labels.Everything())
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ func (*Deployment) Load(f Factory, fqn string) (*appsv1.Deployment, error) {
|
|||
return &dp, nil
|
||||
}
|
||||
|
||||
// ScanSA scans for serviceaccount refs.
|
||||
func (d *Deployment) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
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
|
||||
}
|
||||
|
||||
// Scan scans for resource references.
|
||||
func (d *Deployment) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything())
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@ func (d *DaemonSet) GetInstance(fqn string) (*appsv1.DaemonSet, error) {
|
|||
return &ds, nil
|
||||
}
|
||||
|
||||
// ScanSA scans for serviceaccount refs.
|
||||
func (d *DaemonSet) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
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
|
||||
}
|
||||
|
||||
// Scan scans for cluster refs.
|
||||
func (d *DaemonSet) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything())
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
// ScanSA scans for serviceaccount refs.
|
||||
func (j *Job) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
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
|
||||
}
|
||||
|
||||
// Scan scans for resource references.
|
||||
func (j *Job) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
oo, err := j.Factory.List(j.GVR(), ns, wait, labels.Everything())
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@ func (p *Pod) TailLogs(ctx context.Context, c LogChan, opts LogOptions) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ScanSA scans for serviceaccount refs.
|
||||
func (p *Pod) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
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
|
||||
}
|
||||
|
||||
// Scan scans for cluster resource refs.
|
||||
func (p *Pod) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
oo, err := p.Factory.List(p.GVR(), ns, wait, labels.Everything())
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
var (
|
||||
_ Accessor = (*Reference)(nil)
|
||||
)
|
||||
var _ Accessor = (*Reference)(nil)
|
||||
|
||||
// Reference represents cluster resource references.
|
||||
type Reference struct {
|
||||
NonResource
|
||||
}
|
||||
|
||||
// List collects all references.
|
||||
func (r *Reference) List(ctx context.Context, ns string) ([]runtime.Object, error) {
|
||||
gvr, ok := ctx.Value(internal.KeyGVR).(string)
|
||||
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) {
|
||||
panic("NYI")
|
||||
}
|
||||
|
||||
// Scan scan cluster resources for references.
|
||||
func (r *Reference) Scan(ctx context.Context) ([]runtime.Object, error) {
|
||||
refs, err := ScanForRefs(ctx, r.Factory)
|
||||
if err != nil {
|
||||
|
|
@ -59,6 +61,7 @@ func (r *Reference) Scan(ctx context.Context) ([]runtime.Object, error) {
|
|||
return oo, nil
|
||||
}
|
||||
|
||||
// ScanSA scans for serviceaccount refs.
|
||||
func (r *Reference) ScanSA(ctx context.Context) ([]runtime.Object, error) {
|
||||
refs, err := ScanForSARefs(ctx, r.Factory)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ func (s *StatefulSet) getStatefulSet(fqn string) (*appsv1.StatefulSet, error) {
|
|||
return &sts, nil
|
||||
}
|
||||
|
||||
// ScanSA scans for serviceaccount refs.
|
||||
func (s *StatefulSet) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
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
|
||||
}
|
||||
|
||||
// Scan scans for cluster resource refs.
|
||||
func (s *StatefulSet) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
|
||||
ns, n := client.Namespaced(fqn)
|
||||
oo, err := s.Factory.List(s.GVR(), ns, wait, labels.Everything())
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
hh, _ := sortLabels(labelize(r.Row.Fields[labelCol]))
|
||||
return hh
|
||||
|
|
@ -105,6 +106,7 @@ func (r RowEvent) Diff(re RowEvent, ageCol int) bool {
|
|||
// RowEvents a collection of row events.
|
||||
type RowEvents []RowEvent
|
||||
|
||||
// ExtractHeaderLabels extract header labels.
|
||||
func (r RowEvents) ExtractHeaderLabels(labelCol int) []string {
|
||||
ll := make([]string, 0, 10)
|
||||
for _, re := range r {
|
||||
|
|
@ -114,6 +116,7 @@ func (r RowEvents) ExtractHeaderLabels(labelCol int) []string {
|
|||
return ll
|
||||
}
|
||||
|
||||
// Labelize converts labels into a row event.
|
||||
func (r RowEvents) Labelize(cols []int, labelCol int, labels []string) RowEvents {
|
||||
out := make(RowEvents, 0, len(r))
|
||||
for _, re := range r {
|
||||
|
|
|
|||
|
|
@ -50,9 +50,8 @@ func scanRefs(evt *tcell.EventKey, a *App, t *Table, gvr string) *tcell.EventKey
|
|||
if len(refs) == 0 {
|
||||
a.Flash().Warnf("No references found at this time for %s::%s. Check again later!", gvr, path)
|
||||
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.SetContextFn(refContext(gvr, path, false))
|
||||
if err := a.inject(view); err != nil {
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@ package view
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/derailed/k9s/internal/config"
|
||||
"github.com/derailed/k9s/internal/model"
|
||||
"github.com/derailed/k9s/internal/ui"
|
||||
"github.com/derailed/tview"
|
||||
"github.com/gdamore/tcell"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Meow represents a bomb viewer
|
||||
|
|
|
|||
|
|
@ -49,9 +49,8 @@ func scanSARefs(evt *tcell.EventKey, a *App, t *Table, gvr string) *tcell.EventK
|
|||
if len(refs) == 0 {
|
||||
a.Flash().Warnf("No references found at this time for %s::%s. Check again later!", gvr, path)
|
||||
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.SetContextFn(refContext(gvr, path, false))
|
||||
if err := a.inject(view); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue