Skip to content

Commit

Permalink
k9s: release v0.25.9 (derailed#1364)
Browse files Browse the repository at this point in the history
* release v0.25.9

* update docs
  • Loading branch information
derailed authored Dec 13, 2021
1 parent 0249f7c commit 34eab38
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PACKAGE := github.com/derailed/$(NAME)
GIT_REV ?= $(shell git rev-parse --short HEAD)
SOURCE_DATE_EPOCH ?= $(shell date +%s)
DATE ?= $(shell date -u -d @${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
VERSION ?= v0.25.8
VERSION ?= v0.25.9
IMG_NAME := derailed/k9s
IMAGE := ${IMG_NAME}:${VERSION}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -883,4 +883,4 @@ We always enjoy hearing from folks who benefit from our work!
---
<img src="assets/imhotep_logo.png" width="32" height="auto" alt="Imhotep"/> &nbsp;© 2020 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0)
<img src="assets/imhotep_logo.png" width="32" height="auto" alt="Imhotep"/> &nbsp;© 2021 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0)
54 changes: 54 additions & 0 deletions change_logs/release_v0.25.9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/k9s_small.png" align="right" width="200" height="auto"/>

# Release v0.25.9

## 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 [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)

### A Word From Our Sponsors...

I want to recognize the following folks that have been kind enough to join our sponsorship program and opted to `pay it forward`!

* [Joshua Kapellen](https://github.com/joshuakapellen)
* [Qdentity](https://github.com/qdentity)
* [Maxim](https://github.com/bsod90)
* [Sönke Schau](https://github.com/xgcssch)

So if you feel K9s is helping with your productivity while administering your Kubernetes clusters, please consider pitching in as it will go a long way in ensuring a thriving environment for this repo and our k9ers community at large.

Also please take some time and give a huge shoot out to all the good folks below that have spent time plowing thru the code to help improve K9s for all of us!

Thank you!!

---

## Maintenance Release!

---

## Resolved Issues

* [Issue #1361](https://github.com/derailed/k9s/issues/1361) Pulses not displaying graphs
* [Issue #1358](https://github.com/derailed/k9s/issues/1358) Namespace list is empty
* [Issue #1357](https://github.com/derailed/k9s/issues/1357) Benchmarks doesn't work on windows
* [Issue #1355](https://github.com/derailed/k9s/issues/1355) Trace log level does not exists
* [Issue #1345](https://github.com/derailed/k9s/issues/1345) Access denied after context switch

---

## PRs

* [PR #1363](https://github.com/derailed/k9s/pull/1363) Add rose-pine skin.
[Sergio Soria](https://github.com/sasoria)
* [PR #1356](https://github.com/derailed/k9s/pull/1356) Add flux trace shortcut to flux plugin.
[Guillaume Berche](https://github.com/gberche-orange)
* [PR #1321](https://github.com/derailed/k9s/pull/1321) Add customizable dump directory property.
[Vlasov Artem](https://github.com/VlasovArtem)


<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/imhotep_logo.png" width="32" height="auto"/> © 2021 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0)
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func initK9sFlags() {
k9sFlags.LogLevel,
"logLevel", "l",
config.DefaultLogLevel,
"Specify a log level (info, warn, debug, error, fatal, panic, trace)",
"Specify a log level (info, warn, debug, error)",
)
rootCmd.Flags().StringVarP(
k9sFlags.LogFile,
Expand Down Expand Up @@ -221,7 +221,7 @@ func initK9sFlags() {
}

func initK8sFlags() {
k8sFlags = genericclioptions.NewConfigFlags(false)
k8sFlags = genericclioptions.NewConfigFlags(client.UsePersistentConfig)

rootCmd.Flags().StringVar(
k8sFlags.KubeConfig,
Expand Down
74 changes: 25 additions & 49 deletions internal/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
)

const (
defaultCallTimeoutDuration time.Duration = 5 * time.Second
defaultCallTimeoutDuration time.Duration = 10 * time.Second

// UsePersistentConfig caches client config to avoid reloads.
UsePersistentConfig = true
)

// Config tracks a kubernetes configuration.
type Config struct {
flags *genericclioptions.ConfigFlags
clientCfg clientcmd.ClientConfig
rawCfg *clientcmdapi.Config
mutex *sync.RWMutex
OverrideNS bool
}
Expand Down Expand Up @@ -58,60 +59,35 @@ func (c *Config) Flags() *genericclioptions.ConfigFlags {
return c.flags
}

func (c *Config) rawConfig() (*clientcmdapi.Config, error) {
if c.rawCfg != nil {
return c.rawCfg, nil
}

cfg, err := c.clientConfig().RawConfig()
if err != nil {
return nil, err
}
c.rawCfg = &cfg

return c.rawCfg, nil
func (c *Config) RawConfig() (clientcmdapi.Config, error) {
return c.clientConfig().RawConfig()
}

func (c *Config) clientConfig() clientcmd.ClientConfig {
if c.clientCfg != nil {
return c.clientCfg
}
c.clientCfg = c.flags.ToRawKubeConfigLoader()

return c.clientCfg
return c.flags.ToRawKubeConfigLoader()
}

func (c *Config) reset() {
c.clientCfg, c.rawCfg = nil, nil
}
func (c *Config) reset() {}

// SwitchContext changes the kubeconfig context to a new cluster.
func (c *Config) SwitchContext(name string) error {
if n, err := c.CurrentContextName(); err == nil && n == name {
return nil
}
context, err := c.GetContext(name)
if err != nil {
if _, err := c.GetContext(name); err != nil {
return fmt.Errorf("context %q does not exist", name)
}
c.flags.Namespace = &context.Namespace
c.flags.Context = &name
c.flags.ClusterName = &(context.Cluster)
c.reset()
flags := genericclioptions.NewConfigFlags(UsePersistentConfig)
flags.Context = &name
flags.Timeout = c.flags.Timeout
c.flags = flags

return nil
}

func (c *Config) RawConfig() *clientcmdapi.Config {
return c.rawCfg
}

// CurrentContextName returns the currently active config context.
func (c *Config) CurrentContextName() (string, error) {
if isSet(c.flags.Context) {
return *c.flags.Context, nil
}
cfg, err := c.rawConfig()
cfg, err := c.RawConfig()
if err != nil {
return "", err
}
Expand All @@ -121,7 +97,7 @@ func (c *Config) CurrentContextName() (string, error) {

// GetContext fetch a given context or error if it does not exists.
func (c *Config) GetContext(n string) (*clientcmdapi.Context, error) {
cfg, err := c.rawConfig()
cfg, err := c.RawConfig()
if err != nil {
return nil, err
}
Expand All @@ -134,7 +110,7 @@ func (c *Config) GetContext(n string) (*clientcmdapi.Context, error) {

// Contexts fetch all available contexts.
func (c *Config) Contexts() (map[string]*clientcmdapi.Context, error) {
cfg, err := c.rawConfig()
cfg, err := c.RawConfig()
if err != nil {
return nil, err
}
Expand All @@ -144,7 +120,7 @@ func (c *Config) Contexts() (map[string]*clientcmdapi.Context, error) {

// DelContext remove a given context from the configuration.
func (c *Config) DelContext(n string) error {
cfg, err := c.rawConfig()
cfg, err := c.RawConfig()
if err != nil {
return err
}
Expand All @@ -155,12 +131,12 @@ func (c *Config) DelContext(n string) error {
return err
}

return clientcmd.ModifyConfig(acc, *cfg, true)
return clientcmd.ModifyConfig(acc, cfg, true)
}

// ContextNames fetch all available contexts.
func (c *Config) ContextNames() ([]string, error) {
cfg, err := c.rawConfig()
cfg, err := c.RawConfig()
if err != nil {
return nil, err
}
Expand All @@ -174,7 +150,7 @@ func (c *Config) ContextNames() ([]string, error) {

// ClusterNameFromContext returns the cluster associated with the given context.
func (c *Config) ClusterNameFromContext(context string) (string, error) {
cfg, err := c.rawConfig()
cfg, err := c.RawConfig()
if err != nil {
return "", err
}
Expand All @@ -190,7 +166,7 @@ func (c *Config) CurrentClusterName() (string, error) {
if isSet(c.flags.ClusterName) {
return *c.flags.ClusterName, nil
}
cfg, err := c.rawConfig()
cfg, err := c.RawConfig()
if err != nil {
return "", err
}
Expand All @@ -208,7 +184,7 @@ func (c *Config) CurrentClusterName() (string, error) {

// ClusterNames fetch all kubeconfig defined clusters.
func (c *Config) ClusterNames() ([]string, error) {
cfg, err := c.rawConfig()
cfg, err := c.RawConfig()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -258,7 +234,7 @@ func (c *Config) CurrentUserName() (string, error) {
return *c.flags.AuthInfoName, nil
}

cfg, err := c.rawConfig()
cfg, err := c.RawConfig()
if err != nil {
return "", err
}
Expand All @@ -276,8 +252,8 @@ func (c *Config) CurrentUserName() (string, error) {

// CurrentNamespaceName retrieves the active namespace.
func (c *Config) CurrentNamespaceName() (string, error) {
ns, _, err := c.clientConfig().Namespace()

ns, ov, err := c.clientConfig().Namespace()
fmt.Printf("!!!ZOB!!! %q -- %t\n", ns, ov)
return ns, err
}

Expand Down
8 changes: 8 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ func (c *Config) ActiveNamespace() string {
cl = NewCluster()
c.K9s.Clusters[c.K9s.CurrentCluster] = cl
}
if ns, err := c.settings.CurrentNamespaceName(); err == nil && ns != "" {
if cl.Namespace == nil {
cl.Namespace = NewNamespace()
}
cl.Namespace.Active = ns
return ns
}

if cl.Namespace != nil {
return cl.Namespace.Active
}
Expand Down
21 changes: 19 additions & 2 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func TestConfigRefine(t *testing.T) {
t.Run(k, func(t *testing.T) {
mc := NewMockConnection()
m.When(mc.ValidNamespaces()).ThenReturn(namespaces(), nil)
mk := NewMockKubeSettings()
m.When(mk.NamespaceNames(namespaces())).ThenReturn([]string{"default"})
mk := newMockSettings(u.flags)
cfg := config.NewConfig(mk)

err := cfg.Refine(u.flags, nil, client.NewConfig(u.flags))
Expand Down Expand Up @@ -256,6 +255,24 @@ func TestSetup(t *testing.T) {
})
}

type mockSettings struct {
flags *genericclioptions.ConfigFlags
}

var _ config.KubeSettings = (*mockSettings)(nil)

func newMockSettings(flags *genericclioptions.ConfigFlags) *mockSettings {
return &mockSettings{flags: flags}
}
func (m *mockSettings) CurrentContextName() (string, error) {
return *m.flags.Context, nil
}
func (m *mockSettings) CurrentClusterName() (string, error) { return "", nil }
func (m *mockSettings) CurrentNamespaceName() (string, error) {
return *m.flags.Namespace, nil
}
func (m *mockSettings) ClusterNames() ([]string, error) { return nil, nil }

// ----------------------------------------------------------------------------
// Test Data...

Expand Down
16 changes: 0 additions & 16 deletions internal/dao/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package dao

import (
"context"
"errors"

"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/render"
"github.com/rs/zerolog/log"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/clientcmd"
)

var (
Expand Down Expand Up @@ -61,17 +59,3 @@ func (c *Context) MustCurrentContextName() string {
func (c *Context) Switch(ctx string) error {
return c.Factory.Client().SwitchContext(ctx)
}

// KubeUpdate modifies kubeconfig default context.
func (c *Context) KubeUpdate(n string) error {
cfg := c.config().RawConfig()
if cfg == nil {
return errors.New("unable to fetch raw config")
}
if err := c.Switch(n); err != nil {
return err
}
return clientcmd.ModifyConfig(
clientcmd.NewDefaultPathOptions(), *cfg, true,
)
}
Loading

0 comments on commit 34eab38

Please sign in to comment.