Skip to content

Commit

Permalink
CPU-Pooler Corrections
Browse files Browse the repository at this point in the history
- Issue nokia#10: First check there is no more than 1 shared pool, and if it's correct, start CPU DP server and register resources
- Issue nokia#14: set container's cpu request to "0m" in case of shared pool
  • Loading branch information
balintTobik committed Jun 12, 2019
1 parent 227f1dc commit 808b717
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 30 deletions.
60 changes: 40 additions & 20 deletions cmd/cpu-device-plugin/cpu-device-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,11 @@ func newCPUDeviceManager(poolName string, pool types.Pool, sharedCPUs string) *c
}
}

func createPluginsForPools() error {
files, err := filepath.Glob(filepath.Join(pluginapi.DevicePluginPath, "cpudp*"))
if err != nil {
glog.Fatal(err)
}
for _, f := range files {
if err := os.Remove(f); err != nil {
glog.Fatal(err)
}
}
poolConf, _, err := types.DeterminePoolConfig()
if err != nil {
glog.Fatal(err)
}
glog.Infof("Pool configuration %v", poolConf)
func validatePools(poolConf types.PoolConfig) (string, error) {
var sharedCPUs string
var err error
for poolName, pool := range poolConf.Pools {
poolType := types.DeterminePoolType(poolName)
//Deault or unrecognizable pools need not be made available to Device Manager as schedulable devices
if poolType == types.DefaultPoolID {
continue
}
if poolType == types.SharedPoolID {
if sharedCPUs != "" {
err = fmt.Errorf("Only one shared pool allowed")
Expand All @@ -205,7 +188,20 @@ func createPluginsForPools() error {
}
sharedCPUs = pool.CPUs.String()
}
}
return sharedCPUs, err
}

func createCDMs(poolConf types.PoolConfig, sharedCPUs string) error {
var err error
for poolName, pool := range poolConf.Pools {
poolType := types.DeterminePoolType(poolName)
//Deault or unrecognizable pools need not be made available to Device Manager as schedulable devices
if poolType == types.DefaultPoolID {
continue
}
cdm := newCPUDeviceManager(poolName, pool, sharedCPUs)
cdms = append(cdms, cdm)
if err := cdm.Start(); err != nil {
glog.Errorf("cpuDeviceManager.Start() failed: %v", err)
break
Expand All @@ -218,10 +214,34 @@ func createPluginsForPools() error {
glog.Error(err)
break
}
cdms = append(cdms, cdm)
glog.Infof("CPU device plugin registered with the Kubelet")
}
return err
}

func createPluginsForPools() error {
files, err := filepath.Glob(filepath.Join(pluginapi.DevicePluginPath, "cpudp*"))
if err != nil {
glog.Fatal(err)
}
for _, f := range files {
if err := os.Remove(f); err != nil {
glog.Fatal(err)
}
}
poolConf, _, err := types.DeterminePoolConfig()
if err != nil {
glog.Fatal(err)
}
glog.Infof("Pool configuration %v", poolConf)

var sharedCPUs string
sharedCPUs, err = validatePools(poolConf)
if err != nil {
return err
}

if err := createCDMs(poolConf, sharedCPUs); err != nil {
for _, cdm := range cdms {
cdm.Stop()
}
Expand Down
20 changes: 10 additions & 10 deletions cmd/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ func validateAnnotation(poolRequests poolRequestMap, cpuAnnotation types.CPUAnno

func patchCPULimit(sharedCPUTime int, patchList []patch, i int, c *corev1.Container) []patch {
var patchItem patch
patchItem.Op = "add"

patchItem.Op = "replace"
cpuVal := `"` + strconv.Itoa(sharedCPUTime) + `m"`
if len(c.Resources.Limits) > 0 {
patchItem.Path = "/spec/containers/" + strconv.Itoa(i) + "/resources/limits/cpu"
patchItem.Value =
json.RawMessage(cpuVal)
} else {
patchItem.Path = "/spec/containers/" + strconv.Itoa(i) + "/resources"
patchItem.Value = json.RawMessage(`{ "limits": { "cpu":` + cpuVal + ` } }`)
}
patchItem.Path = "/spec/containers/" + strconv.Itoa(i) + "/resources/limits/cpu"
patchItem.Value = json.RawMessage(cpuVal)
patchList = append(patchList, patchItem)
return patchList

patchItem.Op = "replace"
cpuVal = `"0m"`
patchItem.Path = "/spec/containers/" + strconv.Itoa(i) + "/resources/requests/cpu"
patchItem.Value = json.RawMessage(cpuVal)
patchList = append(patchList, patchItem)

return patchList
}

func patchContainerForPinning(cpuAnnotation types.CPUAnnotation, patchList []patch, i int, c *corev1.Container) ([]patch, error) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/sethandler/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ func (setHandler *SetHandler) applyCpusetToContainer(containerID string, cpuset
return errors.New("cpuset file does not exist for container:" + trimmedCid + " under the provided cgroupfs hierarchy:" + setHandler.cpusetRoot)
}
//And for our grand finale, we just "echo" the calculated cpuset to the cpuset cgroupfs "file" of the given container
//Find child cpuset if it exists (kube-proxy)
filepath.Walk(pathToContainerCpusetFile, func(path string, f os.FileInfo, err error) error {
if f.IsDir() {
pathToContainerCpusetFile = path
}
return nil
})
file, err := os.OpenFile(pathToContainerCpusetFile + "/cpuset.cpus", os.O_WRONLY|os.O_SYNC, 0755)
if err != nil {
return errors.New("Can't open cpuset file:" + pathToContainerCpusetFile + " for container:" + trimmedCid + " because:" + err.Error())
Expand Down

0 comments on commit 808b717

Please sign in to comment.