Skip to content

Commit

Permalink
Hoping resolved on cmd lock out issue + bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Mar 1, 2019
1 parent 4aef289 commit 66bdef9
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 53 deletions.
40 changes: 19 additions & 21 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
project_name: k9s
before:
hooks:
# you may remove this if you don't use vgo
- go mod download
# you may remove this if you don't need go generate
- go generate ./...

release:
prerelease: true

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- 386
- amd64
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}}
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- 386
- amd64
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}}

archive:
replacements:
darwin: Darwin
linux: Linux
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- "^docs:"
- "^test:"

# Homebrew
brew:
Expand All @@ -53,4 +51,4 @@ brew:
homepage: https://k9ss.io
description: Kubernetes CLI To Manage Your Clusters In Style!
test: |
system "k9s version"
system "k9s version"
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go
go_import_path: github.com/derailed/k9s
go:
- 1.11.5
- "1.12"
# - master

os:
Expand All @@ -18,4 +18,4 @@ env:

script:
- go build
- go test ./...
- go test ./...
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/derailed/k9s
require (
contrib.go.opencensus.io/exporter/ocagent v0.4.3 // 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/evanphx/json-patch v4.1.0+incompatible // indirect
github.com/fatih/camelcase v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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/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.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/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/evanphx/json-patch v4.1.0+incompatible h1:K1MDoo4AZ4wU0GIU/fPmtZg7VpzLjCxu+UwBD1FvwOc=
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"runtime/debug"

"github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/k8s"
Expand Down Expand Up @@ -126,14 +127,22 @@ func run(cmd *cobra.Command, args []string) {
level = log.DebugLevel
}
log.SetLevel(level)
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, ForceColors: true})

initK9s()

app := views.NewApp()
{
app.Init(version, refreshRate, k8sFlags)
defer func() {
if err := recover(); err != nil {
app.Stop()
fmt.Println(err)
debug.PrintStack()
}
}()
app.Run()
}

}

func initK8sFlags() {
Expand Down
9 changes: 7 additions & 2 deletions internal/resource/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ func (*Custom) NewInstance(i interface{}) Columnar {
log.Error(err)
}
meta := obj["metadata"].(map[string]interface{})
cr.path = path.Join(meta["namespace"].(string), meta["name"].(string))
cr.group, cr.version, cr.name = obj["kind"].(string), obj["apiVersion"].(string), meta["name"].(string)
ns := ""
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
}

Expand Down
7 changes: 5 additions & 2 deletions internal/resource/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
v1 "k8s.io/api/core/v1"
)

const defaultTimeout = 1 * time.Second
const (
defaultTimeout = 1 * time.Second
podNameSize = 42
)

type (
// Container represents a resource that encompass multiple containers.
Expand Down Expand Up @@ -211,7 +214,7 @@ func (r *Pod) Fields(ns string) Row {

cr, _, rc, cc := r.statuses()
return append(ff,
i.ObjectMeta.Name,
Pad(i.ObjectMeta.Name, podNameSize),
strconv.Itoa(cr)+"/"+strconv.Itoa(len(cc)),
r.phase(i.Status),
strconv.Itoa(rc),
Expand Down
7 changes: 1 addition & 6 deletions internal/views/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,13 @@ func (a *appView) inject(p igniter) {
a.cancel()
}
a.content.RemovePage("main")
a.content.AddPage("main", p, true, true)

var ctx context.Context
{
ctx, a.cancel = context.WithCancel(context.TODO())
p.init(ctx, config.Root.ActiveNamespace())
}

go func() {
<-time.After(100 * time.Millisecond)
a.Draw()
}()
a.content.AddPage("main", p, true, true)

a.focusGroup = append([]tview.Primitive{}, p)
a.focusCurrent = 0
Expand Down
1 change: 0 additions & 1 deletion internal/views/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (v *detailsView) keyboard(evt *tcell.EventKey) *tcell.EventKey {
log.Debug(">> DetailsView handled ", tcell.KeyNames[key])
return a.action(evt)
}
log.Debug("Doh! DetailsView got no registered action for key ", tcell.KeyNames[key])
return evt
}

Expand Down
2 changes: 1 addition & 1 deletion internal/views/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func run(app *appView, args ...string) bool {
log.Error("Command failed:", err, args)
app.flash(flashErr, "Doh! command failed", err.Error())
}
log.Debug("Command Done Running..")
log.Debug("Command exec sucessfully!")
})
}

Expand Down
3 changes: 1 addition & 2 deletions internal/views/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ func newInfoView(app *appView) *infoView {
}

func (v *infoView) init() {
var row int

cluster := resource.NewCluster()

var row int
v.SetCell(row, 0, v.sectionCell("Context"))
v.SetCell(row, 1, v.infoCell(cluster.ContextName()))
row++
Expand Down
2 changes: 2 additions & 0 deletions internal/views/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func newLogView(title string, parent loggable) *logView {
{
v.SetBorderPadding(0, 0, 1, 1)
v.setCategory("Logs")
v.SetDynamicColors(false)
v.SetWrap(true)
v.setTitle(parent.getSelection())
}
return &v
Expand Down
63 changes: 50 additions & 13 deletions internal/views/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ func newPodView(t string, app *appView, list resource.List, c colorerFn) resourc

picker := newSelectList()
{
picker.SetSelectedFunc(func(i int, t, d string, r rune) {
v.sshInto(v.selectedItem, t)
})
picker.setActions(keyActions{
tcell.KeyEscape: {description: "Back", action: v.backCmd},
})
v.AddPage("choose", picker, true, false)
}

v.switchPage("po")
return &v
}
Expand Down Expand Up @@ -81,6 +77,29 @@ func (v *podView) logsCmd(evt *tcell.EventKey) *tcell.EventKey {
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 {
if !v.rowSelected() {
return evt
Expand All @@ -92,11 +111,17 @@ func (v *podView) shellCmd(evt *tcell.EventKey) *tcell.EventKey {
return evt
}
if len(cc) == 1 {
v.sshInto(v.selectedItem, "")
return nil
v.shellIn(v.selectedItem, "")
} 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 nil
return evt
}

func (v *podView) showPicker(cc []string) {
Expand All @@ -105,13 +130,25 @@ func (v *podView) showPicker(cc []string) {
v.switchPage("choose")
}

func (v *podView) sshInto(path, co string) {
func (v *podView) shellIn(path, co string) {
ns, po := namespaced(path)
if len(co) == 0 {
run(v.app, "exec", "-it", "-n", ns, po, "--", "sh")
} else {
run(v.app, "exec", "-it", "-n", ns, po, "-c", co, "--", "sh")
args := []string{"exec", "-it", "-n", ns, po}
if len(co) != 0 {
args = append(args, "-c", co)
}
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) {
Expand Down
3 changes: 2 additions & 1 deletion internal/views/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func (b *logBuffer) length() int {
}

func (*logBuffer) decorateLine(l string) string {
return "[" + newLogColor + "::]" + l + "[::]"
return l
// return "[" + newLogColor + "::]" + l + "[::]"
}

func (b *logBuffer) trimLine(l string) string {
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func init() {
mod := os.O_CREATE | os.O_APPEND | os.O_WRONLY
if file, err := os.OpenFile(config.K9sLogs, mod, config.DefaultFileMod); err == nil {
log.SetOutput(file)
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, ForceColors: true})
} else {
panic(err)
}
Expand Down

0 comments on commit 66bdef9

Please sign in to comment.