Skip to content

Commit 00196a7

Browse files
committed
implement first 2 vmid scheduler plugin
1 parent 1995bcb commit 00196a7

File tree

13 files changed

+880
-778
lines changed

13 files changed

+880
-778
lines changed

cloud/scheduler/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
11
# qemu-scheduler
22

33
Scheduling refers to making sure that VM(QEMU) are matched to Proxmox Nodes.
4+
5+
## How to specify vmid
6+
qemu-scheduler reads context and find key registerd to scheduler. If the context has any value of the registerd key, qemu-scheduler uses the plugin that matchies the key.
7+
8+
### Range Plugin
9+
You can specify vmid range with `(start id)-(end id)` format.
10+
```
11+
key: vmid.qemu-scheduler/range
12+
value(example): 100-150
13+
```
14+
15+
### Regex Plugin
16+
```
17+
key: vmid.qemu-scheduler/regex
18+
value(example): (12[0-9]|130)
19+
```
20+
21+
## How qemu-scheduler works with CAPPX
22+
CAPPX passes all the annotation (of `ProxmoxMachine`) key-values to scheduler's context. So if you will use Range Plugin for your `ProxmoxMachine`, your manifest must look like following.
23+
```sh
24+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
25+
kind: ProxmoxMachine
26+
metadata:
27+
name: sample-machine
28+
annotations:
29+
vmid.qemu-scheduler/range: 100-150 # this means your vmid will be chosen from the range of 100 to 150.
30+
```
31+
32+
Also, you can specifies these annotations via `MachineDeployment` since Cluster API propagates some metadatas (ref: [metadata-propagation](https://cluster-api.sigs.k8s.io/developer/architecture/controllers/metadata-propagation.html#metadata-propagation)).
33+
34+
For example, your `MachineDeployment` may look like following.
35+
```sh
36+
apiVersion: cluster.x-k8s.io/v1beta1
37+
kind: MachineDeployment
38+
metadata:
39+
annotations:
40+
caution: "# do not use here, because this annotation won't be propagated to your ProxmoxMachine"
41+
name: sample-machine-deployment
42+
spec:
43+
template:
44+
metadata:
45+
annotations:
46+
vmid.qemu-scheduler/range: 100-150 # this annotation will be propagated to your ProxmoxMachine via MachineSet
47+
```
Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
1-
package framework
2-
3-
import (
4-
"github.com/sp-yduck/proxmox-go/api"
5-
"github.com/sp-yduck/proxmox-go/proxmox"
6-
)
7-
8-
type CycleState struct {
9-
completed bool
10-
err error
11-
result SchedulerResult
12-
}
13-
14-
type SchedulerResult struct {
15-
vmid int
16-
node string
17-
instance *proxmox.VirtualMachine
18-
}
19-
20-
func NewCycleState() CycleState {
21-
return CycleState{completed: false, err: nil}
22-
}
23-
24-
func (c *CycleState) SetComplete() {
25-
c.completed = true
26-
}
27-
28-
func (c *CycleState) IsCompleted() bool {
29-
return c.completed
30-
}
31-
32-
func (c *CycleState) SetError(err error) {
33-
c.err = err
34-
}
35-
36-
func (c *CycleState) Error() error {
37-
return c.err
38-
}
39-
40-
func (c *CycleState) QEMU() *api.VirtualMachine {
41-
return c.result.instance.VM
42-
}
43-
44-
func (c *CycleState) UpdateState(completed bool, err error, result *SchedulerResult) {
45-
c.completed = completed
46-
c.err = err
47-
c.result = *result
48-
}
49-
50-
func NewSchedulerResult(vmid int, node string, instance *proxmox.VirtualMachine) SchedulerResult {
51-
return SchedulerResult{vmid: vmid, node: node, instance: instance}
52-
}
53-
54-
func (c *CycleState) Result() SchedulerResult {
55-
return c.result
56-
}
57-
58-
func (r *SchedulerResult) Node() string {
59-
return r.node
60-
}
61-
62-
func (r *SchedulerResult) VMID() int {
63-
return r.vmid
64-
}
65-
66-
func (r *SchedulerResult) Instance() *proxmox.VirtualMachine {
67-
return r.instance
68-
}
1+
package framework
2+
3+
import (
4+
"github.com/sp-yduck/proxmox-go/api"
5+
"github.com/sp-yduck/proxmox-go/proxmox"
6+
)
7+
8+
type CycleState struct {
9+
completed bool
10+
err error
11+
result SchedulerResult
12+
}
13+
14+
type SchedulerResult struct {
15+
vmid int
16+
node string
17+
instance *proxmox.VirtualMachine
18+
}
19+
20+
func NewCycleState() CycleState {
21+
return CycleState{completed: false, err: nil}
22+
}
23+
24+
func (c *CycleState) SetComplete() {
25+
c.completed = true
26+
}
27+
28+
func (c *CycleState) IsCompleted() bool {
29+
return c.completed
30+
}
31+
32+
func (c *CycleState) SetError(err error) {
33+
c.err = err
34+
}
35+
36+
func (c *CycleState) Error() error {
37+
return c.err
38+
}
39+
40+
func (c *CycleState) QEMU() *api.VirtualMachine {
41+
return c.result.instance.VM
42+
}
43+
44+
func (c *CycleState) UpdateState(completed bool, err error, result *SchedulerResult) {
45+
c.completed = completed
46+
c.err = err
47+
c.result = *result
48+
}
49+
50+
func NewSchedulerResult(vmid int, node string, instance *proxmox.VirtualMachine) SchedulerResult {
51+
return SchedulerResult{vmid: vmid, node: node, instance: instance}
52+
}
53+
54+
func (c *CycleState) Result() SchedulerResult {
55+
return c.result
56+
}
57+
58+
func (r *SchedulerResult) Node() string {
59+
return r.node
60+
}
61+
62+
func (r *SchedulerResult) VMID() int {
63+
return r.vmid
64+
}
65+
66+
func (r *SchedulerResult) Instance() *proxmox.VirtualMachine {
67+
return r.instance
68+
}
Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
package framework
2-
3-
import (
4-
"context"
5-
6-
"github.com/sp-yduck/proxmox-go/api"
7-
)
8-
9-
type Plugin interface {
10-
// return plugin name
11-
Name() string
12-
}
13-
14-
type NodeFilterPlugin interface {
15-
Plugin
16-
Filter(ctx context.Context, state *CycleState, config api.VirtualMachineCreateOptions, nodeInfo *NodeInfo) *Status
17-
}
18-
19-
type NodeScorePlugin interface {
20-
Plugin
21-
Score(ctx context.Context, state *CycleState, config api.VirtualMachineCreateOptions, nodeInfo *NodeInfo) (int64, *Status)
22-
}
23-
24-
type VMIDPlugin interface {
25-
Plugin
26-
Select(ctx context.Context, state *CycleState, config api.VirtualMachineCreateOptions) (int, error)
27-
}
1+
package framework
2+
3+
import (
4+
"context"
5+
6+
"github.com/sp-yduck/proxmox-go/api"
7+
)
8+
9+
type Plugin interface {
10+
// return plugin name
11+
Name() string
12+
}
13+
14+
type NodeFilterPlugin interface {
15+
Plugin
16+
Filter(ctx context.Context, state *CycleState, config api.VirtualMachineCreateOptions, nodeInfo *NodeInfo) *Status
17+
}
18+
19+
type NodeScorePlugin interface {
20+
Plugin
21+
Score(ctx context.Context, state *CycleState, config api.VirtualMachineCreateOptions, nodeInfo *NodeInfo) (int64, *Status)
22+
}
23+
24+
type VMIDPlugin interface {
25+
Plugin
26+
PluginKey() CtxKey
27+
Select(ctx context.Context, state *CycleState, config api.VirtualMachineCreateOptions, nextid int, usedID map[int]bool) (int, error)
28+
}

0 commit comments

Comments
 (0)