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