diff --git a/cluster-autoscaler/cloudprovider/gce/cache.go b/cluster-autoscaler/cloudprovider/gce/cache.go index 4d1ce64a91e4..075aa2343f4f 100644 --- a/cluster-autoscaler/cloudprovider/gce/cache.go +++ b/cluster-autoscaler/cloudprovider/gce/cache.go @@ -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() diff --git a/cluster-autoscaler/cloudprovider/gce/gce_manager.go b/cluster-autoscaler/cloudprovider/gce/gce_manager.go index 534d3e15b220..11cebc26aa0c 100644 --- a/cluster-autoscaler/cloudprovider/gce/gce_manager.go +++ b/cluster-autoscaler/cloudprovider/gce/gce_manager.go @@ -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) }