add config for max conn retries

mine
derailed 2020-10-27 20:15:50 -06:00
parent dd9bddf78f
commit d5bea6395c
3 changed files with 18 additions and 9 deletions

View File

@ -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

View File

@ -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"`
@ -28,6 +32,7 @@ type K9s struct {
func NewK9s() *K9s {
return &K9s{
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) {

View File

@ -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
}