Skip to content

Commit 9be7e04

Browse files
committed
go fmt
1 parent e3a7b22 commit 9be7e04

File tree

5 files changed

+237
-237
lines changed

5 files changed

+237
-237
lines changed
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
package noderesource
2-
3-
import (
4-
"context"
5-
6-
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework"
7-
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/plugins/names"
8-
"github.com/sp-yduck/proxmox-go/api"
9-
)
10-
11-
type NodeResource struct{}
12-
13-
var _ framework.NodeScorePlugin = &NodeResource{}
14-
15-
const (
16-
Name = names.NodeResource
17-
)
18-
19-
func (pl *NodeResource) Name() string {
20-
return Name
21-
}
22-
23-
// score = 1/(cpu/maxcpu * mem/maxmem)
24-
func (pl *NodeResource) Score(ctx context.Context, state *framework.CycleState, _ api.VirtualMachineCreateOptions, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
25-
cpu := nodeInfo.Node().Cpu
26-
maxCPU := nodeInfo.Node().MaxCpu
27-
mem := nodeInfo.Node().Mem
28-
maxMem := nodeInfo.Node().MaxMem
29-
u := cpu / float32(maxCPU) * float32(mem/maxMem)
30-
score := int64(1 / u)
31-
return score, nil
32-
}
1+
package noderesource
2+
3+
import (
4+
"context"
5+
6+
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework"
7+
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/plugins/names"
8+
"github.com/sp-yduck/proxmox-go/api"
9+
)
10+
11+
type NodeResource struct{}
12+
13+
var _ framework.NodeScorePlugin = &NodeResource{}
14+
15+
const (
16+
Name = names.NodeResource
17+
)
18+
19+
func (pl *NodeResource) Name() string {
20+
return Name
21+
}
22+
23+
// score = 1/(cpu/maxcpu * mem/maxmem)
24+
func (pl *NodeResource) Score(ctx context.Context, state *framework.CycleState, _ api.VirtualMachineCreateOptions, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
25+
cpu := nodeInfo.Node().Cpu
26+
maxCPU := nodeInfo.Node().MaxCpu
27+
mem := nodeInfo.Node().Mem
28+
maxMem := nodeInfo.Node().MaxMem
29+
u := cpu / float32(maxCPU) * float32(mem/maxMem)
30+
score := int64(1 / u)
31+
return score, nil
32+
}
Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
package overcommit
2-
3-
import (
4-
"context"
5-
6-
"github.com/sp-yduck/proxmox-go/api"
7-
8-
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework"
9-
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/plugins/names"
10-
)
11-
12-
type CPUOvercommit struct{}
13-
14-
var _ framework.NodeFilterPlugin = &CPUOvercommit{}
15-
16-
const (
17-
CPUOvercommitName = names.CPUOvercommit
18-
defaultCPUOvercommitRatio = 4
19-
)
20-
21-
func (pl *CPUOvercommit) Name() string {
22-
return CPUOvercommitName
23-
}
24-
25-
// filter by cpu overcommit ratio
26-
func (pl *CPUOvercommit) Filter(ctx context.Context, _ *framework.CycleState, config api.VirtualMachineCreateOptions, nodeInfo *framework.NodeInfo) *framework.Status {
27-
cpu := sumCPUs(nodeInfo.QEMUs())
28-
maxCPU := nodeInfo.Node().MaxCpu
29-
sockets := config.Sockets
30-
if sockets == 0 {
31-
sockets = 1
32-
}
33-
ratio := float32(cpu+config.Cores*sockets) / float32(maxCPU)
34-
if ratio > defaultCPUOvercommitRatio {
35-
status := framework.NewStatus()
36-
status.SetCode(1)
37-
return status
38-
}
39-
return &framework.Status{}
40-
}
41-
42-
func sumCPUs(qemus []*api.VirtualMachine) int {
43-
var result int
44-
for _, q := range qemus {
45-
result += q.Cpus
46-
}
47-
return result
48-
}
1+
package overcommit
2+
3+
import (
4+
"context"
5+
6+
"github.com/sp-yduck/proxmox-go/api"
7+
8+
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework"
9+
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/plugins/names"
10+
)
11+
12+
type CPUOvercommit struct{}
13+
14+
var _ framework.NodeFilterPlugin = &CPUOvercommit{}
15+
16+
const (
17+
CPUOvercommitName = names.CPUOvercommit
18+
defaultCPUOvercommitRatio = 4
19+
)
20+
21+
func (pl *CPUOvercommit) Name() string {
22+
return CPUOvercommitName
23+
}
24+
25+
// filter by cpu overcommit ratio
26+
func (pl *CPUOvercommit) Filter(ctx context.Context, _ *framework.CycleState, config api.VirtualMachineCreateOptions, nodeInfo *framework.NodeInfo) *framework.Status {
27+
cpu := sumCPUs(nodeInfo.QEMUs())
28+
maxCPU := nodeInfo.Node().MaxCpu
29+
sockets := config.Sockets
30+
if sockets == 0 {
31+
sockets = 1
32+
}
33+
ratio := float32(cpu+config.Cores*sockets) / float32(maxCPU)
34+
if ratio > defaultCPUOvercommitRatio {
35+
status := framework.NewStatus()
36+
status.SetCode(1)
37+
return status
38+
}
39+
return &framework.Status{}
40+
}
41+
42+
func sumCPUs(qemus []*api.VirtualMachine) int {
43+
var result int
44+
for _, q := range qemus {
45+
result += q.Cpus
46+
}
47+
return result
48+
}
Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
package overcommit
2-
3-
import (
4-
"context"
5-
6-
"github.com/sp-yduck/proxmox-go/api"
7-
8-
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework"
9-
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/plugins/names"
10-
)
11-
12-
type MemoryOvercommit struct{}
13-
14-
var _ framework.NodeFilterPlugin = &MemoryOvercommit{}
15-
16-
const (
17-
MemoryOvercommitName = names.MemoryOvercommit
18-
defaultMemoryOvercommitRatio = 1
19-
)
20-
21-
func (pl *MemoryOvercommit) Name() string {
22-
return MemoryOvercommitName
23-
}
24-
25-
// filter by memory overcommit ratio
26-
func (pl *MemoryOvercommit) Filter(ctx context.Context, _ *framework.CycleState, config api.VirtualMachineCreateOptions, nodeInfo *framework.NodeInfo) *framework.Status {
27-
mem := sumMems(nodeInfo.QEMUs())
28-
maxMem := nodeInfo.Node().MaxMem
29-
ratio := float32(mem+1024*1024*config.Memory) / float32(maxMem)
30-
if ratio >= defaultMemoryOvercommitRatio {
31-
status := framework.NewStatus()
32-
status.SetCode(1)
33-
return status
34-
}
35-
return &framework.Status{}
36-
}
37-
38-
func sumMems(qemus []*api.VirtualMachine) int {
39-
var result int
40-
for _, q := range qemus {
41-
result += q.MaxMem
42-
}
43-
return result
44-
}
1+
package overcommit
2+
3+
import (
4+
"context"
5+
6+
"github.com/sp-yduck/proxmox-go/api"
7+
8+
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework"
9+
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/plugins/names"
10+
)
11+
12+
type MemoryOvercommit struct{}
13+
14+
var _ framework.NodeFilterPlugin = &MemoryOvercommit{}
15+
16+
const (
17+
MemoryOvercommitName = names.MemoryOvercommit
18+
defaultMemoryOvercommitRatio = 1
19+
)
20+
21+
func (pl *MemoryOvercommit) Name() string {
22+
return MemoryOvercommitName
23+
}
24+
25+
// filter by memory overcommit ratio
26+
func (pl *MemoryOvercommit) Filter(ctx context.Context, _ *framework.CycleState, config api.VirtualMachineCreateOptions, nodeInfo *framework.NodeInfo) *framework.Status {
27+
mem := sumMems(nodeInfo.QEMUs())
28+
maxMem := nodeInfo.Node().MaxMem
29+
ratio := float32(mem+1024*1024*config.Memory) / float32(maxMem)
30+
if ratio >= defaultMemoryOvercommitRatio {
31+
status := framework.NewStatus()
32+
status.SetCode(1)
33+
return status
34+
}
35+
return &framework.Status{}
36+
}
37+
38+
func sumMems(qemus []*api.VirtualMachine) int {
39+
var result int
40+
for _, q := range qemus {
41+
result += q.MaxMem
42+
}
43+
return result
44+
}
Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
package regex
2-
3-
import (
4-
"context"
5-
"fmt"
6-
"regexp"
7-
8-
"github.com/sp-yduck/proxmox-go/api"
9-
10-
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework"
11-
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/plugins/names"
12-
)
13-
14-
type NodeRegex struct{}
15-
16-
var _ framework.NodeFilterPlugin = &NodeRegex{}
17-
18-
const (
19-
NodeRegexName = names.NodeRegex
20-
NodeRegexKey = "node.qemu-scheduler/regex"
21-
)
22-
23-
func (pl *NodeRegex) Name() string {
24-
return NodeRegexName
25-
}
26-
27-
// regex is specified in ctx value (key=node.qemu-scheduler/regex)
28-
func (pl *NodeRegex) Filter(ctx context.Context, _ *framework.CycleState, config api.VirtualMachineCreateOptions, nodeInfo *framework.NodeInfo) *framework.Status {
29-
reg, err := findNodeRegex(ctx)
30-
if err != nil {
31-
32-
return &framework.Status{}
33-
}
34-
if !reg.MatchString(nodeInfo.Node().Node) {
35-
status := framework.NewStatus()
36-
status.SetCode(1)
37-
return status
38-
}
39-
return &framework.Status{}
40-
}
41-
42-
// specify available node name as regex
43-
// example: node.qemu-scheduler/regex=node[0-9]+
44-
func findNodeRegex(ctx context.Context) (*regexp.Regexp, error) {
45-
value := ctx.Value(framework.CtxKey(NodeRegexKey))
46-
if value == nil {
47-
return nil, fmt.Errorf("no node name regex is specified")
48-
}
49-
reg, err := regexp.Compile(fmt.Sprintf("%s", value))
50-
if err != nil {
51-
return nil, err
52-
}
53-
return reg, nil
54-
}
1+
package regex
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"regexp"
7+
8+
"github.com/sp-yduck/proxmox-go/api"
9+
10+
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework"
11+
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/plugins/names"
12+
)
13+
14+
type NodeRegex struct{}
15+
16+
var _ framework.NodeFilterPlugin = &NodeRegex{}
17+
18+
const (
19+
NodeRegexName = names.NodeRegex
20+
NodeRegexKey = "node.qemu-scheduler/regex"
21+
)
22+
23+
func (pl *NodeRegex) Name() string {
24+
return NodeRegexName
25+
}
26+
27+
// regex is specified in ctx value (key=node.qemu-scheduler/regex)
28+
func (pl *NodeRegex) Filter(ctx context.Context, _ *framework.CycleState, config api.VirtualMachineCreateOptions, nodeInfo *framework.NodeInfo) *framework.Status {
29+
reg, err := findNodeRegex(ctx)
30+
if err != nil {
31+
32+
return &framework.Status{}
33+
}
34+
if !reg.MatchString(nodeInfo.Node().Node) {
35+
status := framework.NewStatus()
36+
status.SetCode(1)
37+
return status
38+
}
39+
return &framework.Status{}
40+
}
41+
42+
// specify available node name as regex
43+
// example: node.qemu-scheduler/regex=node[0-9]+
44+
func findNodeRegex(ctx context.Context) (*regexp.Regexp, error) {
45+
value := ctx.Value(framework.CtxKey(NodeRegexKey))
46+
if value == nil {
47+
return nil, fmt.Errorf("no node name regex is specified")
48+
}
49+
reg, err := regexp.Compile(fmt.Sprintf("%s", value))
50+
if err != nil {
51+
return nil, err
52+
}
53+
return reg, nil
54+
}

0 commit comments

Comments
 (0)