@@ -23,6 +23,7 @@ import (
2323 "github.com/onsi/ginkgo/v2"
2424 "github.com/onsi/gomega"
2525 corev1 "k8s.io/api/core/v1"
26+ nodev1 "k8s.io/api/node/v1"
2627 apimeta "k8s.io/apimachinery/pkg/api/meta"
2728 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829 "k8s.io/utils/ptr"
@@ -612,6 +613,95 @@ var _ = ginkgo.Describe("Workload controller", ginkgo.Ordered, ginkgo.ContinueOn
612613 })
613614})
614615
616+ var _ = ginkgo .Describe ("Workload controller interaction with scheduler" , ginkgo .Ordered , ginkgo .ContinueOnFailure , func () {
617+ var (
618+ ns * corev1.Namespace
619+ clusterQueue * kueue.ClusterQueue
620+ localQueue * kueue.LocalQueue
621+ wl * kueue.Workload
622+ )
623+
624+ ginkgo .BeforeAll (func () {
625+ fwk .StartManager (ctx , cfg , managerAndSchedulerSetup )
626+ })
627+
628+ ginkgo .AfterAll (func () {
629+ fwk .StopManager (ctx )
630+ })
631+
632+ ginkgo .When ("workload's runtime class is changed" , func () {
633+ var flavor * kueue.ResourceFlavor
634+ var runtimeClass * nodev1.RuntimeClass
635+
636+ const runtimeClassName = "test-kueue-class"
637+
638+ ginkgo .BeforeEach (func () {
639+ ns = util .CreateNamespaceFromPrefixWithLog (ctx , k8sClient , "core-workload-" )
640+ flavor = utiltestingapi .MakeResourceFlavor (flavorOnDemand ).Obj ()
641+ util .MustCreate (ctx , k8sClient , flavor )
642+ clusterQueue = utiltestingapi .MakeClusterQueue ("cluster-queue" ).
643+ ResourceGroup (* utiltestingapi .MakeFlavorQuotas (flavorOnDemand ).Resource (corev1 .ResourceCPU , "5" , "5" ).Obj ()).
644+ Cohort ("cohort" ).
645+ Obj ()
646+ util .MustCreate (ctx , k8sClient , clusterQueue )
647+ localQueue = utiltestingapi .MakeLocalQueue ("queue" , ns .Name ).ClusterQueue (clusterQueue .Name ).Obj ()
648+ util .MustCreate (ctx , k8sClient , localQueue )
649+ runtimeClass = utiltesting .MakeRuntimeClass (runtimeClassName , "rc-handler-1" ).Obj ()
650+ util .MustCreate (ctx , k8sClient , runtimeClass )
651+ })
652+
653+ ginkgo .AfterEach (func () {
654+ gomega .Expect (util .DeleteNamespace (ctx , k8sClient , ns )).To (gomega .Succeed ())
655+ util .ExpectObjectToBeDeleted (ctx , k8sClient , clusterQueue , true )
656+ util .ExpectObjectToBeDeleted (ctx , k8sClient , flavor , true )
657+ util .ExpectObjectToBeDeleted (ctx , k8sClient , runtimeClass , true )
658+ })
659+
660+ ginkgo .It ("should not temporarily admit an inactive workload" , func () {
661+ ginkgo .By ("creating an inactive workload" , func () {
662+ wl = utiltestingapi .MakeWorkload ("wl1" , ns .Name ).
663+ Queue (kueue .LocalQueueName (localQueue .Name )).
664+ Request (corev1 .ResourceCPU , "1" ).
665+ RuntimeClass (runtimeClassName ).
666+ Active (false ).
667+ Obj ()
668+ util .MustCreate (ctx , k8sClient , wl )
669+
670+ wlKey := client .ObjectKeyFromObject (wl )
671+ gomega .Eventually (func (g gomega.Gomega ) {
672+ g .Expect (k8sClient .Get (ctx , wlKey , wl )).To (gomega .Succeed ())
673+ }, util .Timeout , util .Interval ).Should (gomega .Succeed ())
674+ })
675+
676+ ginkgo .By ("changing the runtime class" , func () {
677+ gomega .Eventually (func (g gomega.Gomega ) {
678+ runtimeClassKey := client .ObjectKeyFromObject (runtimeClass )
679+ g .Expect (k8sClient .Get (ctx , runtimeClassKey , runtimeClass )).To (gomega .Succeed ())
680+ if runtimeClass .ObjectMeta .Annotations == nil {
681+ runtimeClass .ObjectMeta .Annotations = map [string ]string {}
682+ }
683+ runtimeClass .ObjectMeta .Annotations ["foo" ] = "bar"
684+ g .Expect (k8sClient .Update (ctx , runtimeClass )).To (gomega .Succeed ())
685+ }, util .Timeout , util .Interval ).Should (gomega .Succeed ())
686+ })
687+
688+ ginkgo .By ("checking no 'quota reseved' event appearing for the workload" , func () {
689+ gomega .Consistently (func (g gomega.Gomega ) {
690+ found , err := utiltesting .HasMatchingEventAppeared (ctx , k8sClient , func (e * corev1.Event ) bool {
691+ return e .Reason == "QuotaReserved" &&
692+ e .Type == corev1 .EventTypeNormal &&
693+ e .InvolvedObject .Kind == "Workload" &&
694+ e .InvolvedObject .Name == wl .Name &&
695+ e .InvolvedObject .Namespace == wl .Namespace
696+ })
697+ g .Expect (err ).NotTo (gomega .HaveOccurred ())
698+ g .Expect (found ).To (gomega .BeTrue ())
699+ }, util .ShortTimeout , util .Interval ).ShouldNot (gomega .Succeed ())
700+ })
701+ })
702+ })
703+ })
704+
615705var _ = ginkgo .Describe ("Workload controller with resource retention" , ginkgo .Ordered , ginkgo .ContinueOnFailure , func () {
616706 ginkgo .When ("manager is setup with tiny retention period" , func () {
617707 var (
0 commit comments