Hoping resolved on cmd lock out issue + bugs

mine
derailed 2019-02-28 22:47:45 -07:00
parent 4aef2896f2
commit 66bdef9e3f
15 changed files with 104 additions and 53 deletions

View File

@ -1,44 +1,42 @@
project_name: k9s project_name: k9s
before: before:
hooks: hooks:
# you may remove this if you don't use vgo
- go mod download - go mod download
# you may remove this if you don't need go generate
- go generate ./... - go generate ./...
release: release:
prerelease: true prerelease: true
builds: builds:
- env: - env:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux - linux
- darwin - darwin
- windows - windows
goarch: goarch:
- 386 - 386
- amd64 - amd64
ldflags: ldflags:
- -s -w -X github.com/derailed/k9s/internal/cmd.version={{.Version}} -X github.com/derailed/k9s/internal/cmd.commit={{.Commit}} -X github.com/derailed/k9s/internal/cmd.date={{.Date}} - -s -w -X github.com/derailed/k9s/internal/cmd.version={{.Version}} -X github.com/derailed/k9s/internal/cmd.commit={{.Commit}} -X github.com/derailed/k9s/internal/cmd.date={{.Date}}
archive: archive:
replacements: replacements:
darwin: Darwin darwin: Darwin
linux: Linux linux: Linux
windows: Windows windows: Windows
386: i386 386: i386
amd64: x86_64 amd64: x86_64
checksum: checksum:
name_template: 'checksums.txt' name_template: "checksums.txt"
snapshot: snapshot:
name_template: "{{ .Tag }}-next" name_template: "{{ .Tag }}-next"
changelog: changelog:
sort: asc sort: asc
filters: filters:
exclude: exclude:
- '^docs:' - "^docs:"
- '^test:' - "^test:"
# Homebrew # Homebrew
brew: brew:
@ -53,4 +51,4 @@ brew:
homepage: https://k9ss.io homepage: https://k9ss.io
description: Kubernetes CLI To Manage Your Clusters In Style! description: Kubernetes CLI To Manage Your Clusters In Style!
test: | test: |
system "k9s version" system "k9s version"

View File

@ -1,7 +1,7 @@
language: go language: go
go_import_path: github.com/derailed/k9s go_import_path: github.com/derailed/k9s
go: go:
- 1.11.5 - "1.12"
# - master # - master
os: os:
@ -18,4 +18,4 @@ env:
script: script:
- go build - go build
- go test ./... - go test ./...

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/derailed/k9s
require ( require (
contrib.go.opencensus.io/exporter/ocagent v0.4.3 // indirect contrib.go.opencensus.io/exporter/ocagent v0.4.3 // indirect
github.com/Azure/go-autorest v11.4.0+incompatible // indirect github.com/Azure/go-autorest v11.4.0+incompatible // indirect
github.com/derailed/tview v0.1.1 github.com/derailed/tview v0.1.2
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/evanphx/json-patch v4.1.0+incompatible // indirect github.com/evanphx/json-patch v4.1.0+incompatible // indirect
github.com/fatih/camelcase v1.0.0 // indirect github.com/fatih/camelcase v1.0.0 // indirect

2
go.sum
View File

@ -15,6 +15,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/derailed/tview v0.1.1 h1:s9rGoufUkZYsIFCfV3M23yHxTKa7Rt6n+QFaOgnirpk= github.com/derailed/tview v0.1.1 h1:s9rGoufUkZYsIFCfV3M23yHxTKa7Rt6n+QFaOgnirpk=
github.com/derailed/tview v0.1.1/go.mod h1:WRYVfgb2PBMLZ/muaSpOc/4H4fYsOPnHOaGnBoJ+hGE= github.com/derailed/tview v0.1.1/go.mod h1:WRYVfgb2PBMLZ/muaSpOc/4H4fYsOPnHOaGnBoJ+hGE=
github.com/derailed/tview v0.1.2 h1:T/XDdjvWrSdhi68bKE0O87O7oHD/JxmfU4IQ13y4fmc=
github.com/derailed/tview v0.1.2/go.mod h1:WRYVfgb2PBMLZ/muaSpOc/4H4fYsOPnHOaGnBoJ+hGE=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= 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/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/evanphx/json-patch v4.1.0+incompatible h1:K1MDoo4AZ4wU0GIU/fPmtZg7VpzLjCxu+UwBD1FvwOc= github.com/evanphx/json-patch v4.1.0+incompatible h1:K1MDoo4AZ4wU0GIU/fPmtZg7VpzLjCxu+UwBD1FvwOc=

View File

@ -2,6 +2,7 @@ package cmd
import ( import (
"fmt" "fmt"
"runtime/debug"
"github.com/derailed/k9s/internal/config" "github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
@ -126,14 +127,22 @@ func run(cmd *cobra.Command, args []string) {
level = log.DebugLevel level = log.DebugLevel
} }
log.SetLevel(level) log.SetLevel(level)
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, ForceColors: true})
initK9s() initK9s()
app := views.NewApp() app := views.NewApp()
{ {
app.Init(version, refreshRate, k8sFlags) app.Init(version, refreshRate, k8sFlags)
defer func() {
if err := recover(); err != nil {
app.Stop()
fmt.Println(err)
debug.PrintStack()
}
}()
app.Run() app.Run()
} }
} }
func initK8sFlags() { func initK8sFlags() {

View File

@ -68,8 +68,13 @@ func (*Custom) NewInstance(i interface{}) Columnar {
log.Error(err) log.Error(err)
} }
meta := obj["metadata"].(map[string]interface{}) meta := obj["metadata"].(map[string]interface{})
cr.path = path.Join(meta["namespace"].(string), meta["name"].(string)) ns := ""
cr.group, cr.version, cr.name = obj["kind"].(string), obj["apiVersion"].(string), meta["name"].(string) if n, ok := meta["namespace"]; ok {
ns = n.(string)
}
name := meta["name"].(string)
cr.path = path.Join(ns, name)
cr.group, cr.version, cr.name = obj["kind"].(string), obj["apiVersion"].(string), name
return cr return cr
} }

View File

@ -12,7 +12,10 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
) )
const defaultTimeout = 1 * time.Second const (
defaultTimeout = 1 * time.Second
podNameSize = 42
)
type ( type (
// Container represents a resource that encompass multiple containers. // Container represents a resource that encompass multiple containers.
@ -211,7 +214,7 @@ func (r *Pod) Fields(ns string) Row {
cr, _, rc, cc := r.statuses() cr, _, rc, cc := r.statuses()
return append(ff, return append(ff,
i.ObjectMeta.Name, Pad(i.ObjectMeta.Name, podNameSize),
strconv.Itoa(cr)+"/"+strconv.Itoa(len(cc)), strconv.Itoa(cr)+"/"+strconv.Itoa(len(cc)),
r.phase(i.Status), r.phase(i.Status),
strconv.Itoa(rc), strconv.Itoa(rc),

View File

@ -214,18 +214,13 @@ func (a *appView) inject(p igniter) {
a.cancel() a.cancel()
} }
a.content.RemovePage("main") a.content.RemovePage("main")
a.content.AddPage("main", p, true, true)
var ctx context.Context var ctx context.Context
{ {
ctx, a.cancel = context.WithCancel(context.TODO()) ctx, a.cancel = context.WithCancel(context.TODO())
p.init(ctx, config.Root.ActiveNamespace()) p.init(ctx, config.Root.ActiveNamespace())
} }
a.content.AddPage("main", p, true, true)
go func() {
<-time.After(100 * time.Millisecond)
a.Draw()
}()
a.focusGroup = append([]tview.Primitive{}, p) a.focusGroup = append([]tview.Primitive{}, p)
a.focusCurrent = 0 a.focusCurrent = 0

View File

@ -77,7 +77,6 @@ func (v *detailsView) keyboard(evt *tcell.EventKey) *tcell.EventKey {
log.Debug(">> DetailsView handled ", tcell.KeyNames[key]) log.Debug(">> DetailsView handled ", tcell.KeyNames[key])
return a.action(evt) return a.action(evt)
} }
log.Debug("Doh! DetailsView got no registered action for key ", tcell.KeyNames[key])
return evt return evt
} }

View File

@ -13,7 +13,7 @@ func run(app *appView, args ...string) bool {
log.Error("Command failed:", err, args) log.Error("Command failed:", err, args)
app.flash(flashErr, "Doh! command failed", err.Error()) app.flash(flashErr, "Doh! command failed", err.Error())
} }
log.Debug("Command Done Running..") log.Debug("Command exec sucessfully!")
}) })
} }

View File

@ -18,10 +18,9 @@ func newInfoView(app *appView) *infoView {
} }
func (v *infoView) init() { func (v *infoView) init() {
var row int
cluster := resource.NewCluster() cluster := resource.NewCluster()
var row int
v.SetCell(row, 0, v.sectionCell("Context")) v.SetCell(row, 0, v.sectionCell("Context"))
v.SetCell(row, 1, v.infoCell(cluster.ContextName())) v.SetCell(row, 1, v.infoCell(cluster.ContextName()))
row++ row++

View File

@ -16,6 +16,8 @@ func newLogView(title string, parent loggable) *logView {
{ {
v.SetBorderPadding(0, 0, 1, 1) v.SetBorderPadding(0, 0, 1, 1)
v.setCategory("Logs") v.setCategory("Logs")
v.SetDynamicColors(false)
v.SetWrap(true)
v.setTitle(parent.getSelection()) v.setTitle(parent.getSelection())
} }
return &v return &v

View File

@ -28,15 +28,11 @@ func newPodView(t string, app *appView, list resource.List, c colorerFn) resourc
picker := newSelectList() picker := newSelectList()
{ {
picker.SetSelectedFunc(func(i int, t, d string, r rune) {
v.sshInto(v.selectedItem, t)
})
picker.setActions(keyActions{ picker.setActions(keyActions{
tcell.KeyEscape: {description: "Back", action: v.backCmd}, tcell.KeyEscape: {description: "Back", action: v.backCmd},
}) })
v.AddPage("choose", picker, true, false) v.AddPage("choose", picker, true, false)
} }
v.switchPage("po") v.switchPage("po")
return &v return &v
} }
@ -81,6 +77,29 @@ func (v *podView) logsCmd(evt *tcell.EventKey) *tcell.EventKey {
return nil return nil
} }
// func (v *podView) logsCmd(evt *tcell.EventKey) *tcell.EventKey {
// if !v.rowSelected() {
// return evt
// }
// cc, err := fetchContainers(v.list, v.selectedItem, true)
// if err != nil {
// v.app.flash(flashErr, err.Error())
// log.Error("Error fetching containers", err)
// return evt
// }
// if len(cc) == 1 {
// v.showLogs(v.selectedItem, "")
// } else {
// p := v.GetPrimitive("choose").(*selectList)
// p.populate(cc)
// p.SetSelectedFunc(func(i int, t, d string, r rune) {
// v.showLogs(v.selectedItem, t)
// })
// v.switchPage("choose")
// }
// return evt
// }
func (v *podView) shellCmd(evt *tcell.EventKey) *tcell.EventKey { func (v *podView) shellCmd(evt *tcell.EventKey) *tcell.EventKey {
if !v.rowSelected() { if !v.rowSelected() {
return evt return evt
@ -92,11 +111,17 @@ func (v *podView) shellCmd(evt *tcell.EventKey) *tcell.EventKey {
return evt return evt
} }
if len(cc) == 1 { if len(cc) == 1 {
v.sshInto(v.selectedItem, "") v.shellIn(v.selectedItem, "")
return nil } else {
// v.showPicker(cc)
p := v.GetPrimitive("choose").(*selectList)
p.populate(cc)
p.SetSelectedFunc(func(i int, t, d string, r rune) {
v.shellIn(v.selectedItem, t)
})
v.switchPage("choose")
} }
v.showPicker(cc) return evt
return nil
} }
func (v *podView) showPicker(cc []string) { func (v *podView) showPicker(cc []string) {
@ -105,13 +130,25 @@ func (v *podView) showPicker(cc []string) {
v.switchPage("choose") v.switchPage("choose")
} }
func (v *podView) sshInto(path, co string) { func (v *podView) shellIn(path, co string) {
ns, po := namespaced(path) ns, po := namespaced(path)
if len(co) == 0 { args := []string{"exec", "-it", "-n", ns, po}
run(v.app, "exec", "-it", "-n", ns, po, "--", "sh") if len(co) != 0 {
} else { args = append(args, "-c", co)
run(v.app, "exec", "-it", "-n", ns, po, "-c", co, "--", "sh")
} }
args = append(args, "--", "sh")
log.Debug("Shell args", args)
run(v.app, args...)
}
func (v *podView) showLogs(path, co string) {
ns, po := namespaced(path)
args := []string{"logs", "-f", "-n", ns, po}
if len(co) != 0 {
args = append(args, "-c", co)
}
log.Debug("Logs Args", args)
run(v.app, args...)
} }
func (v *podView) extraActions(aa keyActions) { func (v *podView) extraActions(aa keyActions) {

View File

@ -65,7 +65,8 @@ func (b *logBuffer) length() int {
} }
func (*logBuffer) decorateLine(l string) string { func (*logBuffer) decorateLine(l string) string {
return "[" + newLogColor + "::]" + l + "[::]" return l
// return "[" + newLogColor + "::]" + l + "[::]"
} }
func (b *logBuffer) trimLine(l string) string { func (b *logBuffer) trimLine(l string) string {

View File

@ -15,6 +15,7 @@ func init() {
mod := os.O_CREATE | os.O_APPEND | os.O_WRONLY mod := os.O_CREATE | os.O_APPEND | os.O_WRONLY
if file, err := os.OpenFile(config.K9sLogs, mod, config.DefaultFileMod); err == nil { if file, err := os.OpenFile(config.K9sLogs, mod, config.DefaultFileMod); err == nil {
log.SetOutput(file) log.SetOutput(file)
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, ForceColors: true})
} else { } else {
panic(err) panic(err)
} }