-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcpu_overcommit.go
52 lines (43 loc) · 1.28 KB
/
cpu_overcommit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package overcommit
import (
"context"
"github.com/k8s-proxmox/proxmox-go/api"
"github.com/k8s-proxmox/cluster-api-provider-proxmox/cloud/scheduler/framework"
"github.com/k8s-proxmox/cluster-api-provider-proxmox/cloud/scheduler/plugins/names"
)
type CPUOvercommit struct{}
var _ framework.NodeFilterPlugin = &CPUOvercommit{}
const (
CPUOvercommitName = names.CPUOvercommit
defaultCPUOvercommitRatio = 4
)
func (pl *CPUOvercommit) Name() string {
return CPUOvercommitName
}
// filter by cpu overcommit ratio
func (pl *CPUOvercommit) Filter(ctx context.Context, state *framework.CycleState, config api.VirtualMachineCreateOptions, nodeInfo *framework.NodeInfo) *framework.Status {
cpu := sumCPUs(nodeInfo.QEMUs())
maxCPU := nodeInfo.Node().MaxCpu
sockets := config.Sockets
if sockets == 0 {
sockets = 1
}
ratio := float32(cpu+config.Cores*sockets) / float32(maxCPU)
if ratio > defaultCPUOvercommitRatio {
status := framework.NewStatus()
status.SetCode(1)
state.SetMessage(pl.Name(), "exceed cpu overcommit ratio")
return status
}
return &framework.Status{}
}
// sum cpus of all 'running' qemu
func sumCPUs(qemus []*api.VirtualMachine) int {
var result int
for _, q := range qemus {
if q.Status == api.ProcessStatusRunning {
result += q.Cpus
}
}
return result
}