From 3dcf1b0573e71d5c9776706da842e4d84271f606 Mon Sep 17 00:00:00 2001 From: derailed Date: Mon, 11 Mar 2019 06:13:10 -0600 Subject: [PATCH] added context info when running commands --- internal/views/exec.go | 9 --------- internal/views/pod.go | 12 ++++++++++-- internal/views/resource.go | 10 ++++++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/internal/views/exec.go b/internal/views/exec.go index ed5f684a..c1e9e8cd 100644 --- a/internal/views/exec.go +++ b/internal/views/exec.go @@ -37,15 +37,6 @@ func runK(app *appView, args ...string) bool { }) } -func run1(app *appView, bin string, args ...string) bool { - return app.Suspend(func() { - if err := execute(bin, args...); err != nil { - log.Error().Msgf("Command exited: %T %v %v", err, err, args) - app.flash(flashErr, "Command exited: ", err.Error()) - } - }) -} - func execute(bin string, args ...string) error { clearScreen() log.Debug().Msgf("Running command > %s %s", bin, strings.Join(args, " ")) diff --git a/internal/views/pod.go b/internal/views/pod.go index 1fd22f66..40a3701b 100644 --- a/internal/views/pod.go +++ b/internal/views/pod.go @@ -3,6 +3,7 @@ package views import ( "fmt" + "github.com/derailed/k9s/internal/config" "github.com/derailed/k9s/internal/resource" "github.com/gdamore/tcell" "github.com/rs/zerolog/log" @@ -140,7 +141,11 @@ func (v *podView) showPicker(cc []string) { func (v *podView) shellIn(path, co string) { ns, po := namespaced(path) - args := []string{"exec", "-it", "-n", ns, po} + args := make([]string, 0, 12) + args = append(args, "exec", "-it") + args = append(args, "--context", config.Root.K9s.CurrentContext) + args = append(args, "-n", ns) + args = append(args, po) if len(co) != 0 { args = append(args, "-c", co) } @@ -153,13 +158,16 @@ func (v *podView) showLogs(path, co string, previous bool) { ns, po := namespaced(path) args := make([]string, 0, 10) args = append(args, "logs", "-f") + args = append(args, "-n", ns) + args = append(args, "--context", config.Root.K9s.CurrentContext) if len(co) != 0 { args = append(args, "-c", co) v.app.flash(flashInfo, fmt.Sprintf("Viewing logs from container %s on pod %s", co, po)) } else { v.app.flash(flashInfo, fmt.Sprintf("Viewing logs from pod %s", po)) } - runK(v.app, append(args, "-n", ns, po)...) + args = append(args, po) + runK(v.app, args...) } func (v *podView) extraActions(aa keyActions) { diff --git a/internal/views/resource.go b/internal/views/resource.go index 6137eff0..cc609db0 100644 --- a/internal/views/resource.go +++ b/internal/views/resource.go @@ -193,8 +193,14 @@ func (v *resourceView) editCmd(evt *tcell.EventKey) *tcell.EventKey { if !v.rowSelected() { return evt } - ns, s := namespaced(v.selectedItem) - runK(v.app, "edit", v.list.GetName(), "-n", ns, s) + ns, po := namespaced(v.selectedItem) + args := make([]string, 0, 10) + args = append(args, "edit") + args = append(args, v.list.GetName()) + args = append(args, "-n", ns) + args = append(args, "--context", config.Root.K9s.CurrentContext) + args = append(args, po) + runK(v.app, args...) return evt }