Skip to content

Commit

Permalink
Fix: switch context fails after failed connection
Browse files Browse the repository at this point in the history
Fixes #3032

It should not fail to invalidate the cache when there is not cached
connection.
  • Loading branch information
driv committed Dec 14, 2024
1 parent 9b0ffb8 commit f35ee02
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -545,7 +547,10 @@ func (a *APIClient) SwitchContext(name string) error {
if err := a.config.SwitchContext(name); err != nil {
return err
}
if err := a.invalidateCache(); err != nil {
err := a.invalidateCache()
if err == NoConnectionToCachedDial {
log.Warn().Err(err).Msgf("No cache to invalidate")
} else if err != nil {
return err
}
a.reset()
Expand Down

0 comments on commit f35ee02

Please sign in to comment.