checkpoint

mine
derailed 2020-07-18 09:27:41 -06:00
parent 35f67d8e4f
commit 671c819502
11 changed files with 77 additions and 32 deletions

View File

@ -1,5 +1,5 @@
# Build... # Build...
FROM golang:1.14.1-alpine3.11 AS build FROM golang:1.14.4-alpine3.11 AS build
WORKDIR /k9s WORKDIR /k9s
COPY go.mod go.sum main.go Makefile ./ COPY go.mod go.sum main.go Makefile ./

View File

@ -3,7 +3,7 @@ PACKAGE := github.com/derailed/$(NAME)
GIT := $(shell git rev-parse --short HEAD) GIT := $(shell git rev-parse --short HEAD)
SOURCE_DATE_EPOCH ?= $(shell date +%s) SOURCE_DATE_EPOCH ?= $(shell date +%s)
DATE := $(shell date -u -d @${SOURCE_DATE_EPOCH} +%FT%T%Z) DATE := $(shell date -u -d @${SOURCE_DATE_EPOCH} +%FT%T%Z)
VERSION ?= v0.20.3 VERSION ?= v0.21.2
IMG_NAME := derailed/k9s IMG_NAME := derailed/k9s
IMAGE := ${IMG_NAME}:${VERSION} IMAGE := ${IMG_NAME}:${VERSION}

2
go.mod
View File

@ -2,6 +2,8 @@ module github.com/derailed/k9s
go 1.14 go 1.14
replace github.com/derailed/tview => /Users/fernand/go_wk/derailed/src/github.com/derailed/tview
require ( require (
9fans.net/go v0.0.2 9fans.net/go v0.0.2
github.com/atotto/clipboard v0.1.2 github.com/atotto/clipboard v0.1.2

View File

@ -356,7 +356,7 @@ func readLogs(stream io.ReadCloser, c LogChan, opts LogOptions) {
return return
} }
log.Warn().Err(err).Msgf("Stream READ error %s", opts.Info()) log.Warn().Err(err).Msgf("Stream READ error %s", opts.Info())
c <- opts.DecorateLog([]byte("log stream failed\n")) c <- opts.DecorateLog([]byte(fmt.Sprintf("log stream failed: %#v\n", err)))
return return
} }
c <- opts.DecorateLog(bytes) c <- opts.DecorateLog(bytes)

View File

@ -1,6 +1,8 @@
package ui package ui
import ( import (
"sync"
"github.com/derailed/k9s/internal/client" "github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/config" "github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/model" "github.com/derailed/k9s/internal/model"
@ -19,6 +21,8 @@ type App struct {
actions KeyActions actions KeyActions
views map[string]tview.Primitive views map[string]tview.Primitive
cmdModel *model.FishBuff cmdModel *model.FishBuff
running bool
mx sync.RWMutex
} }
// NewApp returns a new app. // NewApp returns a new app.
@ -53,6 +57,18 @@ func (a *App) Init() {
a.SetRoot(a.Main, true) a.SetRoot(a.Main, true)
} }
func (a *App) IsRunning() bool {
a.mx.RLock()
defer a.mx.RUnlock()
return a.running
}
func (a *App) SetRunning(f bool) {
a.mx.Lock()
defer a.mx.Unlock()
a.running = f
}
// BufferChanged indicates the buffer was changed. // BufferChanged indicates the buffer was changed.
func (a *App) BufferChanged(s string) {} func (a *App) BufferChanged(s string) {}
@ -69,7 +85,8 @@ func (a *App) BufferActive(state bool, kind model.BufferKind) {
flex.RemoveItemAtIndex(1) flex.RemoveItemAtIndex(1)
a.SetFocus(flex) a.SetFocus(flex)
} }
a.Draw() // BOZO!!
//a.Draw()
} }
// SuggestionChanged notifies of update to command suggestions. // SuggestionChanged notifies of update to command suggestions.

View File

@ -65,6 +65,9 @@ func (f *Flash) Watch(ctx context.Context, c model.FlashChan) {
// SetMessage sets flash message and level. // SetMessage sets flash message and level.
func (f *Flash) SetMessage(m model.LevelMessage) { func (f *Flash) SetMessage(m model.LevelMessage) {
if !f.app.IsRunning() {
return
}
fn := func() { fn := func() {
if m.Text == "" { if m.Text == "" {
f.Clear() f.Clear()
@ -76,9 +79,11 @@ func (f *Flash) SetMessage(m model.LevelMessage) {
if f.testMode { if f.testMode {
fn() fn()
} else {
f.app.QueueUpdateDraw(fn)
} }
// BOZO!!
//} else {
// f.app.QueueUpdate(fn)
//}
} }
func (f *Flash) flashEmoji(l model.FlashLevel) string { func (f *Flash) flashEmoji(l model.FlashLevel) string {

View File

@ -64,6 +64,9 @@ func (s *StatusIndicator) ClusterInfoUpdated(data model.ClusterMeta) {
// ClusterInfoChanged notifies the cluster meta was changed. // ClusterInfoChanged notifies the cluster meta was changed.
func (s *StatusIndicator) ClusterInfoChanged(prev, cur model.ClusterMeta) { func (s *StatusIndicator) ClusterInfoChanged(prev, cur model.ClusterMeta) {
if !s.app.IsRunning() {
return
}
s.app.QueueUpdateDraw(func() { s.app.QueueUpdateDraw(func() {
s.SetPermanent(fmt.Sprintf( s.SetPermanent(fmt.Sprintf(
statusIndicatorFmt, statusIndicatorFmt,

View File

@ -421,6 +421,7 @@ func (a *App) Run() error {
if err := a.command.defaultCmd(); err != nil { if err := a.command.defaultCmd(); err != nil {
return err return err
} }
a.SetRunning(true)
if err := a.Application.Run(); err != nil { if err := a.Application.Run(); err != nil {
return err return err
} }
@ -446,12 +447,13 @@ func (a *App) IsBenchmarking() bool {
// ClearStatus reset logo back to normal. // ClearStatus reset logo back to normal.
func (a *App) ClearStatus(flash bool) { func (a *App) ClearStatus(flash bool) {
a.QueueUpdateDraw(func() { // BOZO!!
a.Logo().Reset() //a.QueueUpdate(func() {
if flash { a.Logo().Reset()
a.Flash().Clear() if flash {
} a.Flash().Clear()
}) }
//})
} }
func (a *App) setLogo(l model.FlashLevel, msg string) { func (a *App) setLogo(l model.FlashLevel, msg string) {

View File

@ -57,7 +57,9 @@ func (b *Browser) Init(ctx context.Context) error {
return e return e
} }
} }
b.app.CmdBuff().Reset() if b.App().IsRunning() {
b.app.CmdBuff().Reset()
}
b.bindKeys() b.bindKeys()
if b.bindKeysFn != nil { if b.bindKeysFn != nil {
@ -200,14 +202,16 @@ func (b *Browser) Aliases() []string {
// TableDataChanged notifies view new data is available. // TableDataChanged notifies view new data is available.
func (b *Browser) TableDataChanged(data render.TableData) { func (b *Browser) TableDataChanged(data render.TableData) {
if !b.app.ConOK() || b.cancelFn == nil { if !b.app.ConOK() || b.cancelFn == nil || !b.app.IsRunning() {
return return
} }
b.app.QueueUpdateDraw(func() { //BOZO!!
b.app.QueueUpdate(func() {
b.refreshActions() b.refreshActions()
b.Update(data) b.Update(data)
}) })
//b.app.Draw()
} }
// TableLoadFailed notifies view something went south. // TableLoadFailed notifies view something went south.

View File

@ -85,21 +85,25 @@ func (c *ClusterInfo) ClusterInfoUpdated(data model.ClusterMeta) {
// ClusterInfoChanged notifies the cluster meta was changed. // ClusterInfoChanged notifies the cluster meta was changed.
func (c *ClusterInfo) ClusterInfoChanged(prev, curr model.ClusterMeta) { func (c *ClusterInfo) ClusterInfoChanged(prev, curr model.ClusterMeta) {
c.app.QueueUpdate(func() { if !c.app.IsRunning() {
c.Clear() return
c.layout() }
row := c.setCell(0, curr.Context) // BOZO!!
row = c.setCell(row, curr.Cluster) //c.app.QueueUpdate(func() {
row = c.setCell(row, curr.User) c.Clear()
row = c.setCell(row, fmt.Sprintf("%s [%d]", curr.K9sVer, os.Getpid())) c.layout()
row = c.setCell(row, curr.K8sVer) row := c.setCell(0, curr.Context)
if c.app.Conn().HasMetrics() { row = c.setCell(row, curr.Cluster)
row = c.setCell(row, ui.AsPercDelta(prev.Cpu, curr.Cpu)) row = c.setCell(row, curr.User)
_ = c.setCell(row, ui.AsPercDelta(prev.Mem, curr.Mem)) row = c.setCell(row, fmt.Sprintf("%s [%d]", curr.K9sVer, os.Getpid()))
c.setDefCon(curr.Cpu, curr.Mem) row = c.setCell(row, curr.K8sVer)
} if c.app.Conn().HasMetrics() {
c.updateStyle() row = c.setCell(row, ui.AsPercDelta(prev.Cpu, curr.Cpu))
}) _ = c.setCell(row, ui.AsPercDelta(prev.Mem, curr.Mem))
c.setDefCon(curr.Cpu, curr.Mem)
}
c.updateStyle()
//})
} }
const defconFmt = "%s %s level!" const defconFmt = "%s %s level!"

View File

@ -116,13 +116,15 @@ func (l *Log) LogFailed(err error) {
if l.logs.GetText(true) == logMessage { if l.logs.GetText(true) == logMessage {
l.logs.Clear() l.logs.Clear()
} }
fmt.Fprintln(l.ansiWriter, tview.Escape(color.Colorize(err.Error(), color.Red))) if _, err = l.ansiWriter.Write([]byte(tview.Escape(color.Colorize(err.Error(), color.Red)))); err != nil {
log.Error().Err(err).Msgf("Writing log error")
}
}) })
} }
// LogChanged updates the logs. // LogChanged updates the logs.
func (l *Log) LogChanged(lines dao.LogItems) { func (l *Log) LogChanged(lines dao.LogItems) {
l.app.QueueUpdateDraw(func() { l.app.QueueUpdate(func() {
l.Flush(lines) l.Flush(lines)
}) })
} }
@ -247,13 +249,19 @@ var EOL = []byte{'\n'}
// Flush write logs to viewer. // Flush write logs to viewer.
func (l *Log) Flush(lines dao.LogItems) { func (l *Log) Flush(lines dao.LogItems) {
log.Debug().Msgf("Flush %d", len(lines))
ll := make([][]byte, len(lines)) ll := make([][]byte, len(lines))
log.Debug().Msgf("A")
lines.Render(l.Indicator().showTime, ll) lines.Render(l.Indicator().showTime, ll)
log.Debug().Msgf("A")
_, _ = l.ansiWriter.Write(EOL) _, _ = l.ansiWriter.Write(EOL)
log.Debug().Msgf("A")
if _, err := l.ansiWriter.Write(bytes.Join(ll, EOL)); err != nil { if _, err := l.ansiWriter.Write(bytes.Join(ll, EOL)); err != nil {
log.Error().Err(err).Msgf("write logs failed") log.Error().Err(err).Msgf("write logs failed")
} }
log.Debug().Msgf("A")
l.logs.ScrollToEnd() l.logs.ScrollToEnd()
log.Debug().Msgf("A")
l.indicator.Refresh() l.indicator.Refresh()
} }