From c5080925428e15f9bd464b8971c4a1c3ae7cb5af Mon Sep 17 00:00:00 2001 From: Federico Nafria Date: Sat, 14 Dec 2024 20:48:55 +0100 Subject: [PATCH] Fix: switch context fails after failed connection Fixes https://github.com/derailed/k9s/issues/3032 It should not fail to invalidate the cache when there is not cached connection. --- internal/client/client.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/client/client.go b/internal/client/client.go index e43a561aa6..8f2957c668 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -458,10 +458,12 @@ func (a *APIClient) RestConfig() (*restclient.Config, error) { return a.config.RESTConfig() } +var NoConnectionToCachedDial = errors.New("no connection to cached dial") + // CachedDiscovery returns a cached discovery client. func (a *APIClient) CachedDiscovery() (*disk.CachedDiscoveryClient, error) { if !a.getConnOK() { - return nil, errors.New("no connection to cached dial") + return nil, NoConnectionToCachedDial } if c := a.getCachedClient(); c != nil { @@ -546,7 +548,11 @@ func (a *APIClient) SwitchContext(name string) error { return err } if err := a.invalidateCache(); err != nil { - return err + if err == NoConnectionToCachedDial { + log.Warn().Err(err).Msgf("No cache to invalidate") + } else { + return err + } } a.reset() ResetMetrics()