@@ -3,6 +3,7 @@ package scheduler
33import (
44 "context"
55 "fmt"
6+ "strings"
67 "time"
78
89 "github.com/go-logr/logr"
@@ -221,7 +222,15 @@ func (s *Scheduler) ScheduleOne(ctx context.Context) {
221222 return
222223 }
223224
224- result := framework .NewSchedulerResult (vmid , node )
225+ // select vm storage to be used for vm image
226+ // must be done after node selection as some storages may not be available on some nodes
227+ storage , err := s .SelectStorage (qemuCtx , * config , node )
228+ if err != nil {
229+ state .UpdateState (true , err , framework.SchedulerResult {})
230+ return
231+ }
232+
233+ result := framework .NewSchedulerResult (vmid , node , storage )
225234 state .UpdateState (true , nil , result )
226235}
227236
@@ -271,7 +280,7 @@ func (s *Scheduler) CreateQEMU(ctx context.Context, config *api.VirtualMachineCr
271280
272281func (s * Scheduler ) SelectNode (ctx context.Context , config api.VirtualMachineCreateOptions ) (string , error ) {
273282 s .logger .Info ("finding proxmox node matching qemu" )
274- nodes , err := s .client .Nodes (ctx )
283+ nodes , err := s .client .GetNodes (ctx )
275284 if err != nil {
276285 return "" , err
277286 }
@@ -316,6 +325,33 @@ func (s *Scheduler) SelectVMID(ctx context.Context, config api.VirtualMachineCre
316325 return s .RunVMIDPlugins (ctx , nil , config , nextid , * usedID )
317326}
318327
328+ func (s * Scheduler ) SelectStorage (ctx context.Context , config api.VirtualMachineCreateOptions , nodeName string ) (string , error ) {
329+ s .logger .Info ("finding proxmox storage to be used for qemu" )
330+ if config .Storage != "" {
331+ // to do: raise error if storage is not available on the node
332+ return config .Storage , nil
333+ }
334+
335+ node , err := s .client .Node (ctx , nodeName )
336+ if err != nil {
337+ return "" , err
338+ }
339+ storages , err := node .GetStorages (ctx )
340+ if err != nil {
341+ return "" , err
342+ }
343+
344+ // current logic is just selecting the first storage
345+ // that is active and supports "images" type of content
346+ for _ , storage := range storages {
347+ if strings .Contains (storage .Content , "images" ) && storage .Active == 1 {
348+ return storage .Storage , nil
349+ }
350+ }
351+
352+ return "" , fmt .Errorf ("no storage available for VM image on node %s" , nodeName )
353+ }
354+
319355func (s * Scheduler ) RunFilterPlugins (ctx context.Context , state * framework.CycleState , config api.VirtualMachineCreateOptions , nodes []* api.Node ) ([]* api.Node , error ) {
320356 s .logger .Info ("filtering proxmox node" )
321357 feasibleNodes := make ([]* api.Node , 0 , len (nodes ))
0 commit comments