QOSManagerConf
QOSManagerConf: qmframework.NewDefaultConfig(),
func NewDefaultConfig() *Config {
return &Config{
CollectResUsedInterval: 1 * time.Second,//收集重新利用间隔1s
CollectNodeCPUInfoInterval: 60 * time.Second,//采集节点cpu信息间隔60s
CollectNodeStorageInfoInterval: 1 * time.Second,//采集节点存储信息间隔 1s
CPICollectorInterval: 60 * time.Second,//cpi采集间隔10s
PSICollectorInterval: 10 * time.Second,//psi采集间隔10s
CPICollectorTimeWindow: 10 * time.Second,//cpi采集窗口10s
}
}
QosManager初始化
- 参数:配置、schema、k8s客户端、crd客户端、node名称、statesInformer、metric缓存、采集配置、驱逐版本。
//创建qosManager
qosManager := qosmanager.NewQOSManager(config.QOSManagerConf, scheme, kubeClient, crdClient,
nodeName, statesInformer, metricCache, config.CollectorConf, evictVersion)
NewQOSManager
-
初始化eventRecord、cgroupReader、evictor
-
构建opt,包含cgroupReader、statesInformer、metric缓存、eventRecorder、k8s客户端、驱逐版本、Qos配置、metricAdvisor配置。
-
构建context,包含evictor和策略map。
-
- 遍历策略插件,调用插件初始化方法,然后加入到插件中
func NewQOSManager(cfg *framework.Config, schema *apiruntime.Scheme, kubeClient clientset.Interface, crdClient *koordclientset.Clientset, nodeName string,
statesInformer statesinformer.StatesInformer, metricCache metriccache.MetricCache, metricAdvisorConfig *ma.Config, evictVersion string) QOSManager {
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartRecordingToSink(&clientcorev1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})
recorder := eventBroadcaster.NewRecorder(schema, corev1.EventSource{Component: "koordlet-qosManager", Host: nodeName})
cgroupReader := resourceexecutor.NewCgroupReader()
evictor := framework.NewEvictor(kubeClient, recorder, evictVersion)
opt := &framework.Options{
CgroupReader: cgroupReader,
StatesInformer: statesInformer,
MetricCache: metricCache,
EventRecorder: recorder,
KubeClient: kubeClient,
EvictVersion: evictVersion,
Config: cfg,
MetricAdvisorConfig: metricAdvisorConfig,
}
ctx := &framework.Context{
Evictor: evictor,
Strategies: make(map[string]framework.QOSStrategy, len(plugins.StrategyPlugins)),
}
for name, strategyFn := range plugins.StrategyPlugins {
ctx.Strategies[name] = strategyFn(opt)
}
r := &qosManager{
options: opt,
context: ctx,
}
return r
}
插件策略列表
- blkio
- cgreconcile
- cpuburst
- cpuevict
- cpusuppress
- memoryevict
- resctrl
- sysreconcile
StrategyPlugins = map[string]framework.QOSStrategyFactory{
blkio.BlkIOReconcileName: blkio.New,
cgreconcile.CgroupReconcileName: cgreconcile.New,
cpuburst.CPUBurstName: cpuburst.New,
cpuevict.CPUEvictName: cpuevict.New,
cpusuppress.CPUSuppressName: cpusuppress.New,
memoryevict.MemoryEvictName: memoryevict.New,
resctrl.ResctrlReconcileName: resctrl.New,
sysreconcile.SystemConfigReconcileName: sysreconcile.New,
}
QosManager启动
- 采集间隔小于1s直接退出
- qosManager.setup()
- Evictor启动
- framework.RunQOSGreyCtrlPlugins灰度插件(暂时没看到这个插件)
- 等所有informer启动完成
- 遍历启动context所有策略(就是上面讲的插件策略),当然只有enable才启动。
- framework.SetupPlugins(暂时没看到这个插件)
- 等待退出
func (r *qosManager) Run(stopCh <-chan struct{}) error {
defer utilruntime.HandleCrash()
// minimum interval is one second.
if r.options.MetricAdvisorConfig.CollectResUsedInterval < time.Second {
klog.Infof("collectResUsedIntervalSeconds is %v, qos manager is disabled",
r.options.MetricAdvisorConfig.CollectResUsedInterval)
return nil
}
klog.Info("Starting qos manager")
r.setup()
err := r.context.Evictor.Start(stopCh)
if err != nil {
klog.Fatal("start evictor failed %v", err)
}
go framework.RunQOSGreyCtrlPlugins(r.options.KubeClient, stopCh)
if !cache.WaitForCacheSync(stopCh, r.options.StatesInformer.HasSynced) {
return fmt.Errorf("time out waiting for states informer caches to sync")
}
for name, strategy := range r.context.Strategies {
klog.V(4).Infof("reaady to start qos strategy %v", name)
if !strategy.Enabled() {
klog.V(4).Infof("qos strategy %v is not enabled, skip running", name)
continue
}
go strategy.Run(stopCh)
klog.V(4).Infof("qos strategy %v start", name)
}
klog.Infof("start qos manager extensions")
framework.SetupPlugins(r.options.KubeClient, r.options.MetricCache, r.options.StatesInformer)
utilruntime.Must(framework.StartPlugins(r.options.Config.QOSExtensionCfg, stopCh))
klog.Info("Starting qosManager successfully")
<-stopCh
klog.Info("shutting down qosManager")
return nil
}