Skip to content

Commit

Permalink
Fix: switch context fails after failed connection
Browse files Browse the repository at this point in the history
Fixes derailed#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 c508092
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 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 @@ -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()
Expand Down

0 comments on commit c508092

Please sign in to comment.