资源限制入口pkg/koordlet/resmanager/cpu_suppress.go中
func (r *CPUSuppress) suppressBECPU() {
...
if nodeSLO.Spec.ResourceUsedThresholdWithBE.CPUSuppressPolicy == slov1alpha1.CPUCfsQuotaPolicy {
adjustByCfsQuota(suppressCPUQuantity, node)
r.suppressPolicyStatuses[string(slov1alpha1.CPUCfsQuotaPolicy)] = policyUsing
r.recoverCPUSetIfNeed()
} else {
adjustByCPUSet(suppressCPUQuantity, nodeCPUInfo)
r.suppressPolicyStatuses[string(slov1alpha1.CPUSetPolicy)] = policyUsing
r.recoverCFSQuotaIfNeed()
}
...
}
拿cfsquota举例pkg/koordlet/resmanager/cpu_suppress.go中
func adjustByCfsQuota(cpuQuantity *resource.Quantity, node *corev1.Node) {
...
if err := sysutil.CgroupFileWrite(beCgroupPath, sysutil.CPUCFSQuota, strconv.FormatInt(newBeQuota, 10)); err != nil {
klog.Errorf("suppressBECPU: failed to write cfs_quota_us for offline pods, error: %v", err)
return
}
...
}
其实最终的操作就是写入相应的值到/sys/fs/cgroup/cpu/kubepods.slice/kubepods-besteffort.slice/cpu.cfs_quota_us这个文件中
由于
1cgroup是层级的,子cgroup会继承父cgroup
2 所有的best effort pod都在此目录下
因此可以限制best effort pod的总cpu开销
网友评论