Skip to content
Snippets Groups Projects
Unverified Commit 2ca75135 authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub
Browse files

Merge pull request #7694 from mtrqq/bug/clean-instance-templates

Fix memory leak while fetching GCE instance templates.
parents 2937e9c3 99584890
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment