Skip to content

Commit

Permalink
K9s/release v0.30.7 (#2416)
Browse files Browse the repository at this point in the history
* [Bug] Fix #2413

* [Bug] Fix #2414

* [Bug] Fix #2407

* cleaning up

* Add config files watcher

* rel notes
  • Loading branch information
derailed authored Jan 3, 2024
1 parent d93041b commit 982bf6a
Show file tree
Hide file tree
Showing 40 changed files with 474 additions and 232 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DATE ?= $(shell TZ=UTC date -j -f "%s" ${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:
else
DATE ?= $(shell date -u -d @${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
endif
VERSION ?= v0.30.6
VERSION ?= v0.30.7
IMG_NAME := derailed/k9s
IMAGE := ${IMG_NAME}:${VERSION}

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

# Release v0.30.7

## 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!
Also big thanks to all that have allocated their own time to help others on both slack and on this repo!!

As you may know, K9s is not pimped out by corps with deep pockets, thus if you feel K9s is helping your Kubernetes journey,
please consider joining our [sponsorship 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!

Thank you all for pitching in and helping flesh out issues!!

---

## Videos Are In The Can!

Please dial [K9s Channel](https://www.youtube.com/channel/UC897uwPygni4QIjkPCpgjmw) for up coming content...

* [K9s v0.30.0 Sneak peek](https://youtu.be/mVBc1XneRJ4)
* [Vulnerability Scans](https://youtu.be/ULkl0MsaidU)

---

## Resolved Issues

* [#2414](https://github.com/derailed/k9s/issues/2414) View pods with context filter, along with namespace filter, prompts an error if the namespace exists only in the desired context
* [#2413](https://github.com/derailed/k9s/issues/2413) Typing apply -f in command bar causes k9s to crash
* [#2407](https://github.com/derailed/k9s/issues/2407) Long-running background plugins block UI rendering

---

## Contributed PRs

Please be sure to give `Big Thanks!` and `ATTA Girls/Boys!` to all the fine contributors for making K9s better for all of us!!

* [#2415](https://github.com/derailed/k9s/pull/2415) Add boundary check for args parser
* [#2411](https://github.com/derailed/k9s/pull/2411) Use dash as a standard word separator in skin names


<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/imhotep_logo.png" width="32" height="auto"/> © 2023 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0)
6 changes: 1 addition & 5 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,7 @@ func (a *APIClient) Config() *Config {

// HasMetrics checks if the cluster supports metrics.
func (a *APIClient) HasMetrics() bool {
err := a.supportsMetricsResources()
if err != nil {
log.Debug().Msgf("Metrics server detect failed: %s", err)
}
return err == nil
return a.supportsMetricsResources() != nil
}

// DialLogs returns a handle to api server for logs.
Expand Down
4 changes: 4 additions & 0 deletions internal/config/data/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (n *Namespace) addFavNS(ns string) {
}

func (n *Namespace) rmFavNS(ns string) {
if n.LockFavorites {
return
}

victim := -1
for i, f := range n.Favorites {
if f == ns {
Expand Down
17 changes: 16 additions & 1 deletion internal/config/k9s.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (k *K9s) ActiveContext() (*data.Context, error) {
// ActivateContext initializes the active context is not present.
func (k *K9s) ActivateContext(n string) (*data.Context, error) {
k.activeContextName = n
ct, err := k.ks.GetContext(k.activeContextName)
ct, err := k.ks.GetContext(n)
if err != nil {
return nil, err
}
Expand All @@ -197,6 +197,21 @@ func (k *K9s) ActivateContext(n string) (*data.Context, error) {
return k.activeConfig.Context, nil
}

// Reload reloads the active config from disk.
func (k *K9s) Reload() error {
ct, err := k.ks.GetContext(k.activeContextName)
if err != nil {
return err
}

k.activeConfig, err = k.dir.Load(k.activeContextName, ct)
if err != nil {
return err
}

return nil
}

// OverrideRefreshRate set the refresh rate manually.
func (k *K9s) OverrideRefreshRate(r int) {
k.manualRefreshRate = r
Expand Down
10 changes: 8 additions & 2 deletions internal/config/mock/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,17 @@ func (m mockKubeSettings) ContextNames() (map[string]struct{}, error) {
return mm, nil
}

type mockConnection struct{}
type mockConnection struct {
ct string
}

func NewMockConnection() mockConnection {
return mockConnection{}
}
func NewMockConnectionWithContext(ct string) mockConnection {
return mockConnection{ct: ct}
}

func (m mockConnection) CanI(ns, gvr string, verbs []string) (bool, error) {
return true, nil
}
Expand Down Expand Up @@ -155,7 +161,7 @@ func (m mockConnection) CheckConnectivity() bool {
return false
}
func (m mockConnection) ActiveContext() string {
return ""
return m.ct
}
func (m mockConnection) ActiveNamespace() string {
return ""
Expand Down
21 changes: 8 additions & 13 deletions internal/dao/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"math"
"regexp"

"github.com/derailed/tview"
runewidth "github.com/mattn/go-runewidth"
"github.com/rs/zerolog/log"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -21,7 +19,7 @@ const defaultServiceAccount = "default"

var (
inverseRx = regexp.MustCompile(`\A\!`)
fuzzyRx = regexp.MustCompile(`\A\-f`)
fuzzyRx = regexp.MustCompile(`\A-f\s?([\w-]+)\b`)
)

func inList(ll []string, s string) bool {
Expand All @@ -41,12 +39,14 @@ func IsInverseSelector(s string) bool {
return inverseRx.MatchString(s)
}

// IsFuzzySelector checks if filter is fuzzy or not.
func IsFuzzySelector(s string) bool {
if s == "" {
return false
// HasFuzzySelector checks if query is fuzzy.
func HasFuzzySelector(s string) (string, bool) {
mm := fuzzyRx.FindStringSubmatch(s)
if len(mm) != 2 {
return "", false
}
return fuzzyRx.MatchString(s)

return mm[1], true
}

func toPerc(v1, v2 float64) float64 {
Expand All @@ -56,11 +56,6 @@ func toPerc(v1, v2 float64) float64 {
return math.Round((v1 / v2) * 100)
}

// Truncate a string to the given l and suffix ellipsis if needed.
func Truncate(str string, width int) string {
return runewidth.Truncate(str, width, string(tview.SemigraphicsHorizontalEllipsis))
}

// ToYAML converts a resource to its YAML representation.
func ToYAML(o runtime.Object, showManaged bool) (string, error) {
if o == nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/dao/log_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func (l *LogItems) Filter(index int, q string, showTime bool) ([]int, [][]int, e
if q == "" {
return nil, nil, nil
}
if IsFuzzySelector(q) {
mm, ii := l.fuzzyFilter(index, strings.TrimSpace(q[2:]), showTime)
if f, ok := HasFuzzySelector(q); ok {
mm, ii := l.fuzzyFilter(index, f, showTime)
return mm, ii, nil
}
matches, indices, err := l.filterLogs(index, q, showTime)
Expand Down
4 changes: 2 additions & 2 deletions internal/model/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (d *Describe) filter(q string, lines []string) fuzzy.Matches {
if q == "" {
return nil
}
if dao.IsFuzzySelector(q) {
return d.fuzzyFilter(strings.TrimSpace(q[2:]), lines)
if f, ok := dao.HasFuzzySelector(q); ok {
return d.fuzzyFilter(strings.TrimSpace(f), lines)
}
return rxFilter(q, lines)
}
Expand Down
7 changes: 0 additions & 7 deletions internal/model/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"time"

"github.com/cenkalti/backoff/v4"
"github.com/derailed/tview"
"github.com/mattn/go-runewidth"
"github.com/sahilm/fuzzy"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -28,11 +26,6 @@ func FQN(ns, n string) string {
return ns + "/" + n
}

// Truncate a string to the given l and suffix ellipsis if needed.
func Truncate(str string, width int) string {
return runewidth.Truncate(str, width, string(tview.SemigraphicsHorizontalEllipsis))
}

// NewExpBackOff returns a new exponential backoff timer.
func NewExpBackOff(ctx context.Context, start, max time.Duration) backoff.BackOffContext {
bf := backoff.NewExponentialBackOff()
Expand Down
31 changes: 0 additions & 31 deletions internal/model/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,3 @@ func TestMetaFQN(t *testing.T) {
})
}
}

func TestTruncate(t *testing.T) {
uu := map[string]struct {
data string
size int
e string
}{
"same": {
data: "fred",
size: 4,
e: "fred",
},
"small": {
data: "fred",
size: 10,
e: "fred",
},
"larger": {
data: "fred",
size: 3,
e: "fr…",
},
}

for k := range uu {
u := uu[k]
t.Run(k, func(t *testing.T) {
assert.Equal(t, u.e, model.Truncate(u.data, u.size))
})
}
}
4 changes: 2 additions & 2 deletions internal/model/rev_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (v *RevValues) filter(q string, lines []string) fuzzy.Matches {
if q == "" {
return nil
}
if dao.IsFuzzySelector(q) {
return v.fuzzyFilter(strings.TrimSpace(q[2:]), lines)
if f, ok := dao.HasFuzzySelector(q); ok {
return v.fuzzyFilter(strings.TrimSpace(f), lines)
}
return rxFilter(q, lines)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/model/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func (t *Text) filter(q string, lines []string) fuzzy.Matches {
if q == "" {
return nil
}
if dao.IsFuzzySelector(q) {
return t.fuzzyFilter(strings.TrimSpace(q[2:]), lines)
if f, ok := dao.HasFuzzySelector(q); ok {
return t.fuzzyFilter(strings.TrimSpace(f), lines)
}
return rxFilter(q, lines)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/model/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func (v *Values) filter(q string, lines []string) fuzzy.Matches {
if q == "" {
return nil
}
if dao.IsFuzzySelector(q) {
return v.fuzzyFilter(strings.TrimSpace(q[2:]), lines)
if f, ok := dao.HasFuzzySelector(q); ok {
return v.fuzzyFilter(strings.TrimSpace(f), lines)
}
return rxFilter(q, lines)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/model/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (y *YAML) filter(q string, lines []string) fuzzy.Matches {
if q == "" {
return nil
}
if dao.IsFuzzySelector(q) {
return y.fuzzyFilter(strings.TrimSpace(q[2:]), lines)
if f, ok := dao.HasFuzzySelector(q); ok {
return y.fuzzyFilter(strings.TrimSpace(f), lines)
}
return rxFilter(q, lines)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/render/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/vul"
"github.com/derailed/tview"
runewidth "github.com/mattn/go-runewidth"
"github.com/mattn/go-runewidth"
"github.com/rs/zerolog/log"
"golang.org/x/text/language"
"golang.org/x/text/message"
Expand Down
33 changes: 24 additions & 9 deletions internal/render/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,33 @@ func TestNa(t *testing.T) {
}

func TestTruncate(t *testing.T) {
uu := []struct {
s string
l int
e string
uu := map[string]struct {
data string
size int
e string
}{
{"fred", 3, "fr…"},
{"fred", 2, "f…"},
{"fred", 10, "fred"},
"same": {
data: "fred",
size: 4,
e: "fred",
},
"small": {
data: "fred",
size: 10,
e: "fred",
},
"larger": {
data: "fred",
size: 3,
e: "fr…",
},
}

for _, u := range uu {
assert.Equal(t, u.e, Truncate(u.s, u.l))
for k := range uu {
u := uu[k]
t.Run(k, func(t *testing.T) {
assert.Equal(t, u.e, Truncate(u.data, u.size))
})
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewApp(cfg *config.Config, context string) *App {
flash: model.NewFlash(model.DefaultFlashDelay),
cmdBuff: model.NewFishBuff(':', model.CommandBuffer),
}
a.ReloadStyles(context)
a.ReloadStyles()

a.views = map[string]tview.Primitive{
"menu": NewMenu(a.Styles),
Expand Down Expand Up @@ -135,8 +135,8 @@ func (a *App) StylesChanged(s *config.Styles) {
}

// ReloadStyles reloads skin file.
func (a *App) ReloadStyles(context string) {
a.RefreshStyles(context)
func (a *App) ReloadStyles() {
a.RefreshStyles()
}

// Conn returns an api server connection.
Expand Down
Loading

0 comments on commit 982bf6a

Please sign in to comment.