resolved issue #562
parent
5b45819c62
commit
18db3f1f3c
|
|
@ -2,7 +2,6 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -32,72 +31,6 @@ func NewAliases() *Aliases {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Aliases) loadDefaults() {
|
|
||||||
const (
|
|
||||||
contexts = "contexts"
|
|
||||||
portFwds = "portforwards"
|
|
||||||
benchmarks = "benchmarks"
|
|
||||||
dumps = "screendumps"
|
|
||||||
groups = "groups"
|
|
||||||
users = "users"
|
|
||||||
)
|
|
||||||
|
|
||||||
a.mx.Lock()
|
|
||||||
defer a.mx.Unlock()
|
|
||||||
|
|
||||||
a.Alias["dp"] = "apps/v1/deployments"
|
|
||||||
a.Alias["sec"] = "v1/secrets"
|
|
||||||
a.Alias["jo"] = "batch/v1/jobs"
|
|
||||||
a.Alias["cr"] = "rbac.authorization.k8s.io/v1/clusterroles"
|
|
||||||
a.Alias["crb"] = "rbac.authorization.k8s.io/v1/clusterrolebindings"
|
|
||||||
a.Alias["ro"] = "rbac.authorization.k8s.io/v1/roles"
|
|
||||||
a.Alias["rb"] = "rbac.authorization.k8s.io/v1/rolebindings"
|
|
||||||
a.Alias["np"] = "networking.k8s.io/v1/networkpolicies"
|
|
||||||
{
|
|
||||||
a.Alias["ctx"] = contexts
|
|
||||||
a.Alias[contexts] = contexts
|
|
||||||
a.Alias["context"] = contexts
|
|
||||||
}
|
|
||||||
{
|
|
||||||
a.Alias["usr"] = users
|
|
||||||
a.Alias[users] = users
|
|
||||||
a.Alias["user"] = users
|
|
||||||
}
|
|
||||||
{
|
|
||||||
a.Alias["grp"] = groups
|
|
||||||
a.Alias["group"] = groups
|
|
||||||
a.Alias[groups] = groups
|
|
||||||
}
|
|
||||||
{
|
|
||||||
a.Alias["pf"] = portFwds
|
|
||||||
a.Alias[portFwds] = portFwds
|
|
||||||
a.Alias["portforward"] = portFwds
|
|
||||||
}
|
|
||||||
{
|
|
||||||
a.Alias["be"] = benchmarks
|
|
||||||
a.Alias["benchmark"] = benchmarks
|
|
||||||
a.Alias[benchmarks] = benchmarks
|
|
||||||
}
|
|
||||||
{
|
|
||||||
a.Alias["sd"] = dumps
|
|
||||||
a.Alias["screendump"] = dumps
|
|
||||||
a.Alias[dumps] = dumps
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load K9s aliases.
|
|
||||||
func (a *Aliases) Load() error {
|
|
||||||
a.loadDefaults()
|
|
||||||
|
|
||||||
_, err := os.Stat(K9sAlias)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
log.Debug().Err(err).Msgf("No custom aliases found")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return a.LoadAliases(K9sAlias)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShortNames return all shortnames.
|
// ShortNames return all shortnames.
|
||||||
func (a *Aliases) ShortNames() ShortNames {
|
func (a *Aliases) ShortNames() ShortNames {
|
||||||
a.mx.RLock()
|
a.mx.RLock()
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,11 @@ func TestFlash(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(5 * delay)
|
time.Sleep(5 * delay)
|
||||||
s, _, l, m := v.getMetrics()
|
s, c, l, m := v.getMetrics()
|
||||||
assert.Equal(t, 1, s)
|
assert.Equal(t, 1, s)
|
||||||
assert.Equal(t, u.level, l)
|
assert.Equal(t, u.level, l)
|
||||||
assert.Equal(t, u.e, m)
|
assert.Equal(t, u.e, m)
|
||||||
|
assert.Equal(t, 1, c)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,16 +79,19 @@ func (p PodDisruptionBudget) Render(o interface{}, ns string, r *Row) error {
|
||||||
strconv.Itoa(int(pdb.Status.DesiredHealthy)),
|
strconv.Itoa(int(pdb.Status.DesiredHealthy)),
|
||||||
strconv.Itoa(int(pdb.Status.ExpectedPods)),
|
strconv.Itoa(int(pdb.Status.ExpectedPods)),
|
||||||
mapToStr(pdb.Labels),
|
mapToStr(pdb.Labels),
|
||||||
asStatus(p.diagnose(pdb.Spec.MinAvailable.IntVal, pdb.Status.CurrentHealthy)),
|
asStatus(p.diagnose(pdb.Spec.MinAvailable, pdb.Status.CurrentHealthy)),
|
||||||
toAge(pdb.ObjectMeta.CreationTimestamp),
|
toAge(pdb.ObjectMeta.CreationTimestamp),
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (PodDisruptionBudget) diagnose(min, healthy int32) error {
|
func (PodDisruptionBudget) diagnose(min *intstr.IntOrString, healthy int32) error {
|
||||||
if min > healthy {
|
if min == nil {
|
||||||
return fmt.Errorf("expected %d but got %d", min, healthy)
|
return nil
|
||||||
|
}
|
||||||
|
if min.IntVal > healthy {
|
||||||
|
return fmt.Errorf("expected %d but got %d", min.IntVal, healthy)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package view
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/derailed/k9s/internal/client"
|
"github.com/derailed/k9s/internal/client"
|
||||||
|
|
@ -155,11 +154,3 @@ func (c *Container) isForwardable(path string) ([]string, bool) {
|
||||||
|
|
||||||
return pp, true
|
return pp, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryListenPort(port string) error {
|
|
||||||
server, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return server.Close()
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,5 @@ func TestContainerNew(t *testing.T) {
|
||||||
|
|
||||||
assert.Nil(t, c.Init(makeCtx()))
|
assert.Nil(t, c.Init(makeCtx()))
|
||||||
assert.Equal(t, "Containers", c.Name())
|
assert.Equal(t, "Containers", c.Name())
|
||||||
assert.Equal(t, 15, len(c.Hints()))
|
assert.Equal(t, 16, len(c.Hints()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,7 @@ func TestHelp(t *testing.T) {
|
||||||
v := view.NewHelp()
|
v := view.NewHelp()
|
||||||
|
|
||||||
assert.Nil(t, v.Init(ctx))
|
assert.Nil(t, v.Init(ctx))
|
||||||
assert.Equal(t, 21, v.GetRowCount())
|
assert.Equal(t, 23, v.GetRowCount())
|
||||||
assert.Equal(t, 22, v.GetRowCount())
|
|
||||||
assert.Equal(t, 8, v.GetColumnCount())
|
assert.Equal(t, 8, v.GetColumnCount())
|
||||||
assert.Equal(t, "<a>", strings.TrimSpace(v.GetCell(1, 0).Text))
|
assert.Equal(t, "<a>", strings.TrimSpace(v.GetCell(1, 0).Text))
|
||||||
assert.Equal(t, "Attach", strings.TrimSpace(v.GetCell(1, 1).Text))
|
assert.Equal(t, "Attach", strings.TrimSpace(v.GetCell(1, 1).Text))
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package view
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/derailed/k9s/internal/client"
|
"github.com/derailed/k9s/internal/client"
|
||||||
|
|
@ -71,6 +72,14 @@ func (p *PortForwardExtender) fetchPodName(path string) (string, error) {
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Helpers...
|
// Helpers...
|
||||||
|
|
||||||
|
func tryListenPort(port string) error {
|
||||||
|
server, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return server.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func runForward(v ResourceViewer, pf watch.Forwarder, f *portforward.PortForwarder) {
|
func runForward(v ResourceViewer, pf watch.Forwarder, f *portforward.PortForwarder) {
|
||||||
v.App().factory.AddForwarder(pf)
|
v.App().factory.AddForwarder(pf)
|
||||||
|
|
||||||
|
|
@ -92,7 +101,11 @@ func runForward(v ResourceViewer, pf watch.Forwarder, f *portforward.PortForward
|
||||||
}
|
}
|
||||||
|
|
||||||
func startFwdCB(v ResourceViewer, path, co string, t client.PortTunnel) {
|
func startFwdCB(v ResourceViewer, path, co string, t client.PortTunnel) {
|
||||||
log.Debug().Msgf("CURRENT-FWD %#v", v.App().factory.Forwarders())
|
err := tryListenPort(t.LocalPort)
|
||||||
|
if err != nil {
|
||||||
|
v.App().Flash().Err(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if _, ok := v.App().factory.ForwarderFor(dao.PortForwardID(path, co)); ok {
|
if _, ok := v.App().factory.ForwarderFor(dao.PortForwardID(path, co)); ok {
|
||||||
v.App().Flash().Err(errors.New("A port-forward is already active on this pod"))
|
v.App().Flash().Err(errors.New("A port-forward is already active on this pod"))
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ func (p *Pod) attachCmd(evt *tcell.EventKey) *tcell.EventKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
row := p.GetTable().GetSelectedRowIndex()
|
row := p.GetTable().GetSelectedRowIndex()
|
||||||
status := ui.TrimCell(p.GetTable().SelectTable, row, p.GetTable().NameColIndex()+2)
|
status := ui.TrimCell(p.GetTable().SelectTable, row, p.GetTable().NameColIndex()+3)
|
||||||
if status != render.Running {
|
if status != render.Running {
|
||||||
p.App().Flash().Errf("%s is not in a running state", path)
|
p.App().Flash().Errf("%s is not in a running state", path)
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -230,35 +230,21 @@ func resumeAttachIn(a *App, c model.Component, path, co string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func attachIn(a *App, path, co string) {
|
func attachIn(a *App, path, co string) {
|
||||||
args := computeAttachArgs(path, co, a.Config.K9s.CurrentContext, a.Conn().Config().Flags().KubeConfig)
|
args := buildShellArgs("attach", path, co, a.Config.K9s.CurrentContext, a.Conn().Config().Flags().KubeConfig)
|
||||||
|
|
||||||
c := color.New(color.BgGreen).Add(color.FgBlack).Add(color.Bold)
|
c := color.New(color.BgGreen).Add(color.FgBlack).Add(color.Bold)
|
||||||
if !runK(a, shellOpts{clear: true, banner: c.Sprintf(bannerFmt, path, co), args: args}) {
|
if !runK(a, shellOpts{clear: true, banner: c.Sprintf(bannerFmt, path, co), args: args}) {
|
||||||
a.Flash().Err(errors.New("Attach exec failed"))
|
a.Flash().Err(errors.New("Attach exec failed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func computeShellArgs(path, co, context string, kcfg *string) []string {
|
func computeShellArgs(path, co, context string, kcfg *string) []string {
|
||||||
args := make([]string, 0, 15)
|
args := buildShellArgs("exec", path, co, context, kcfg)
|
||||||
args = append(args, "exec", "-it")
|
|
||||||
args = append(args, "--context", context)
|
|
||||||
ns, po := client.Namespaced(path)
|
|
||||||
args = append(args, "-n", ns)
|
|
||||||
args = append(args, po)
|
|
||||||
if kcfg != nil && *kcfg != "" {
|
|
||||||
args = append(args, "--kubeconfig", *kcfg)
|
|
||||||
}
|
|
||||||
if co != "" {
|
|
||||||
args = append(args, "-c", co)
|
|
||||||
}
|
|
||||||
|
|
||||||
return append(args, "--", "sh", "-c", shellCheck)
|
return append(args, "--", "sh", "-c", shellCheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
func computeAttachArgs(path, co, context string, kcfg *string) []string {
|
func buildShellArgs(cmd, path, co, context string, kcfg *string) []string {
|
||||||
args := make([]string, 0, 15)
|
args := make([]string, 0, 15)
|
||||||
args = append(args, "attach", "-it")
|
args = append(args, cmd, "-it")
|
||||||
args = append(args, "--context", context)
|
args = append(args, "--context", context)
|
||||||
ns, po := client.Namespaced(path)
|
ns, po := client.Namespaced(path)
|
||||||
args = append(args, "-n", ns)
|
args = append(args, "-n", ns)
|
||||||
|
|
@ -269,7 +255,7 @@ func computeAttachArgs(path, co, context string, kcfg *string) []string {
|
||||||
if co != "" {
|
if co != "" {
|
||||||
args = append(args, "-c", co)
|
args = append(args, "-c", co)
|
||||||
}
|
}
|
||||||
|
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@ func TestPodNew(t *testing.T) {
|
||||||
|
|
||||||
assert.Nil(t, po.Init(makeCtx()))
|
assert.Nil(t, po.Init(makeCtx()))
|
||||||
assert.Equal(t, "Pods", po.Name())
|
assert.Equal(t, "Pods", po.Name())
|
||||||
assert.Equal(t, 20, len(po.Hints()))
|
assert.Equal(t, 22, len(po.Hints()))
|
||||||
assert.Equal(t, 21, len(po.Hints()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helpers...
|
// Helpers...
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue