File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
cluster-autoscaler/cloudprovider/gce Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -432,6 +432,25 @@ func (gc *GceCache) InvalidateAllMigInstanceTemplates() {
432432 gc .instanceTemplatesCache = map [GceRef ]* gce.InstanceTemplate {}
433433}
434434
435+ // DropInstanceTemplatesForMissingMigs clears the instance template
436+ // cache intended MIGs which are no longer present in the cluster
437+ func (gc * GceCache ) DropInstanceTemplatesForMissingMigs (currentMigs []Mig ) {
438+ gc .cacheMutex .Lock ()
439+ defer gc .cacheMutex .Unlock ()
440+
441+ requiredKeys := make (map [GceRef ]struct {}, len (currentMigs ))
442+ for _ , mig := range currentMigs {
443+ requiredKeys [mig .GceRef ()] = struct {}{}
444+ }
445+
446+ klog .V (5 ).Infof ("Instance template cache partially invalidated" )
447+ for key := range gc .instanceTemplatesCache {
448+ if _ , exists := requiredKeys [key ]; ! exists {
449+ delete (gc .instanceTemplatesCache , key )
450+ }
451+ }
452+ }
453+
435454// GetMigKubeEnv returns the cached KubeEnv for a mig GceRef
436455func (gc * GceCache ) GetMigKubeEnv (ref GceRef ) (KubeEnv , bool ) {
437456 gc .cacheMutex .Lock ()
Original file line number Diff line number Diff line change @@ -306,7 +306,14 @@ func (m *gceManagerImpl) Refresh() error {
306306 if m .lastRefresh .Add (refreshInterval ).After (time .Now ()) {
307307 return nil
308308 }
309- return m .forceRefresh ()
309+
310+ if err := m .forceRefresh (); err != nil {
311+ return err
312+ }
313+
314+ migs := m .migLister .GetMigs ()
315+ m .cache .DropInstanceTemplatesForMissingMigs (migs )
316+ return nil
310317}
311318
312319func (m * gceManagerImpl ) CreateInstances (mig Mig , delta int64 ) error {
You can’t perform that action at this time.
0 commit comments