sigs.k8s.io/kueue@v0.6.2/test/integration/controller/jobs/mxjob/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 mxjob 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/mxjob" 37 "sigs.k8s.io/kueue/pkg/queue" 38 "sigs.k8s.io/kueue/pkg/scheduler" 39 "sigs.k8s.io/kueue/test/integration/framework" 40 ) 41 42 var ( 43 cfg *rest.Config 44 k8sClient client.Client 45 ctx context.Context 46 fwk *framework.Framework 47 crdPath = filepath.Join("..", "..", "..", "..", "..", "config", "components", "crd", "bases") 48 mxnetCrdPath = filepath.Join("..", "..", "..", "..", "..", "dep-crds", "training-operator") 49 ) 50 51 func TestAPIs(t *testing.T) { 52 gomega.RegisterFailHandler(ginkgo.Fail) 53 54 ginkgo.RunSpecs(t, 55 "MXJob Controller Suite", 56 ) 57 } 58 59 func managerSetup(opts ...jobframework.Option) framework.ManagerSetup { 60 return func(mgr manager.Manager, ctx context.Context) { 61 reconciler := mxjob.NewReconciler( 62 mgr.GetClient(), 63 mgr.GetEventRecorderFor(constants.JobControllerName), 64 opts...) 65 err := mxjob.SetupIndexes(ctx, mgr.GetFieldIndexer()) 66 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 67 err = reconciler.SetupWithManager(mgr) 68 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 69 err = mxjob.SetupMXJobWebhook(mgr, opts...) 70 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 71 } 72 } 73 74 func managerAndSchedulerSetup(opts ...jobframework.Option) framework.ManagerSetup { 75 return func(mgr manager.Manager, ctx context.Context) { 76 err := indexer.Setup(ctx, mgr.GetFieldIndexer()) 77 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 78 79 cCache := cache.New(mgr.GetClient()) 80 queues := queue.NewManager(mgr.GetClient(), cCache) 81 82 configuration := &config.Configuration{} 83 mgr.GetScheme().Default(configuration) 84 85 failedCtrl, err := core.SetupControllers(mgr, queues, cCache, configuration) 86 gomega.Expect(err).ToNot(gomega.HaveOccurred(), "controller", failedCtrl) 87 88 err = mxjob.SetupIndexes(ctx, mgr.GetFieldIndexer()) 89 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 90 err = mxjob.NewReconciler(mgr.GetClient(), 91 mgr.GetEventRecorderFor(constants.JobControllerName), opts...).SetupWithManager(mgr) 92 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 93 err = mxjob.SetupMXJobWebhook(mgr, opts...) 94 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 95 96 sched := scheduler.New(queues, cCache, mgr.GetClient(), mgr.GetEventRecorderFor(constants.AdmissionName)) 97 err = sched.Start(ctx) 98 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 99 } 100 }