@@ -30,37 +30,68 @@ func NewManager(params SchedulerParams) *Manager {
3030
3131func (m * Manager ) NewScheduler (client * proxmox.Service ) * Scheduler {
3232 logger := m .params .Logger .WithName ("[qemu-scheduler]" )
33- nodeScheduler := NodeScheduler {filterPlugins : plugins .NewNodeFilterPlugins (), scorePlugins : plugins .NewNodeScorePlugins ()}
34- return & Scheduler {client : client , nodeScheduler : nodeScheduler , logger : logger }
33+ return & Scheduler {client : client , logger : logger }
3534}
3635
3736type Scheduler struct {
38- client * proxmox.Service
39- nodeScheduler NodeScheduler
40- vmidScheduler VMIDScheduler
41- logger logr.Logger
37+ client * proxmox.Service
38+ logger logr.Logger
4239}
4340
4441type SchedulerParams struct {
4542 Logger logr.Logger
4643}
4744
4845type NodeScheduler struct {
46+ client * proxmox.Service
4947 filterPlugins []framework.NodeFilterPlugin
5048 scorePlugins []framework.NodeScorePlugin
49+ logger logr.Logger
5150}
5251
5352type VMIDScheduler struct {
53+ client * proxmox.Service
54+ plugin framework.VMIDPlugin
55+ logger logr.Logger
5456}
5557
56- // just poc codes
57- // return nextID fetched from Proxmox rest API nextID endpoint
58- func (s * Scheduler ) GetID (ctx context.Context ) (int , error ) {
59- return s .client .RESTClient ().GetNextID (ctx )
58+ func (s * Scheduler ) NewNodeScheduler () NodeScheduler {
59+ return NodeScheduler {
60+ client : s .client ,
61+ filterPlugins : plugins .NewNodeFilterPlugins (),
62+ scorePlugins : plugins .NewNodeScorePlugins (),
63+ logger : s .logger .WithValues ("qemu-scheduler" , "node" ),
64+ }
65+ }
66+
67+ func (s * Scheduler ) NewVMIDScheduler (name string ) (VMIDScheduler , error ) {
68+ plugin , err := plugins .NewVMIDPlugin (s .client , name )
69+ if err != nil {
70+ return VMIDScheduler {}, err
71+ }
72+ return VMIDScheduler {
73+ client : s .client ,
74+ plugin : plugin ,
75+ logger : s .logger .WithValues ("qemu-scheduler" , "vmid" ),
76+ }, nil
6077}
6178
6279func (s * Scheduler ) SelectNode (ctx context.Context , config api.VirtualMachineCreateOptions ) (string , error ) {
6380 s .logger .Info ("finding proxmox node matching qemu" )
81+ sched := s .NewNodeScheduler ()
82+ return sched .run (ctx , config )
83+ }
84+
85+ func (s * Scheduler ) SelectVMID (ctx context.Context , config api.VirtualMachineCreateOptions ) (int , error ) {
86+ s .logger .Info ("finding proxmox vmid to be assigned to qemu" )
87+ sched , err := s .NewVMIDScheduler ("NextID" )
88+ if err != nil {
89+ return 0 , err
90+ }
91+ return sched .run (ctx , config )
92+ }
93+
94+ func (s * NodeScheduler ) run (ctx context.Context , config api.VirtualMachineCreateOptions ) (string , error ) {
6495 nodes , err := s .client .Nodes (ctx )
6596 if err != nil {
6697 return "" , err
@@ -88,7 +119,7 @@ func (s *Scheduler) SelectNode(ctx context.Context, config api.VirtualMachineCre
88119 return selectedNode , nil
89120}
90121
91- func (s * Scheduler ) RunFilterPlugins (ctx context.Context , state * framework.CycleState , config api.VirtualMachineCreateOptions , nodes []* api.Node ) ([]* api.Node , error ) {
122+ func (s * NodeScheduler ) RunFilterPlugins (ctx context.Context , state * framework.CycleState , config api.VirtualMachineCreateOptions , nodes []* api.Node ) ([]* api.Node , error ) {
92123 s .logger .Info ("filtering proxmox node" )
93124 feasibleNodes := make ([]* api.Node , 0 , len (nodes ))
94125 nodeInfos , err := framework .GetNodeInfoList (ctx , s .client )
@@ -97,7 +128,7 @@ func (s *Scheduler) RunFilterPlugins(ctx context.Context, state *framework.Cycle
97128 }
98129 for _ , nodeInfo := range nodeInfos {
99130 status := framework .NewStatus ()
100- for _ , pl := range s .nodeScheduler . filterPlugins {
131+ for _ , pl := range s .filterPlugins {
101132 status = pl .Filter (ctx , state , config , nodeInfo )
102133 if ! status .IsSuccess () {
103134 status .SetFailedPlugin (pl .Name ())
@@ -111,7 +142,7 @@ func (s *Scheduler) RunFilterPlugins(ctx context.Context, state *framework.Cycle
111142 return feasibleNodes , nil
112143}
113144
114- func (s * Scheduler ) RunScorePlugins (ctx context.Context , state * framework.CycleState , config api.VirtualMachineCreateOptions , nodes []* api.Node ) (framework.NodeScoreList , * framework.Status ) {
145+ func (s * NodeScheduler ) RunScorePlugins (ctx context.Context , state * framework.CycleState , config api.VirtualMachineCreateOptions , nodes []* api.Node ) (framework.NodeScoreList , * framework.Status ) {
115146 s .logger .Info ("scoring proxmox node" )
116147 var scoresMap map [string ](map [int ]framework.NodeScore )
117148 nodeInfos , err := framework .GetNodeInfoList (ctx , s .client )
@@ -121,7 +152,7 @@ func (s *Scheduler) RunScorePlugins(ctx context.Context, state *framework.CycleS
121152 return nil , status
122153 }
123154 for index , nodeInfo := range nodeInfos {
124- for _ , pl := range s .nodeScheduler . scorePlugins {
155+ for _ , pl := range s .scorePlugins {
125156 score , status := pl .Score (ctx , state , config , nodeInfo )
126157 if ! status .IsSuccess () {
127158 return nil , status
@@ -154,3 +185,7 @@ func selectHighestScoreNode(scoreList framework.NodeScoreList) (string, error) {
154185 }
155186 return selectedScore .Name , nil
156187}
188+
189+ func (s * VMIDScheduler ) run (ctx context.Context , config api.VirtualMachineCreateOptions ) (int , error ) {
190+ return s .plugin .Select (ctx , nil , config )
191+ }
0 commit comments