From 530d0671106194fd907ca1a94f930973c6e7a964 Mon Sep 17 00:00:00 2001 From: Mohamed Messaad Date: Tue, 29 Nov 2022 16:52:33 +0100 Subject: [PATCH] feat: add noLatestRevCheck config option (#1874) * feat: add noLatestRevCheck flag to configure whether k9s should fetch the latest rev from the Github repo. * refactor: rename "noLatestRevCheck" to more appropriate "skipLatestRevCheck" --- README.md | 2 ++ internal/config/config_test.go | 2 ++ internal/config/k9s.go | 1 + internal/model/cluster_info.go | 35 +++++++++++++++++++++------------- internal/ui/app.go | 2 +- internal/view/app.go | 2 +- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6d2c6743..08f89b1b 100644 --- a/README.md +++ b/README.md @@ -311,6 +311,8 @@ K9s uses aliases to navigate most K8s resources. noExitOnCtrlC: false # Toggles icons display as not all terminal support these chars. noIcons: false + # Toggles whether k9s should check for the latest revision from the Github repository releases. Default is false. + skipLatestRevCheck: false # Logs configuration logger: # Defines the number of lines to return. Default 100 diff --git a/internal/config/config_test.go b/internal/config/config_test.go index d3109b17..f2fc354b 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -286,6 +286,7 @@ var expectedConfig = `k9s: readOnly: true noExitOnCtrlC: false noIcons: false + skipLatestRevCheck: false logger: tail: 500 buffer: 800 @@ -381,6 +382,7 @@ var resetConfig = `k9s: readOnly: false noExitOnCtrlC: false noIcons: false + skipLatestRevCheck: false logger: tail: 200 buffer: 2000 diff --git a/internal/config/k9s.go b/internal/config/k9s.go index 964fcbf1..2358d9ab 100644 --- a/internal/config/k9s.go +++ b/internal/config/k9s.go @@ -20,6 +20,7 @@ type K9s struct { ReadOnly bool `yaml:"readOnly"` NoExitOnCtrlC bool `yaml:"noExitOnCtrlC"` NoIcons bool `yaml:"noIcons"` + SkipLatestRevCheck bool `yaml:"skipLatestRevCheck"` Logger *Logger `yaml:"logger"` CurrentContext string `yaml:"currentContext"` CurrentCluster string `yaml:"currentCluster"` diff --git a/internal/model/cluster_info.go b/internal/model/cluster_info.go index 961cd952..0f9d98c2 100644 --- a/internal/model/cluster_info.go +++ b/internal/model/cluster_info.go @@ -69,22 +69,24 @@ func (c ClusterMeta) Deltas(n ClusterMeta) bool { // ClusterInfo models cluster metadata. type ClusterInfo struct { - cluster *Cluster - factory dao.Factory - data ClusterMeta - version string - listeners []ClusterInfoListener - cache *cache.LRUExpireCache + cluster *Cluster + factory dao.Factory + data ClusterMeta + version string + skipLatestRevCheck bool + listeners []ClusterInfoListener + cache *cache.LRUExpireCache } // NewClusterInfo returns a new instance. -func NewClusterInfo(f dao.Factory, v string) *ClusterInfo { +func NewClusterInfo(f dao.Factory, v string, skipLatestRevCheck bool) *ClusterInfo { c := ClusterInfo{ - factory: f, - cluster: NewCluster(f), - data: NewClusterMeta(), - version: v, - cache: cache.NewLRUExpireCache(cacheSize), + factory: f, + cluster: NewCluster(f), + data: NewClusterMeta(), + version: v, + skipLatestRevCheck: skipLatestRevCheck, + cache: cache.NewLRUExpireCache(cacheSize), } return &c @@ -130,7 +132,14 @@ func (c *ClusterInfo) Refresh() { } } data.K9sVer = c.version - v1, v2 := NewSemVer(data.K9sVer), NewSemVer(c.fetchK9sLatestRev()) + v1 := NewSemVer(data.K9sVer) + + var latestRev string + if !c.skipLatestRevCheck { + latestRev = c.fetchK9sLatestRev() + } + v2 := NewSemVer(latestRev) + data.K9sVer, data.K9sLatest = v1.String(), v2.String() if v1.IsCurrent(v2) { data.K9sLatest = "" diff --git a/internal/ui/app.go b/internal/ui/app.go index 55fa2a18..2e0475f7 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -151,7 +151,7 @@ func (a *App) bindKeys() { } } -// BailOut exists the application. +// BailOut exits the application. func (a *App) BailOut() { a.Stop() os.Exit(0) diff --git a/internal/view/app.go b/internal/view/app.go index 96228f5f..130b9cc3 100644 --- a/internal/view/app.go +++ b/internal/view/app.go @@ -100,7 +100,7 @@ func (a *App) Init(version string, rate int) error { } a.initFactory(ns) - a.clusterModel = model.NewClusterInfo(a.factory, a.version) + a.clusterModel = model.NewClusterInfo(a.factory, a.version, a.Config.K9s.SkipLatestRevCheck) a.clusterModel.AddListener(a.clusterInfo()) a.clusterModel.AddListener(a.statusIndicator()) if a.Conn().ConnectionOK() {