func (m *managerImpl) synchronize(diskInfoProvider DiskInfoProvider, podFunc ActivePodsFunc, capacityProvider CapacityProvider) []*v1.Pod {
// 1. 从配置中读取所有Thresholds
thresholds := m.config.Thresholds
if len(thresholds) == 0 {
return nil
}
....
// 2. 初始化rank funcs/reclaim funcs等
if m.dedicatedImageFs == nil {
hasImageFs, ok := diskInfoProvider.HasDedicatedImageFs()
if ok != nil {
return nil
}
m.dedicatedImageFs = &hasImageFs
m.resourceToRankFunc = buildResourceToRankFunc(hasImageFs)
m.resourceToNodeReclaimFuncs = buildResourceToNodeReclaimFuncs(m.imageGC, m.containerGC, hasImageFs)
}
// 3. 通过初始化传入的func获取Pods
activePods := podFunc()
// 4. 通过summary provider获得当前资源使用情况
observations, statsFunc, err := makeSignalObservations(m.summaryProvider, capacityProvider, activePods)
....
// 5. 通过memcg加速内存占用通知,只在notifiersInitialized 为false时进入
if m.config.KernelMemcgNotification && !m.notifiersInitialized {
....
m.notifiersInitialized = true // 初始化完成
err = startMemoryThresholdNotifier(m.config.Thresholds, observations, true , func(desc string) {
// 回调函数,memcg的通知会立即触发synchronize函数
glog.Infof( "hard memory eviction threshold crossed at %s" , desc)
m.synchronize(diskInfoProvider, podFunc, capacityProvider)
})
....
}
....
}
|