diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 906b1672..bb81ddfe 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -261,6 +261,7 @@ func TestSetup(t *testing.T) { var expectedConfig = `k9s: refreshRate: 100 + maxConnRetry: 15 enableMouse: false headless: false crumbsless: false @@ -343,6 +344,7 @@ var expectedConfig = `k9s: var resetConfig = `k9s: refreshRate: 2 + maxConnRetry: 15 enableMouse: false headless: false crumbsless: false diff --git a/internal/config/k9s.go b/internal/config/k9s.go index 98c5bf85..578e6f2d 100644 --- a/internal/config/k9s.go +++ b/internal/config/k9s.go @@ -2,11 +2,15 @@ package config import "github.com/derailed/k9s/internal/client" -const defaultRefreshRate = 2 +const ( + defaultRefreshRate = 2 + defaultMaxConnRetry = 15 +) // K9s tracks K9s configuration options. type K9s struct { RefreshRate int `yaml:"refreshRate"` + MaxConnRetry int `yaml:"maxConnRetry"` EnableMouse bool `yaml:"enableMouse"` Headless bool `yaml:"headless"` Crumbsless bool `yaml:"crumbsless"` @@ -27,10 +31,11 @@ type K9s struct { // NewK9s create a new K9s configuration. func NewK9s() *K9s { return &K9s{ - RefreshRate: defaultRefreshRate, - Logger: NewLogger(), - Clusters: make(map[string]*Cluster), - Thresholds: NewThreshold(), + RefreshRate: defaultRefreshRate, + MaxConnRetry: defaultMaxConnRetry, + Logger: NewLogger(), + Clusters: make(map[string]*Cluster), + Thresholds: NewThreshold(), } } @@ -116,6 +121,9 @@ func (k *K9s) validateDefaults() { if k.RefreshRate <= 0 { k.RefreshRate = defaultRefreshRate } + if k.MaxConnRetry <= 0 { + k.MaxConnRetry = defaultMaxConnRetry + } } func (k *K9s) validateClusters(c client.Connection, ks KubeSettings) { diff --git a/internal/view/app.go b/internal/view/app.go index ff3f92d4..1c754545 100644 --- a/internal/view/app.go +++ b/internal/view/app.go @@ -30,7 +30,6 @@ var ExitStatus = "" const ( splashDelay = 1 * time.Second clusterRefresh = 15 * time.Second - maxConRetry = 15 clusterInfoWidth = 50 clusterInfoPad = 15 ) @@ -304,13 +303,13 @@ func (a *App) refreshCluster() { c.Stop() } - count := atomic.LoadInt32(&a.conRetry) - if count >= maxConRetry { + count, maxConnRetry := atomic.LoadInt32(&a.conRetry), int32(a.Config.K9s.MaxConnRetry) + if count >= maxConnRetry { ExitStatus = fmt.Sprintf("Lost K8s connection (%d). Bailing out!", count) a.BailOut() } if count > 0 { - log.Warn().Msgf("Conn check failed (%d/%d)", count, maxConRetry) + log.Warn().Msgf("Conn check failed (%d/%d)", count, maxConnRetry) a.Status(model.FlashWarn, fmt.Sprintf("Dial K8s failed (%d)", count)) return }