From 7cf9fe6c8b6e6d487f99e148b200e1b142b577a3 Mon Sep 17 00:00:00 2001 From: derailed Date: Tue, 25 Feb 2020 23:31:49 -0800 Subject: [PATCH] cleaning up --- internal/client/client.go | 2 +- internal/config/views.go | 6 +++++- internal/dao/dp.go | 2 +- internal/dao/rs.go | 15 +-------------- internal/render/container.go | 2 ++ internal/render/header.go | 2 +- internal/render/row_event.go | 1 + internal/render/svc.go | 1 + internal/render/table_data.go | 1 + internal/ui/app.go | 1 + internal/ui/config.go | 2 +- internal/ui/table.go | 1 + 12 files changed, 17 insertions(+), 19 deletions(-) diff --git a/internal/client/client.go b/internal/client/client.go index 4fd18a79..9dc252c2 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -45,7 +45,7 @@ type APIClient struct { metricsAPI bool } -// NewTestAPIClient for testing ONLY!! +// NewTestClient for testing ONLY!! func NewTestClient() *APIClient { return &APIClient{ config: NewConfig(nil), diff --git a/internal/config/views.go b/internal/config/views.go index 2d32394b..ebbb772e 100644 --- a/internal/config/views.go +++ b/internal/config/views.go @@ -7,6 +7,7 @@ import ( "gopkg.in/yaml.v2" ) +// K9sViewConfigFile represents the location for the views configuration. var K9sViewConfigFile = filepath.Join(K9sHome, "views.yml") // ViewConfigListener represents a view config listener. @@ -15,15 +16,17 @@ type ViewConfigListener interface { ViewSettingsChanged(ViewSetting) } +// ViewSetting represents a view configuration. type ViewSetting struct { Columns []string `yaml:"columns"` } +// ViewSettings represent a collection of view configurations. type ViewSettings struct { - Fuck string `yaml:"fuck"` Views map[string]ViewSetting `yaml:"views"` } +// NewViewSettings returns a new configuration. func NewViewSettings() ViewSettings { return ViewSettings{ Views: make(map[string]ViewSetting), @@ -36,6 +39,7 @@ type CustomView struct { listeners map[string]ViewConfigListener } +// NewCustomView returns a views configuration. func NewCustomView() *CustomView { return &CustomView{ K9s: NewViewSettings(), diff --git a/internal/dao/dp.go b/internal/dao/dp.go index 5bbfed77..9410227b 100644 --- a/internal/dao/dp.go +++ b/internal/dao/dp.go @@ -102,7 +102,7 @@ func (d *Deployment) Pod(fqn string) (string, error) { return podFromSelector(d.Factory, dp.Namespace, dp.Spec.Selector.MatchLabels) } -// GetInstance returns a deployment instance. +// Load returns a deployment instance. func (*Deployment) Load(f Factory, fqn string) (*appsv1.Deployment, error) { o, err := f.Get("apps/v1/deployments", fqn, false, labels.Everything()) if err != nil { diff --git a/internal/dao/rs.go b/internal/dao/rs.go index 4307f591..749e4803 100644 --- a/internal/dao/rs.go +++ b/internal/dao/rs.go @@ -21,20 +21,7 @@ type ReplicaSet struct { Resource } -// BOZO!! -// // IsHappy check for happy deployments. -// func (*ReplicaSet) IsHappy(rs appsv1.ReplicaSet) bool { -// if rs.Status.Replicas == 0 && rs.Status.Replicas != rs.Status.ReadyReplicas { -// return false -// } - -// if rs.Status.Replicas != 0 && rs.Status.Replicas != rs.Status.ReadyReplicas { -// return false -// } - -// return true -// } - +// Load returns a given instance. func (r *ReplicaSet) Load(f Factory, path string) (*v1.ReplicaSet, error) { o, err := f.Get("apps/v1/replicasets", path, true, labels.Everything()) if err != nil { diff --git a/internal/render/container.go b/internal/render/container.go index ca430692..efde7428 100644 --- a/internal/render/container.go +++ b/internal/render/container.go @@ -167,6 +167,7 @@ func gatherMetrics(co *v1.Container, mx *mv1beta1.ContainerMetrics) (c, p, l met return } +// ToContainerPorts returns container ports as a string. func ToContainerPorts(pp []v1.ContainerPort) string { ports := make([]string, len(pp)) for i, p := range pp { @@ -182,6 +183,7 @@ func ToContainerPorts(pp []v1.ContainerPort) string { return strings.Join(ports, ",") } +// ToContainerState returns container state as a string. func ToContainerState(s v1.ContainerState) string { switch { case s.Waiting != nil: diff --git a/internal/render/header.go b/internal/render/header.go index b57bd354..3250459c 100644 --- a/internal/render/header.go +++ b/internal/render/header.go @@ -132,7 +132,7 @@ func (h Header) HasAge() bool { return h.IndexOf(ageCol, true) != -1 } -// AgeCol checks if given column index is the age column. +// IsAgeCol checks if given column index is the age column. func (h Header) IsAgeCol(col int) bool { if !h.HasAge() || col >= len(h) { return false diff --git a/internal/render/row_event.go b/internal/render/row_event.go index 2c7b572a..c0230724 100644 --- a/internal/render/row_event.go +++ b/internal/render/row_event.go @@ -93,6 +93,7 @@ func (r RowEvent) Diff(re RowEvent, ageCol int) bool { // RowEvents a collection of row events. type RowEvents []RowEvent +// Customize returns custom row events based on columns layout. func (r RowEvents) Customize(cols []int) RowEvents { ee := make(RowEvents, 0, len(cols)) for _, re := range r { diff --git a/internal/render/svc.go b/internal/render/svc.go index 71255f2e..5f274e58 100644 --- a/internal/render/svc.go +++ b/internal/render/svc.go @@ -131,6 +131,7 @@ func toIPs(svcType v1.ServiceType, ips []string) string { return strings.Join(ips, ",") } +// ToPorts returns service ports as a string. func ToPorts(pp []v1.ServicePort) string { ports := make([]string, len(pp)) for i, p := range pp { diff --git a/internal/render/table_data.go b/internal/render/table_data.go index beef289e..0657c70f 100644 --- a/internal/render/table_data.go +++ b/internal/render/table_data.go @@ -12,6 +12,7 @@ func NewTableData() *TableData { return &TableData{} } +// Customize returns a new model with customized column layout. func (t *TableData) Customize(cols []string, wide bool) TableData { res := TableData{ Namespace: t.Namespace, diff --git a/internal/ui/app.go b/internal/ui/app.go index 3ef444c8..ee66562a 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -152,6 +152,7 @@ func (a *App) InCmdMode() bool { return a.Cmd().InCmdMode() } +// HasAction checks if key matches a registered binding. func (a *App) HasAction(key tcell.Key) (KeyAction, bool) { act, ok := a.actions[key] return act, ok diff --git a/internal/ui/config.go b/internal/ui/config.go index 1232e862..a448f87d 100644 --- a/internal/ui/config.go +++ b/internal/ui/config.go @@ -65,7 +65,7 @@ func (c *Configurator) CustomViewsWatcher(ctx context.Context, s synchronizer) e return w.Add(config.K9sViewConfigFile) } -// RefreshCustomView load view configuration changes. +// RefreshCustomViews load view configuration changes. func (c *Configurator) RefreshCustomViews() { if c.CustomView == nil { c.CustomView = config.NewCustomView() diff --git a/internal/ui/table.go b/internal/ui/table.go index 13e88b7a..bcb59347 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -128,6 +128,7 @@ func (t *Table) Styles() *config.Styles { return t.styles } +// FilterInput filters user commands. func (t *Table) FilterInput(r rune) bool { if !t.cmdBuff.IsActive() { return false