sigs.k8s.io/kueue@v0.6.2/test/integration/scheduler/podsready/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 podsready
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  	"time"
    23  
    24  	"github.com/onsi/ginkgo/v2"
    25  	"github.com/onsi/gomega"
    26  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    27  	"k8s.io/client-go/rest"
    28  	"k8s.io/utils/ptr"
    29  	"sigs.k8s.io/controller-runtime/pkg/client"
    30  	"sigs.k8s.io/controller-runtime/pkg/manager"
    31  
    32  	config "sigs.k8s.io/kueue/apis/config/v1beta1"
    33  	"sigs.k8s.io/kueue/pkg/cache"
    34  	"sigs.k8s.io/kueue/pkg/constants"
    35  	"sigs.k8s.io/kueue/pkg/controller/core"
    36  	"sigs.k8s.io/kueue/pkg/controller/core/indexer"
    37  	workloadjob "sigs.k8s.io/kueue/pkg/controller/jobs/job"
    38  	"sigs.k8s.io/kueue/pkg/queue"
    39  	"sigs.k8s.io/kueue/pkg/scheduler"
    40  	"sigs.k8s.io/kueue/pkg/webhooks"
    41  	"sigs.k8s.io/kueue/test/integration/framework"
    42  	// +kubebuilder:scaffold:imports
    43  )
    44  
    45  var (
    46  	cfg       *rest.Config
    47  	k8sClient client.Client
    48  	ctx       context.Context
    49  	fwk       *framework.Framework
    50  )
    51  
    52  func TestSchedulerWithWaitForPodsReady(t *testing.T) {
    53  	gomega.RegisterFailHandler(ginkgo.Fail)
    54  
    55  	ginkgo.RunSpecs(t,
    56  		"Scheduler with WaitForPodsReady Suite",
    57  	)
    58  }
    59  
    60  func managerAndSchedulerSetupWithTimeoutAdmission(
    61  	mgr manager.Manager,
    62  	ctx context.Context,
    63  	value time.Duration,
    64  	blockAdmission bool,
    65  	requeuingTimestamp config.RequeuingTimestamp,
    66  	requeuingBackoffLimitCount *int32,
    67  ) {
    68  	cfg := &config.Configuration{
    69  		WaitForPodsReady: &config.WaitForPodsReady{
    70  			Enable:         true,
    71  			BlockAdmission: &blockAdmission,
    72  			Timeout:        &metav1.Duration{Duration: value},
    73  			RequeuingStrategy: &config.RequeuingStrategy{
    74  				Timestamp:         ptr.To(requeuingTimestamp),
    75  				BackoffLimitCount: requeuingBackoffLimitCount,
    76  			},
    77  		},
    78  	}
    79  	mgr.GetScheme().Default(cfg)
    80  
    81  	err := indexer.Setup(ctx, mgr.GetFieldIndexer())
    82  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    83  
    84  	cCache := cache.New(mgr.GetClient(), cache.WithPodsReadyTracking(cfg.WaitForPodsReady.Enable && cfg.WaitForPodsReady.BlockAdmission != nil && *cfg.WaitForPodsReady.BlockAdmission))
    85  	queues := queue.NewManager(
    86  		mgr.GetClient(), cCache,
    87  		queue.WithPodsReadyRequeuingTimestamp(requeuingTimestamp),
    88  	)
    89  
    90  	failedCtrl, err := core.SetupControllers(mgr, queues, cCache, cfg)
    91  	gomega.Expect(err).ToNot(gomega.HaveOccurred(), "controller", failedCtrl)
    92  
    93  	failedWebhook, err := webhooks.Setup(mgr)
    94  	gomega.Expect(err).ToNot(gomega.HaveOccurred(), "webhook", failedWebhook)
    95  
    96  	err = workloadjob.SetupIndexes(ctx, mgr.GetFieldIndexer())
    97  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    98  
    99  	sched := scheduler.New(
   100  		queues, cCache, mgr.GetClient(), mgr.GetEventRecorderFor(constants.AdmissionName),
   101  		scheduler.WithPodsReadyRequeuingTimestamp(requeuingTimestamp),
   102  	)
   103  	err = sched.Start(ctx)
   104  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
   105  }