Skip to content

Commit

Permalink
[GCE cloudprovider] Invalidate mig instances cache after node deletion
Browse files Browse the repository at this point in the history
After deleting some instances from a mig, invalidate the mig
instances cache so that the deleted instances are refreshed
accordingly.
  • Loading branch information
bskiba committed Jul 23, 2024
1 parent b58fed5 commit 77d38c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cluster-autoscaler/cloudprovider/gce/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ func (gc *GceCache) InvalidateAllMigInstances() {
gc.instancesUpdateTime = make(map[GceRef]time.Time)
}

// InvalidateMigInstances clears the mig instances cache for a given Mig
func (gc *GceCache) InvalidateMigInstances(migRef GceRef) {
gc.cacheMutex.Lock()
defer gc.cacheMutex.Unlock()

klog.V(5).Infof("Mig instances cache invalidated for %v", migRef.Name)
delete(gc.instances, migRef)
delete(gc.instancesUpdateTime, migRef)
}

// InvalidateInstancesToMig clears the instance to mig mapping for a GceRef
func (gc *GceCache) InvalidateInstancesToMig(migRef GceRef) {
gc.cacheMutex.Lock()
Expand Down
1 change: 1 addition & 0 deletions cluster-autoscaler/cloudprovider/gce/gce_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func (m *gceManagerImpl) DeleteInstances(instances []GceRef) error {
}
}
m.cache.InvalidateMigTargetSize(commonMig.GceRef())
m.cache.InvalidateMigInstances(commonMig.GceRef())
return m.GceService.DeleteInstances(commonMig.GceRef(), instances)
}

Expand Down

0 comments on commit 77d38c0

Please sign in to comment.