diff --git a/go.mod b/go.mod index 25af63b4..4daf737e 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/alexellis/go-execute v0.0.0-20200124154445-8697e4e28c5e // indirect github.com/alexellis/hmac v0.0.0-20180624211220-5c52ab81c0de // indirect github.com/atotto/clipboard v0.1.2 - github.com/derailed/tview v0.3.5 + github.com/derailed/tview v0.3.6 github.com/drone/envsubst v1.0.2 // indirect github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f // indirect github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f // indirect diff --git a/go.sum b/go.sum index 0980b97e..ad8eaeee 100644 --- a/go.sum +++ b/go.sum @@ -157,6 +157,8 @@ github.com/derailed/tview v0.3.4 h1:PnF64fLqm48LEjC/XwOS7JufDgFuuPYx85YVt5t3rwE= github.com/derailed/tview v0.3.4/go.mod h1:yApPszFU62FoaGkf7swy2nIdV/h7Nid3dhMSVy6+OFI= github.com/derailed/tview v0.3.5 h1:1vKqcJIiZtLAs5moX9c38+BbBSYhPgFq0ZndnVNVNFc= github.com/derailed/tview v0.3.5/go.mod h1:yApPszFU62FoaGkf7swy2nIdV/h7Nid3dhMSVy6+OFI= +github.com/derailed/tview v0.3.6 h1:9PyX6Nu1vs9mCVfvV2q2fwT/dZta0dBGr4ZPjCF1KnU= +github.com/derailed/tview v0.3.6/go.mod h1:GJ3k/TIzEE+sj1L09/usk6HrkjsdadSsb03eHgPbcII= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= diff --git a/internal/client/metrics.go b/internal/client/metrics.go index 25b137f9..7f02787e 100644 --- a/internal/client/metrics.go +++ b/internal/client/metrics.go @@ -16,8 +16,10 @@ const ( mxCacheExpiry = 1 * time.Minute ) +// MetricsDial tracks global metric server handle. var MetricsDial *MetricsServer +// DialMetrics dials the metrics server. func DialMetrics(c Connection) *MetricsServer { if MetricsDial == nil { MetricsDial = NewMetricsServer(c) @@ -26,6 +28,7 @@ func DialMetrics(c Connection) *MetricsServer { return MetricsDial } +// ResetMetrics resets the metric server handle. func ResetMetrics() { MetricsDial = nil } diff --git a/internal/config/styles.go b/internal/config/styles.go index e14ecdf4..cc56482f 100644 --- a/internal/config/styles.go +++ b/internal/config/styles.go @@ -105,7 +105,7 @@ type ( FgColor Color `yaml:"fgColor"` } - // ColorBorder tracks border styles. + // Border tracks border styles. Border struct { FgColor Color `yaml:"fgColor"` FocusColor Color `yaml:"focusColor"` @@ -179,7 +179,7 @@ func (c Color) String() string { return string(c) } -// AsColor returns a view color. +// Color returns a view color. func (c Color) Color() tcell.Color { if c == DefaultColor { return tcell.ColorDefault @@ -190,7 +190,7 @@ func (c Color) Color() tcell.Color { return tcell.GetColor(c.String()) } -// AsColors converts series string colors to colors. +// Colors converts series string colors to colors. func (c Colors) Colors() []tcell.Color { cc := make([]tcell.Color, 0, len(c)) for _, color := range c { diff --git a/internal/dao/pulse.go b/internal/dao/pulse.go index 6b323021..4c93ad38 100644 --- a/internal/dao/pulse.go +++ b/internal/dao/pulse.go @@ -7,10 +7,12 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) +// Pulse tracks pulses. type Pulse struct { NonResource } +// List lists out pulses. func (h *Pulse) List(ctx context.Context, ns string) ([]runtime.Object, error) { return nil, fmt.Errorf("NYI") } diff --git a/internal/model/flash.go b/internal/model/flash.go index 284985b8..d7fe8300 100644 --- a/internal/model/flash.go +++ b/internal/model/flash.go @@ -20,6 +20,7 @@ const ( FlashErr ) +// LevelMessage tracks an message and severity. type LevelMessage struct { Level FlashLevel Text string @@ -29,6 +30,7 @@ func newClearMessage() LevelMessage { return LevelMessage{} } +// IsClear returns true if message is empty. func (l LevelMessage) IsClear() bool { return l.Text == "" } @@ -56,6 +58,7 @@ type Flash struct { msgChan chan LevelMessage } +// NewFlash returns a new instance. func NewFlash(dur time.Duration) *Flash { return &Flash{ delay: dur, diff --git a/internal/model/pulse.go b/internal/model/pulse.go index 9db88a0b..d26ecc83 100644 --- a/internal/model/pulse.go +++ b/internal/model/pulse.go @@ -35,6 +35,7 @@ type Pulse struct { data health.Checks } +// NewPulse returns a new pulse. func NewPulse(gvr string) *Pulse { return &Pulse{ gvr: gvr, @@ -42,6 +43,7 @@ func NewPulse(gvr string) *Pulse { } } +// Watch monitors pulses. func (p *Pulse) Watch(ctx context.Context) { p.Refresh(ctx) go p.updater(ctx) diff --git a/internal/model/pulse_health.go b/internal/model/pulse_health.go index 12de902d..d0a1c5c0 100644 --- a/internal/model/pulse_health.go +++ b/internal/model/pulse_health.go @@ -14,16 +14,19 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) +// PulseHealth tracks resources health. type PulseHealth struct { factory dao.Factory } +// NewPulseHealth returns a new instance. func NewPulseHealth(f dao.Factory) *PulseHealth { return &PulseHealth{ factory: f, } } +// List returns a canned collection of resources health. func (h *PulseHealth) List(ctx context.Context, ns string) ([]runtime.Object, error) { defer func(t time.Time) { log.Debug().Msgf("PulseHealthCheck %v", time.Since(t)) diff --git a/internal/render/ofaas.go b/internal/render/ofaas.go index 4d285197..1edb3439 100644 --- a/internal/render/ofaas.go +++ b/internal/render/ofaas.go @@ -55,8 +55,8 @@ func (OpenFaas) Header(ns string) HeaderRow { } // Render renders a chart to screen. -func (f OpenFaas) Render(o interface{}, ns string, r *Row) error { - fn, ok := o.(OpenFaasRes) +func (o OpenFaas) Render(i interface{}, ns string, r *Row) error { + fn, ok := i.(OpenFaasRes) if !ok { return fmt.Errorf("expected OpenFaasRes, but got %T", o) } @@ -71,7 +71,7 @@ func (f OpenFaas) Render(o interface{}, ns string, r *Row) error { } r.ID = client.FQN(fn.Function.Namespace, fn.Function.Name) - r.Fields = make(Fields, 0, len(f.Header(ns))) + r.Fields = make(Fields, 0, len(o.Header(ns))) if client.IsAllNamespaces(ns) { r.Fields = append(r.Fields, fn.Function.Namespace) } @@ -83,7 +83,7 @@ func (f OpenFaas) Render(o interface{}, ns string, r *Row) error { strconv.Itoa(int(fn.Function.InvocationCount)), strconv.Itoa(int(fn.Function.Replicas)), strconv.Itoa(int(fn.Function.AvailableReplicas)), - asStatus(f.diagnose(status)), + asStatus(o.diagnose(status)), toAge(metav1.Time{Time: time.Now()}), ) diff --git a/internal/render/rs.go b/internal/render/rs.go index f0412d56..63f4885b 100644 --- a/internal/render/rs.go +++ b/internal/render/rs.go @@ -50,7 +50,7 @@ func (ReplicaSet) Header(ns string) HeaderRow { } // Render renders a K8s resource to screen. -func (s ReplicaSet) Render(o interface{}, ns string, r *Row) error { +func (r ReplicaSet) Render(o interface{}, ns string, row *Row) error { raw, ok := o.(*unstructured.Unstructured) if !ok { return fmt.Errorf("Expected ReplicaSet, but got %T", o) @@ -61,18 +61,18 @@ func (s ReplicaSet) Render(o interface{}, ns string, r *Row) error { return err } - r.ID = client.MetaFQN(rs.ObjectMeta) - r.Fields = make(Fields, 0, len(s.Header(ns))) + row.ID = client.MetaFQN(rs.ObjectMeta) + row.Fields = make(Fields, 0, len(r.Header(ns))) if client.IsAllNamespaces(ns) { - r.Fields = append(r.Fields, rs.Namespace) + row.Fields = append(row.Fields, rs.Namespace) } - r.Fields = append(r.Fields, + row.Fields = append(row.Fields, rs.Name, strconv.Itoa(int(*rs.Spec.Replicas)), strconv.Itoa(int(rs.Status.Replicas)), strconv.Itoa(int(rs.Status.ReadyReplicas)), mapToStr(rs.Labels), - asStatus(s.diagnose(rs)), + asStatus(r.diagnose(rs)), toAge(rs.ObjectMeta.CreationTimestamp), ) diff --git a/internal/tchart/dot_matrix.go b/internal/tchart/dot_matrix.go index 8115a314..6eaf596a 100644 --- a/internal/tchart/dot_matrix.go +++ b/internal/tchart/dot_matrix.go @@ -4,23 +4,26 @@ import ( "fmt" ) -// var dots = []rune{' ', '⠂', '⠶', '⠿'} var dots = []rune{' ', '⠂', '▤', '▥'} -// var dots = []rune{' ', '⠂', '▤', '▇'} - +// Segment represents a dial segment. type Segment []int +// Segments represents a collection of segments. type Segments []Segment +// Matrics represents a number dial. type Matrix [][]rune +// Orientation tracks char orientations. type Orientation int +// DotMatrix tracks a char matrix. type DotMatrix struct { row, col int } +// NewDotMatrix returns a new matrix. func NewDotMatrix(row, col int) DotMatrix { return DotMatrix{ row: row, @@ -28,6 +31,7 @@ func NewDotMatrix(row, col int) DotMatrix { } } +// Print prints the matrix. func (d DotMatrix) Print(n int) Matrix { m := make(Matrix, d.row) segs := asSegments(n) @@ -67,6 +71,7 @@ func asSegments(n int) Segment { } } +// CharFor return a char based on row/col. func (s Segment) CharFor(row, col int) rune { c := ' ' segs := ToSegments(row, col) @@ -101,6 +106,7 @@ var segs = map[int][][]int{ 4: [][]int{[]int{4, 6}, []int{6}, []int{5, 6}}, } +// ToSegments return path segments. func ToSegments(row, col int) []int { return segs[row][col] } diff --git a/internal/tchart/gauge.go b/internal/tchart/gauge.go index b40fa546..f019b4d2 100644 --- a/internal/tchart/gauge.go +++ b/internal/tchart/gauge.go @@ -9,8 +9,13 @@ import ( ) const ( + // DeltaSame represents no difference. DeltaSame delta = iota + + // DeltaMore represents a higher value. DeltaMore + + // DeltaLess represents a lower value. DeltaLess gaugeFmt = "0%dd" @@ -38,6 +43,7 @@ func (g *Gauge) IsDial() bool { return true } +// Add adds a new metric. func (g *Gauge) Add(m Metric) { g.mx.Lock() defer g.mx.Unlock() @@ -73,6 +79,7 @@ func (g *Gauge) drawNum(sc tcell.Screen, ok bool, o image.Point, n int, dn delta } } +// Draw draws the primitive. func (g *Gauge) Draw(sc tcell.Screen) { g.Component.Draw(sc) diff --git a/internal/ui/flash.go b/internal/ui/flash.go index 5faa123d..d401fe7e 100644 --- a/internal/ui/flash.go +++ b/internal/ui/flash.go @@ -49,6 +49,7 @@ func (f *Flash) StylesChanged(s *config.Styles) { f.SetTextColor(s.FgColor()) } +// Watch watches for flash changes. func (f *Flash) Watch(ctx context.Context, c model.FlashChan) { defer log.Debug().Msgf("Flash Canceled!") for { diff --git a/internal/view/alias.go b/internal/view/alias.go index 430c9635..ac582262 100644 --- a/internal/view/alias.go +++ b/internal/view/alias.go @@ -32,6 +32,7 @@ func NewAlias(gvr client.GVR) ResourceViewer { return &a } +// Init initialiazes the view. func (a *Alias) Init(ctx context.Context) error { if err := a.ResourceViewer.Init(ctx); err != nil { return err diff --git a/internal/view/app.go b/internal/view/app.go index 8a68ffb0..55e0fb01 100644 --- a/internal/view/app.go +++ b/internal/view/app.go @@ -18,7 +18,7 @@ import ( "github.com/rs/zerolog/log" ) -// // ExitStatus indicates UI exit conditions. +// ExitStatus indicates UI exit conditions. var ExitStatus = "" const ( diff --git a/internal/view/pulse.go b/internal/view/pulse.go index 92314ffb..b936f42b 100644 --- a/internal/view/pulse.go +++ b/internal/view/pulse.go @@ -157,7 +157,7 @@ func (p *Pulse) PulseChanged(c *health.Check) { v.Add(tchart.Metric{OK: c.Tally(health.OK), Fault: c.Tally(health.Toast)}) } -// PulseLoadFailed notifies the load failed. +// PulseFailed notifies the load failed. func (p *Pulse) PulseFailed(err error) { p.app.Flash().Err(err) }