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

     1  /*
     2  Copyright 2023 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 pytorchjob
    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  	"sigs.k8s.io/kueue/pkg/controller/jobframework"
    36  	"sigs.k8s.io/kueue/pkg/controller/jobs/kubeflow/jobs/pytorchjob"
    37  	"sigs.k8s.io/kueue/pkg/queue"
    38  	"sigs.k8s.io/kueue/pkg/scheduler"
    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  	crdPath        = filepath.Join("..", "..", "..", "..", "..", "config", "components", "crd", "bases")
    49  	pytorchCrdPath = filepath.Join("..", "..", "..", "..", "..", "dep-crds", "training-operator")
    50  )
    51  
    52  func TestAPIs(t *testing.T) {
    53  	gomega.RegisterFailHandler(ginkgo.Fail)
    54  
    55  	ginkgo.RunSpecs(t,
    56  		"PyTorchJob Controller Suite",
    57  	)
    58  }
    59  
    60  func managerSetup(opts ...jobframework.Option) framework.ManagerSetup {
    61  	return func(mgr manager.Manager, ctx context.Context) {
    62  		reconciler := pytorchjob.NewReconciler(
    63  			mgr.GetClient(),
    64  			mgr.GetEventRecorderFor(constants.JobControllerName),
    65  			opts...)
    66  		err := pytorchjob.SetupIndexes(ctx, mgr.GetFieldIndexer())
    67  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    68  		err = reconciler.SetupWithManager(mgr)
    69  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    70  		err = pytorchjob.SetupPyTorchJobWebhook(mgr, opts...)
    71  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    72  	}
    73  }
    74  
    75  func managerAndSchedulerSetup(opts ...jobframework.Option) framework.ManagerSetup {
    76  	return func(mgr manager.Manager, ctx context.Context) {
    77  		err := indexer.Setup(ctx, mgr.GetFieldIndexer())
    78  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    79  
    80  		cCache := cache.New(mgr.GetClient())
    81  		queues := queue.NewManager(mgr.GetClient(), cCache)
    82  
    83  		configuration := &config.Configuration{}
    84  		mgr.GetScheme().Default(configuration)
    85  
    86  		failedCtrl, err := core.SetupControllers(mgr, queues, cCache, configuration)
    87  		gomega.Expect(err).ToNot(gomega.HaveOccurred(), "controller", failedCtrl)
    88  
    89  		err = pytorchjob.SetupIndexes(ctx, mgr.GetFieldIndexer())
    90  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    91  		err = pytorchjob.NewReconciler(mgr.GetClient(),
    92  			mgr.GetEventRecorderFor(constants.JobControllerName), opts...).SetupWithManager(mgr)
    93  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    94  		err = pytorchjob.SetupPyTorchJobWebhook(mgr, opts...)
    95  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    96  
    97  		sched := scheduler.New(queues, cCache, mgr.GetClient(), mgr.GetEventRecorderFor(constants.AdmissionName))
    98  		err = sched.Start(ctx)
    99  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
   100  	}
   101  }