Merge pull request #7694 from mtrqq/bug/clean-instance-templates
Fix memory leak while fetching GCE instance templates.
This commit is contained in:
commit
2ca75135fb
|
@ -432,6 +432,25 @@ func (gc *GceCache) InvalidateAllMigInstanceTemplates() {
|
|||
gc.instanceTemplatesCache = map[GceRef]*gce.InstanceTemplate{}
|
||||
}
|
||||
|
||||
// DropInstanceTemplatesForMissingMigs clears the instance template
|
||||
// cache intended MIGs which are no longer present in the cluster
|
||||
func (gc *GceCache) DropInstanceTemplatesForMissingMigs(currentMigs []Mig) {
|
||||
gc.cacheMutex.Lock()
|
||||
defer gc.cacheMutex.Unlock()
|
||||
|
||||
requiredKeys := make(map[GceRef]struct{}, len(currentMigs))
|
||||
for _, mig := range currentMigs {
|
||||
requiredKeys[mig.GceRef()] = struct{}{}
|
||||
}
|
||||
|
||||
klog.V(5).Infof("Instance template cache partially invalidated")
|
||||
for key := range gc.instanceTemplatesCache {
|
||||
if _, exists := requiredKeys[key]; !exists {
|
||||
delete(gc.instanceTemplatesCache, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetMigKubeEnv returns the cached KubeEnv for a mig GceRef
|
||||
func (gc *GceCache) GetMigKubeEnv(ref GceRef) (KubeEnv, bool) {
|
||||
gc.cacheMutex.Lock()
|
||||
|
|
|
@ -306,7 +306,14 @@ func (m *gceManagerImpl) Refresh() error {
|
|||
if m.lastRefresh.Add(refreshInterval).After(time.Now()) {
|
||||
return nil
|
||||
}
|
||||
return m.forceRefresh()
|
||||
|
||||
if err := m.forceRefresh(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
migs := m.migLister.GetMigs()
|
||||
m.cache.DropInstanceTemplatesForMissingMigs(migs)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *gceManagerImpl) CreateInstances(mig Mig, delta int64) error {
|
||||
|
|
Loading…
Reference in New Issue