fix issues #882,881,880

mine
derailed 2020-09-18 13:51:37 -06:00
parent 58d2bfe9e3
commit 2e04a846e6
9 changed files with 78 additions and 40 deletions

View File

@ -0,0 +1,27 @@
<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/k9s_small.png" align="right" width="200" height="auto"/>
# Release v0.22.1
## Notes
Thank you to all that contributed with flushing out issues and enhancements for K9s! I'll try to mark some of these issues as fixed. But if you don't mind grab the latest rev and see if we're happier with some of the fixes! If you've filed an issue please help me verify and close. Your support, kindness and awesome suggestions to make K9s better are as ever very much noted and appreciated!
If you feel K9s is helping your Kubernetes journey, please consider joining our [sponsorhip program](https://github.com/sponsors/derailed) and/or make some noise on social! [@kitesurfer](https://twitter.com/kitesurfer)
On Slack? Please join us [K9slackers](https://join.slack.com/t/k9sers/shared_invite/enQtOTA5MDEyNzI5MTU0LWQ1ZGI3MzliYzZhZWEyNzYxYzA3NjE0YTk1YmFmNzViZjIyNzhkZGI0MmJjYzhlNjdlMGJhYzE2ZGU1NjkyNTM)
---
Maintenance Release!
## Resolved Issues/Features
* [Issue #882](https://github.com/derailed/k9s/issues/882) After filtering objects cannot enter them anymore
* [Issue #881](https://github.com/derailed/k9s/issues/881) CPU limit percentage in pod view counts containers without limits
* [Issue #880](https://github.com/derailed/k9s/issues/880) filtering/search doesn't take all columns into account anymore
## Resolved PRs
---
<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/imhotep_logo.png" width="32" height="auto"/> © 2020 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0)

View File

@ -155,18 +155,18 @@ func gatherMetrics(co *v1.Container, mx *mv1beta1.ContainerMetrics) (c, p, l met
rcpu, rmem := containerResources(*co)
if rcpu != nil {
p.cpu = IntToStr(client.ToPercentage(cpu, rcpu.MilliValue()))
p.cpu = client.ToPercentageStr(cpu, rcpu.MilliValue())
}
if rmem != nil {
p.mem = IntToStr(client.ToPercentage(mem, client.ToMB(rmem.Value())))
p.mem = client.ToPercentageStr(mem, client.ToMB(rmem.Value()))
}
lcpu, lmem := containerLimits(*co)
if lcpu != nil {
l.cpu = IntToStr(client.ToPercentage(cpu, lcpu.MilliValue()))
l.cpu = client.ToPercentageStr(cpu, lcpu.MilliValue())
}
if lmem != nil {
l.mem = IntToStr(client.ToPercentage(mem, client.ToMB(lmem.Value())))
l.mem = client.ToPercentageStr(mem, client.ToMB(lmem.Value()))
}
return

View File

@ -155,13 +155,17 @@ func (*Pod) gatherPodMX(pod *v1.Pod, mx *mv1beta1.PodMetrics) (c, p metric) {
return
}
coMetrix := make(map[string]v1.ResourceList)
for _, cm := range mx.Containers {
coMetrix[cm.Name] = cm.Usage
}
cpu, mem := currentRes(mx)
c = metric{
cpu: ToMillicore(cpu.MilliValue()),
mem: ToMi(client.ToMB(mem.Value())),
}
rc, rm := requestedRes(pod.Spec.Containers)
rc, rm := resourceRequests(pod.Spec.Containers)
lc, lm := resourceLimits(pod.Spec.Containers)
p = metric{
cpu: client.ToPercentageStr(cpu.MilliValue(), rc.MilliValue()),
@ -197,7 +201,9 @@ func resourceLimits(cc []v1.Container) (cpu, mem resource.Quantity) {
for _, co := range cc {
limit := co.Resources.Limits
if len(limit) == 0 {
continue
cpu.Reset()
mem.Reset()
break
}
if limit.Cpu() != nil {
cpu.Add(*limit.Cpu())
@ -209,9 +215,14 @@ func resourceLimits(cc []v1.Container) (cpu, mem resource.Quantity) {
return
}
func requestedRes(cc []v1.Container) (cpu, mem resource.Quantity) {
func resourceRequests(cc []v1.Container) (cpu, mem resource.Quantity) {
for _, co := range cc {
c, m := containerResources(co)
if c == nil || m == nil {
cpu.Reset()
mem.Reset()
break
}
if c != nil {
cpu.Add(*c)
}

View File

@ -17,13 +17,13 @@ type App struct {
*tview.Application
Configurator
Main *Pages
flash *model.Flash
actions KeyActions
views map[string]tview.Primitive
cmdModel *model.FishBuff
running bool
mx sync.RWMutex
Main *Pages
flash *model.Flash
actions KeyActions
views map[string]tview.Primitive
cmdBuff *model.FishBuff
running bool
mx sync.RWMutex
}
// NewApp returns a new app.
@ -34,7 +34,7 @@ func NewApp(cfg *config.Config, context string) *App {
Configurator: Configurator{Config: cfg},
Main: NewPages(),
flash: model.NewFlash(model.DefaultFlashDelay),
cmdModel: model.NewFishBuff(':', model.CommandBuffer),
cmdBuff: model.NewFishBuff(':', model.CommandBuffer),
}
a.ReloadStyles(context)
@ -51,8 +51,8 @@ func NewApp(cfg *config.Config, context string) *App {
// Init initializes the application.
func (a *App) Init() {
a.bindKeys()
a.Prompt().SetModel(a.cmdModel)
a.cmdModel.AddListener(a)
a.Prompt().SetModel(a.cmdBuff)
a.cmdBuff.AddListener(a)
a.Styles.AddListener(a)
a.SetRoot(a.Main, true).EnableMouse(a.Config.K9s.EnableMouse)
@ -157,27 +157,27 @@ func (a *App) ResetPrompt(m PromptModel) {
// ResetCmd clear out user command.
func (a *App) ResetCmd() {
a.cmdModel.Reset()
a.cmdBuff.Reset()
}
// ActivateCmd toggle command mode.
func (a *App) ActivateCmd(b bool) {
a.cmdModel.SetActive(b)
a.cmdBuff.SetActive(b)
}
// GetCmd retrieves user command.
func (a *App) GetCmd() string {
return a.cmdModel.GetText()
return a.cmdBuff.GetText()
}
// CmdBuff returns a cmd buffer.
// CmdBuff returns the app cmd model.
func (a *App) CmdBuff() *model.FishBuff {
return a.cmdModel
return a.cmdBuff
}
// HasCmd check if cmd buffer is active and has a command.
func (a *App) HasCmd() bool {
return a.cmdModel.IsActive() && !a.cmdModel.Empty()
return a.cmdBuff.IsActive() && !a.cmdBuff.Empty()
}
func (a *App) quitCmd(evt *tcell.EventKey) *tcell.EventKey {
@ -218,10 +218,10 @@ func (a *App) Views() map[string]tview.Primitive {
}
func (a *App) clearCmd(evt *tcell.EventKey) *tcell.EventKey {
if !a.CmdBuff().IsActive() {
if !a.cmdBuff.IsActive() {
return evt
}
a.CmdBuff().ClearText(true)
a.cmdBuff.ClearText(true)
return nil
}
@ -230,8 +230,8 @@ func (a *App) activateCmd(evt *tcell.EventKey) *tcell.EventKey {
if a.InCmdMode() {
return evt
}
a.ResetPrompt(a.cmdModel)
a.cmdModel.ClearText(true)
a.ResetPrompt(a.cmdBuff)
a.cmdBuff.ClearText(true)
return nil
}

View File

@ -38,14 +38,14 @@ func ShowDelete(styles config.Dialog, pages *ui.Pages, msg string, ok okFunc, ca
dismissDelete(pages)
cancel()
})
// for i := 0; i < 2; i++ {
// b := f.GetButton(i)
// if b == nil {
// continue
// }
// b.SetBackgroundColorActivated(styles.ButtonFocusBgColor.Color())
// b.SetLabelColorActivated(styles.ButtonFocusFgColor.Color())
// }
for i := 0; i < 2; i++ {
b := f.GetButton(i)
if b == nil {
continue
}
b.SetBackgroundColorActivated(styles.ButtonFocusBgColor.Color())
b.SetLabelColorActivated(styles.ButtonFocusFgColor.Color())
}
f.SetFocus(2)
confirm := tview.NewModalForm("<Delete>", f)

View File

@ -149,7 +149,7 @@ func rxFilter(q string, data render.TableData) (render.TableData, error) {
Namespace: data.Namespace,
}
for _, re := range data.RowEvents {
fields := strings.Join(re.Row.Fields[:2], " ")
fields := strings.Join(re.Row.Fields, " ")
if rx.MatchString(fields) {
filtered.RowEvents = append(filtered.RowEvents, re)
}

View File

@ -113,7 +113,8 @@ func (a *App) Init(version string, rate int) error {
return err
}
a.CmdBuff().SetSuggestionFn(a.suggestCommand())
a.CmdBuff().AddListener(a)
// BOZO!!
// a.CmdBuff().AddListener(a)
a.layout(ctx, version)
a.initSignals()
@ -506,7 +507,6 @@ func (a *App) gotoCmd(evt *tcell.EventKey) *tcell.EventKey {
a.ResetCmd()
return nil
}
a.ActivateCmd(false)
return evt
}

View File

@ -42,7 +42,7 @@ func (n *Namespace) bindKeys(aa ui.KeyActions) {
func (n *Namespace) switchNs(app *App, model ui.Tabular, gvr, path string) {
n.useNamespace(path)
if err := app.gotoResource("pods", "", true); err != nil {
if err := app.gotoResource("pods", "", false); err != nil {
app.Flash().Err(err)
}
}

View File

@ -216,5 +216,5 @@ func (t *Table) activateCmd(evt *tcell.EventKey) *tcell.EventKey {
}
t.App().ResetPrompt(t.CmdBuff())
return nil
return evt
}