Skip to content

Commit

Permalink
maintenance release. Fix derailed#920 and perhaps improved derailed#663
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Nov 3, 2020
1 parent f241cda commit fb1d731
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PACKAGE := github.com/derailed/$(NAME)
GIT := $(shell git rev-parse --short HEAD)
SOURCE_DATE_EPOCH ?= $(shell date +%s)
DATE := $(shell date -u -d @${SOURCE_DATE_EPOCH} +%FT%T%Z)
VERSION ?= v0.23.3
VERSION ?= v0.23.4
IMG_NAME := derailed/k9s
IMAGE := ${IMG_NAME}:${VERSION}

Expand Down
28 changes: 28 additions & 0 deletions change_logs/release_v0.23.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/k9s_small.png" align="right" width="200" height="auto"/>

# Release v0.23.4

## 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 #920](https://github.com/derailed/k9s/issues/920) Timestamp stopped working
* [Issue #663](https://github.com/derailed/k9s/issues/663) Perf issues in v0.23.X - Better??

## 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)
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func init() {
if err := flags.Set("stderrthreshold", "fatal"); err != nil {
panic(err)
}
if err := flags.Set("v", "0"); err != nil {
if err := flags.Set("v", "-1"); err != nil {
panic(err)
}
if err := flags.Set("log_file", config.K9sLogs); err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/config/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (n *Namespace) Validate(c client.Connection, ks KubeSettings) {

// SetActive set the active namespace.
func (n *Namespace) SetActive(ns string, ks KubeSettings) error {
log.Debug().Msgf("Setting active ns %q", ns)
n.Active = ns
if ns != "" {
n.addFavNS(ns)
Expand Down
16 changes: 11 additions & 5 deletions internal/model/fish_buff.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,28 @@ func (f *FishBuff) SetSuggestionFn(fn SuggestionFunc) {
}

// Notify publish suggestions to all listeners.
func (f *FishBuff) Notify() {
func (f *FishBuff) Notify(delete bool) {
if f.suggestionFn == nil {
return
}
ss := f.suggestionFn(string(f.buff))
if len(ss) == 1 && !delete {
f.SetText(string(string(f.buff) + ss[0]))
return
}
f.fireSuggestionChanged(f.suggestionFn(string(f.buff)))
}

// Add adds a new charater to the buffer.
// Add adds a new character to the buffer.
func (f *FishBuff) Add(r rune) {
f.CmdBuff.Add(r)
f.Notify()
f.Notify(false)
}

// Delete removes the last character from the buffer.
func (f *FishBuff) Delete() {
f.CmdBuff.Delete()
f.Notify()
f.Notify(true)
}

func (f *FishBuff) fireSuggestionChanged(ss []string) {
Expand All @@ -127,9 +132,10 @@ func (f *FishBuff) fireSuggestionChanged(ss []string) {
return
}

text, sug := f.GetText(), ss[f.suggestionIndex]
for _, l := range f.listeners {
if listener, ok := l.(SuggestionListener); ok {
listener.SuggestionChanged(f.GetText(), ss[f.suggestionIndex])
listener.SuggestionChanged(text, sug)
}
}
}
32 changes: 25 additions & 7 deletions internal/model/fish_buff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,37 @@ import (
"github.com/stretchr/testify/assert"
)

func TestFishExact(t *testing.T) {
m := mockSuggestionListener{}

f := model.NewFishBuff(' ', model.FilterBuffer)
f.AddListener(&m)
f.SetSuggestionFn(func(text string) sort.StringSlice {
return sort.StringSlice{"lee"}
})
f.Add('b')
f.SetActive(true)

assert.True(t, m.active)
assert.Equal(t, 1, m.buff)
assert.Equal(t, 0, m.sugg)
assert.Equal(t, "blee", m.text)
}

func TestFishAdd(t *testing.T) {
m := mockSuggestionListener{}

f := model.NewFishBuff(' ', model.FilterBuffer)
f.AddListener(&m)
f.SetSuggestionFn(func(text string) sort.StringSlice {
return sort.StringSlice{"blee", "duh"}
return sort.StringSlice{"blee", "brew"}
})
f.Add('a')
f.Add('b')
f.SetActive(true)

assert.True(t, m.active)
assert.Equal(t, 1, m.buff)
assert.Equal(t, 1, m.sugg)
assert.True(t, m.active)
assert.Equal(t, "blee", m.suggestion)

c, ok := f.CurrentSuggestion()
Expand All @@ -30,7 +47,7 @@ func TestFishAdd(t *testing.T) {

c, ok = f.NextSuggestion()
assert.True(t, ok)
assert.Equal(t, "duh", c)
assert.Equal(t, "brew", c)

c, ok = f.PrevSuggestion()
assert.True(t, ok)
Expand Down Expand Up @@ -70,16 +87,17 @@ func TestFishDelete(t *testing.T) {
// Helpers...

type mockSuggestionListener struct {
buff, sugg int
suggestion string
active bool
buff, sugg int
suggestion, text string
active bool
}

func (m *mockSuggestionListener) BufferChanged(s string) {
m.buff++
}

func (m *mockSuggestionListener) BufferCompleted(s string) {
m.text = s
}

func (m *mockSuggestionListener) BufferActive(state bool, kind model.BufferKind) {
Expand Down
23 changes: 8 additions & 15 deletions internal/model/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ func NewLog(gvr client.GVR, opts dao.LogOptions, flushTimeout time.Duration) *Lo
}
}

// LogOptions returns the current log options.
func (l *Log) LogOptions() dao.LogOptions {
l.mx.RLock()
defer l.mx.RUnlock()

return l.logOptions
}

// SinceSeconds returns since seconds option.
func (l *Log) SinceSeconds() int64 {
l.mx.RLock()
Expand All @@ -66,14 +58,15 @@ func (l *Log) SinceSeconds() int64 {
return l.logOptions.SinceSeconds
}

// SetLogOptions updates logger options.
func (l *Log) SetLogOptions(opts dao.LogOptions) {
l.mx.Lock()
{
l.logOptions = opts
}
l.mx.Unlock()
// ToggleShowTimestamp toggles to logs timestamps.
func (l *Log) ToggleShowTimestamp(b bool) {
l.logOptions.ShowTimestamp = b
l.Refresh()
}

// SetSinceSeconds sets the logs retrieval time.
func (l *Log) SetSinceSeconds(i int64) {
l.logOptions.SinceSeconds = i
l.Restart()
}

Expand Down
11 changes: 5 additions & 6 deletions internal/render/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,14 @@ func gatherMetrics(co *v1.Container, mx *mv1beta1.ContainerMetrics) (resources,
if rList.Cpu() != nil {
p[requestCPU] = percentMc(c.rCPU(), rList.Cpu())
}
if rList.Memory() != nil {
p[requestMEM] = percentMi(c.rMEM(), rList.Memory())
}

if lList.Cpu() != nil {
p[limitCPU] = percentMc(c.lCPU(), lList.Cpu())
p[limitCPU] = percentMc(c.rCPU(), lList.Cpu())
}
if rList.Memory() != nil {
p[limitMEM] = percentMi(c.lMEM(), lList.Memory())
p[requestMEM] = percentMi(c.rMEM(), rList.Memory())
}
if lList.Memory() != nil {
p[limitMEM] = percentMi(c.rMEM(), lList.Memory())
}

return c, p, r
Expand Down
4 changes: 2 additions & 2 deletions internal/render/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func TestContainer(t *testing.T) {
"20:20",
"100:100",
"50",
"0",
"50",
"20",
"20",
"0",
"",
"container is not ready",
},
Expand Down
17 changes: 7 additions & 10 deletions internal/render/helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package render

import (
"fmt"
"regexp"
"sort"
"strconv"
Expand Down Expand Up @@ -120,7 +119,7 @@ func join(a []string, sep string) string {
return a[0]
}

var b []string
b := make([]string, 0, len(a))
for _, s := range a {
if s != "" {
b = append(b, s)
Expand Down Expand Up @@ -258,28 +257,26 @@ func mapToIfc(m interface{}) (s string) {
return
}

func toMcPerc(v1, v2 *resource.Quantity) string {
m := v1.MilliValue()
return fmt.Sprintf("%s (%d%%)", toMc(m), client.ToPercentage(m, v2.MilliValue()))
func toMcPerc(v1, v2 int64) string {
return toMc(v1) + " (" + strconv.Itoa(client.ToPercentage(v1, v2)) + "%)"
}

func toMiPerc(v1, v2 *resource.Quantity) string {
m := v1.Value()
return fmt.Sprintf("%s (%d%%)", toMi(m), client.ToPercentage(m, v2.Value()))
func toMiPerc(v1, v2 int64) string {
return toMi(v1) + " (" + strconv.Itoa(client.ToPercentage(v1, v2)) + "%)"
}

func toMc(v int64) string {
if v == 0 {
return ZeroValue
}
return AsThousands(v)
return strconv.Itoa(int(v))
}

func toMi(v int64) string {
if v == 0 {
return ZeroValue
}
return AsThousands(client.ToMB(v))
return strconv.Itoa(int(client.ToMB(v)))
}

func boolPtrToStr(b *bool) string {
Expand Down
4 changes: 2 additions & 2 deletions internal/render/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func TestToMc(t *testing.T) {
}{
{0, "0"},
{2, "2"},
{1_000, "1,000"},
{1_000, "1000"},
}

for _, u := range uu {
Expand All @@ -383,7 +383,7 @@ func TestToMi(t *testing.T) {
}{
{0, "0"},
{2 * client.MegaByte, "2"},
{1_000 * client.MegaByte, "1,000"},
{1_000 * client.MegaByte, "1000"},
}

for _, u := range uu {
Expand Down
Loading

0 comments on commit fb1d731

Please sign in to comment.