sigs.k8s.io/kueue@v0.6.2/test/integration/scheduler/suite_test.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package scheduler
    18  
    19  import (
    20  	"context"
    21  	"path/filepath"
    22  	"testing"
    23  
    24  	"github.com/onsi/ginkgo/v2"
    25  	"github.com/onsi/gomega"
    26  	"k8s.io/client-go/rest"
    27  	"sigs.k8s.io/controller-runtime/pkg/client"
    28  	"sigs.k8s.io/controller-runtime/pkg/manager"
    29  
    30  	config "sigs.k8s.io/kueue/apis/config/v1beta1"
    31  	"sigs.k8s.io/kueue/pkg/cache"
    32  	"sigs.k8s.io/kueue/pkg/constants"
    33  	"sigs.k8s.io/kueue/pkg/controller/core"
    34  	"sigs.k8s.io/kueue/pkg/controller/core/indexer"
    35  	workloadjob "sigs.k8s.io/kueue/pkg/controller/jobs/job"
    36  	"sigs.k8s.io/kueue/pkg/queue"
    37  	"sigs.k8s.io/kueue/pkg/scheduler"
    38  	"sigs.k8s.io/kueue/pkg/webhooks"
    39  	"sigs.k8s.io/kueue/test/integration/framework"
    40  	// +kubebuilder:scaffold:imports
    41  )
    42  
    43  var (
    44  	cfg       *rest.Config
    45  	k8sClient client.Client
    46  	ctx       context.Context
    47  	fwk       *framework.Framework
    48  )
    49  
    50  func TestScheduler(t *testing.T) {
    51  	gomega.RegisterFailHandler(ginkgo.Fail)
    52  
    53  	ginkgo.RunSpecs(t,
    54  		"Scheduler Suite",
    55  	)
    56  }
    57  
    58  var _ = ginkgo.BeforeSuite(func() {
    59  	fwk = &framework.Framework{
    60  		CRDPath:     filepath.Join("..", "..", "..", "config", "components", "crd", "bases"),
    61  		WebhookPath: filepath.Join("..", "..", "..", "config", "components", "webhook"),
    62  	}
    63  	cfg = fwk.Init()
    64  	ctx, k8sClient = fwk.RunManager(cfg, managerAndSchedulerSetup)
    65  })
    66  
    67  var _ = ginkgo.AfterSuite(func() {
    68  	fwk.Teardown()
    69  })
    70  
    71  func managerAndSchedulerSetup(mgr manager.Manager, ctx context.Context) {
    72  	err := indexer.Setup(ctx, mgr.GetFieldIndexer())
    73  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    74  
    75  	cCache := cache.New(mgr.GetClient())
    76  	queues := queue.NewManager(mgr.GetClient(), cCache)
    77  
    78  	configuration := &config.Configuration{}
    79  	mgr.GetScheme().Default(configuration)
    80  
    81  	failedCtrl, err := core.SetupControllers(mgr, queues, cCache, configuration)
    82  	gomega.Expect(err).ToNot(gomega.HaveOccurred(), "controller", failedCtrl)
    83  
    84  	failedWebhook, err := webhooks.Setup(mgr)
    85  	gomega.Expect(err).ToNot(gomega.HaveOccurred(), "webhook", failedWebhook)
    86  
    87  	err = workloadjob.SetupIndexes(ctx, mgr.GetFieldIndexer())
    88  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    89  
    90  	sched := scheduler.New(queues, cCache, mgr.GetClient(), mgr.GetEventRecorderFor(constants.AdmissionName))
    91  	err = sched.Start(ctx)
    92  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    93  }