@@ -535,6 +535,114 @@ var _ = ginkgo.Describe("StatefulSet integration", func() {
535535 g .Expect (createdHighPriorityWl .Status .Conditions ).To (utiltesting .HaveConditionStatusTrue (kueue .WorkloadAdmitted ))
536536 }, util .Timeout , util .Interval ).Should (gomega .Succeed ())
537537 })
538+
539+ ginkgo .By ("Check the low priority Workload is preempted" , func () {
540+ gomega .Eventually (func (g gomega.Gomega ) {
541+ g .Expect (k8sClient .Get (ctx , lowPriorityWlKey , createdLowPriorityWl )).To (gomega .Succeed ())
542+ g .Expect (createdLowPriorityWl .Status .Conditions ).To (utiltesting .HaveConditionStatusFalse (kueue .WorkloadAdmitted ))
543+ g .Expect (createdLowPriorityWl .Status .Conditions ).To (utiltesting .HaveConditionStatusTrue (kueue .WorkloadPreempted ))
544+ }, util .Timeout , util .Interval ).Should (gomega .Succeed ())
545+ })
546+ })
547+ })
548+
549+ ginkgo .When ("Workload deactivated" , func () {
550+ ginkgo .It ("shouldn't delete deactivated Workload" , func () {
551+ statefulSet := statefulsettesting .MakeStatefulSet ("sts" , ns .Name ).
552+ Image (util .GetAgnHostImage (), util .BehaviorWaitForDeletion ).
553+ RequestAndLimit (corev1 .ResourceCPU , "200m" ).
554+ TerminationGracePeriod (1 ).
555+ Replicas (3 ).
556+ Queue (lq .Name ).
557+ Obj ()
558+
559+ ginkgo .By ("Create StatefulSet" , func () {
560+ gomega .Expect (k8sClient .Create (ctx , statefulSet )).To (gomega .Succeed ())
561+ })
562+
563+ wlLookupKey := types.NamespacedName {Name : statefulset .GetWorkloadName (statefulSet .Name ), Namespace : ns .Name }
564+ createdWorkload := & kueue.Workload {}
565+ ginkgo .By ("Check workload is created" , func () {
566+ gomega .Eventually (func (g gomega.Gomega ) {
567+ g .Expect (k8sClient .Get (ctx , wlLookupKey , createdWorkload )).To (gomega .Succeed ())
568+ g .Expect (createdWorkload .Status .Conditions ).To (utiltesting .HaveConditionStatusTrue (kueue .WorkloadAdmitted ))
569+ }, util .Timeout , util .Interval ).Should (gomega .Succeed ())
570+ })
571+
572+ createdWorkloadUID := createdWorkload .UID
573+
574+ ginkgo .By ("Waiting for all replicas to be ready" , func () {
575+ gomega .Eventually (func (g gomega.Gomega ) {
576+ createdStatefulSet := & appsv1.StatefulSet {}
577+ g .Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (statefulSet ), createdStatefulSet )).To (gomega .Succeed ())
578+ g .Expect (createdStatefulSet .Status .ReadyReplicas ).To (gomega .Equal (int32 (3 )))
579+ }, util .LongTimeout , util .Interval ).Should (gomega .Succeed ())
580+ })
581+
582+ ginkgo .By ("Deactivate the workload" , func () {
583+ gomega .Eventually (func (g gomega.Gomega ) {
584+ g .Expect (k8sClient .Get (ctx , wlLookupKey , createdWorkload )).To (gomega .Succeed ())
585+ createdWorkload .Spec .Active = ptr .To (false )
586+ g .Expect (k8sClient .Update (ctx , createdWorkload )).To (gomega .Succeed ())
587+ }, util .Timeout , util .Interval ).Should (gomega .Succeed ())
588+ })
589+
590+ ginkgo .By ("Check workload is deactivated" , func () {
591+ gomega .Eventually (func (g gomega.Gomega ) {
592+ g .Expect (k8sClient .Get (ctx , wlLookupKey , createdWorkload )).To (gomega .Succeed ())
593+ g .Expect (createdWorkload .UID ).Should (gomega .Equal (createdWorkloadUID ))
594+ g .Expect (createdWorkload .Spec .Active ).Should (gomega .Equal (ptr .To (false )))
595+ g .Expect (createdWorkload .Status .Conditions ).Should (utiltesting .HaveConditionStatusTrue (kueue .WorkloadEvicted ))
596+ }, util .LongTimeout , util .Interval ).Should (gomega .Succeed ())
597+ })
598+
599+ ginkgo .By ("Waiting for all replicas to be not ready" , func () {
600+ gomega .Eventually (func (g gomega.Gomega ) {
601+ createdStatefulSet := & appsv1.StatefulSet {}
602+ g .Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (statefulSet ), createdStatefulSet )).To (gomega .Succeed ())
603+ g .Expect (createdStatefulSet .Status .ReadyReplicas ).To (gomega .Equal (int32 (0 )))
604+ }, util .LongTimeout , util .Interval ).Should (gomega .Succeed ())
605+ })
606+
607+ ginkgo .By ("Re-activate the workload" , func () {
608+ gomega .Eventually (func (g gomega.Gomega ) {
609+ g .Expect (k8sClient .Get (ctx , wlLookupKey , createdWorkload )).To (gomega .Succeed ())
610+ createdWorkload .Spec .Active = ptr .To (true )
611+ g .Expect (k8sClient .Update (ctx , createdWorkload )).To (gomega .Succeed ())
612+ }, util .Timeout , util .Interval ).Should (gomega .Succeed ())
613+ })
614+
615+ ginkgo .By ("Check workload is re-admitted" , func () {
616+ gomega .Eventually (func (g gomega.Gomega ) {
617+ g .Expect (k8sClient .Get (ctx , wlLookupKey , createdWorkload )).To (gomega .Succeed ())
618+ g .Expect (createdWorkload .UID ).Should (gomega .Equal (createdWorkloadUID ))
619+ g .Expect (createdWorkload .Status .Conditions ).To (utiltesting .HaveConditionStatusTrue (kueue .WorkloadAdmitted ))
620+ }, util .LongTimeout , util .Interval ).Should (gomega .Succeed ())
621+ })
622+
623+ ginkgo .By ("Waiting for all replicas to be ready" , func () {
624+ gomega .Eventually (func (g gomega.Gomega ) {
625+ createdStatefulSet := & appsv1.StatefulSet {}
626+ g .Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (statefulSet ), createdStatefulSet )).To (gomega .Succeed ())
627+ g .Expect (createdStatefulSet .Status .ReadyReplicas ).To (gomega .Equal (int32 (3 )))
628+ }, util .LongTimeout , util .Interval ).Should (gomega .Succeed ())
629+ })
630+
631+ ginkgo .By ("Delete StatefulSet" , func () {
632+ gomega .Expect (k8sClient .Delete (ctx , statefulSet )).To (gomega .Succeed ())
633+ })
634+
635+ ginkgo .By ("Check all pods are deleted" , func () {
636+ pods := & corev1.PodList {}
637+ gomega .Eventually (func (g gomega.Gomega ) {
638+ g .Expect (k8sClient .List (ctx , pods , client .InNamespace (ns .Name ))).To (gomega .Succeed ())
639+ g .Expect (pods .Items ).Should (gomega .BeEmpty ())
640+ }, util .LongTimeout , util .Interval ).Should (gomega .Succeed ())
641+ })
642+
643+ ginkgo .By ("Check workload is deleted" , func () {
644+ util .ExpectObjectToBeDeletedWithTimeout (ctx , k8sClient , createdWorkload , false , util .LongTimeout )
645+ })
538646 })
539647 })
540648})
0 commit comments