@@ -36,7 +36,6 @@ import (
3636 logger "sigs.k8s.io/controller-runtime/pkg/log"
3737
3838 "github.com/gophercloud/gophercloud/v2"
39- "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/flavors"
4039 "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/hypervisors"
4140 "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers"
4241 "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/services"
@@ -63,6 +62,7 @@ const (
6362type OnboardingController struct {
6463 k8sclient.Client
6564 Scheme * runtime.Scheme
65+ TestFlavorID string
6666 computeClient * gophercloud.ServiceClient
6767 testComputeClient * gophercloud.ServiceClient
6868 testImageClient * gophercloud.ServiceClient
@@ -490,10 +490,7 @@ func (r *OnboardingController) createOrGetTestServer(ctx context.Context, zone,
490490 return foundServer , nil
491491 }
492492
493- flavorRef , err := r .findTestFlavor (ctx )
494- if err != nil {
495- return nil , err
496- }
493+ flavorRef := r .TestFlavorID
497494
498495 imageRef , err := r .findTestImage (ctx )
499496 if err != nil {
@@ -576,35 +573,17 @@ func (r *OnboardingController) findTestImage(ctx context.Context) (string, error
576573 return "" , fmt .Errorf ("couldn't find image with name %v" , testImageName )
577574}
578575
579- func (r * OnboardingController ) findTestFlavor (ctx context.Context ) (string , error ) {
580- flavorPages , err := flavors .ListDetail (r .testComputeClient , flavors.ListOpts {SortDir : "asc" , SortKey : "memory_mb" }).AllPages (ctx )
581- if err != nil {
582- return "" , err
583- }
584-
585- extractedFlavors , err := flavors .ExtractFlavors (flavorPages )
586- if err != nil {
587- return "" , err
588- }
589-
590- for _ , flavor := range extractedFlavors {
591- _ , found := flavor .ExtraSpecs ["capabilities:hypervisor_type" ]
592- if ! found {
593- // Flavor does not restrict the hypervisor-type
594- return flavor .ID , nil
595- }
596- }
597-
598- return "" , errors .New ("couldn't find flavor" )
599- }
600-
601576func (r * OnboardingController ) patchStatus (ctx context.Context , hv , base * kvmv1.Hypervisor ) error {
602577 return r .Status ().Patch (ctx , hv , k8sclient .MergeFromWithOptions (base ,
603578 k8sclient.MergeFromWithOptimisticLock {}), k8sclient .FieldOwner (OnboardingControllerName ))
604579}
605580
606581// SetupWithManager sets up the controller with the Manager.
607582func (r * OnboardingController ) SetupWithManager (mgr ctrl.Manager ) error {
583+ if r .TestFlavorID == "" {
584+ r .TestFlavorID = "1"
585+ }
586+
608587 ctx := context .Background ()
609588
610589 var err error
0 commit comments