|
| 1 | +/* |
| 2 | +Copyright 2025 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 queuename |
| 18 | + |
| 19 | +import ( |
| 20 | + "time" |
| 21 | + |
| 22 | + "github.com/onsi/ginkgo/v2" |
| 23 | + "github.com/onsi/gomega" |
| 24 | + batchv1 "k8s.io/api/batch/v1" |
| 25 | + corev1 "k8s.io/api/core/v1" |
| 26 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 27 | + "k8s.io/apimachinery/pkg/types" |
| 28 | + |
| 29 | + "k8s.io/utils/ptr" |
| 30 | + kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1" |
| 31 | + workloadjob "sigs.k8s.io/kueue/pkg/controller/jobs/job" |
| 32 | + "sigs.k8s.io/kueue/pkg/util/testing" |
| 33 | + testingjob "sigs.k8s.io/kueue/pkg/util/testingjobs/job" |
| 34 | + "sigs.k8s.io/kueue/test/util" |
| 35 | +) |
| 36 | + |
| 37 | +var _ = ginkgo.Describe("ManageJobsWithoutQueueName", ginkgo.Ordered, func() { |
| 38 | + var ns *corev1.Namespace |
| 39 | + |
| 40 | + ginkgo.BeforeAll(func() { |
| 41 | + configurationUpdate := time.Now() |
| 42 | + config := util.GetKueueConfiguration(ctx, k8sClient) |
| 43 | + config.ManageJobsWithoutQueueName = true |
| 44 | + util.ApplyKueueConfiguration(ctx, k8sClient, config) |
| 45 | + util.RestartKueueController(ctx, k8sClient) |
| 46 | + ginkgo.GinkgoLogr.Info("Kueue configuration updated", "took", time.Since(configurationUpdate)) |
| 47 | + }) |
| 48 | + |
| 49 | + ginkgo.AfterAll(func() { |
| 50 | + config := util.GetKueueConfiguration(ctx, k8sClient) |
| 51 | + config.ManageJobsWithoutQueueName = false |
| 52 | + util.ApplyKueueConfiguration(ctx, k8sClient, config) |
| 53 | + util.RestartKueueController(ctx, k8sClient) |
| 54 | + }) |
| 55 | + |
| 56 | + ginkgo.BeforeEach(func() { |
| 57 | + ns = &corev1.Namespace{ |
| 58 | + ObjectMeta: metav1.ObjectMeta{ |
| 59 | + GenerateName: "e2e-", |
| 60 | + }, |
| 61 | + } |
| 62 | + gomega.Expect(k8sClient.Create(ctx, ns)).To(gomega.Succeed()) |
| 63 | + }) |
| 64 | + ginkgo.AfterEach(func() { |
| 65 | + gomega.Expect(util.DeleteNamespace(ctx, k8sClient, ns)).To(gomega.Succeed()) |
| 66 | + }) |
| 67 | + ginkgo.When("creating a Job when manageJobsWithoutQueueName=true", func() { |
| 68 | + var ( |
| 69 | + defaultRf *kueue.ResourceFlavor |
| 70 | + localQueue *kueue.LocalQueue |
| 71 | + clusterQueue *kueue.ClusterQueue |
| 72 | + ) |
| 73 | + ginkgo.BeforeEach(func() { |
| 74 | + defaultRf = testing.MakeResourceFlavor("default").Obj() |
| 75 | + gomega.Expect(k8sClient.Create(ctx, defaultRf)).Should(gomega.Succeed()) |
| 76 | + clusterQueue = testing.MakeClusterQueue("cluster-queue"). |
| 77 | + ResourceGroup( |
| 78 | + *testing.MakeFlavorQuotas(defaultRf.Name). |
| 79 | + Resource(corev1.ResourceCPU, "2"). |
| 80 | + Resource(corev1.ResourceMemory, "2G").Obj()).Obj() |
| 81 | + gomega.Expect(k8sClient.Create(ctx, clusterQueue)).Should(gomega.Succeed()) |
| 82 | + localQueue = testing.MakeLocalQueue("main", ns.Name).ClusterQueue("cluster-queue").Obj() |
| 83 | + gomega.Expect(k8sClient.Create(ctx, localQueue)).Should(gomega.Succeed()) |
| 84 | + }) |
| 85 | + ginkgo.AfterEach(func() { |
| 86 | + gomega.Expect(util.DeleteAllJobsInNamespace(ctx, k8sClient, ns)).Should(gomega.Succeed()) |
| 87 | + // Force remove workloads to be sure that cluster queue can be removed. |
| 88 | + gomega.Expect(util.DeleteWorkloadsInNamespace(ctx, k8sClient, ns)).Should(gomega.Succeed()) |
| 89 | + gomega.Expect(util.DeleteObject(ctx, k8sClient, localQueue)).Should(gomega.Succeed()) |
| 90 | + util.ExpectObjectToBeDeleted(ctx, k8sClient, clusterQueue, true) |
| 91 | + util.ExpectObjectToBeDeleted(ctx, k8sClient, defaultRf, true) |
| 92 | + }) |
| 93 | + |
| 94 | + ginkgo.It("should suspend it", func() { |
| 95 | + |
| 96 | + var testJob *batchv1.Job |
| 97 | + ginkgo.By("creating a job without queue name", func() { |
| 98 | + testJob = testingjob.MakeJob("test-job", ns.Name).Suspend(false).Obj() |
| 99 | + gomega.Expect(k8sClient.Create(ctx, testJob)).Should(gomega.Succeed()) |
| 100 | + }) |
| 101 | + |
| 102 | + ginkgo.By("verifying that the job is suspended", func() { |
| 103 | + jobLookupKey := types.NamespacedName{Name: testJob.Name, Namespace: ns.Name} |
| 104 | + createdJob := &batchv1.Job{} |
| 105 | + gomega.Eventually(func(g gomega.Gomega) { |
| 106 | + g.Expect(k8sClient.Get(ctx, jobLookupKey, createdJob)).Should(gomega.Succeed()) |
| 107 | + g.Expect(ptr.Deref(createdJob.Spec.Suspend, false)).To(gomega.BeTrue()) |
| 108 | + }, util.LongTimeout, util.Interval).Should(gomega.Succeed()) |
| 109 | + }) |
| 110 | + }) |
| 111 | + |
| 112 | + ginkgo.It("should unsuspend it", func() { |
| 113 | + |
| 114 | + var testJob *batchv1.Job |
| 115 | + var jobLookupKey types.NamespacedName |
| 116 | + createdJob := &batchv1.Job{} |
| 117 | + ginkgo.By("creating a job without queue name", func() { |
| 118 | + testJob = testingjob.MakeJob("test-job", ns.Name).Suspend(false).Obj() |
| 119 | + gomega.Expect(k8sClient.Create(ctx, testJob)).Should(gomega.Succeed()) |
| 120 | + }) |
| 121 | + ginkgo.By("setting the queue-name label", func() { |
| 122 | + jobLookupKey = types.NamespacedName{Name: testJob.Name, Namespace: ns.Name} |
| 123 | + gomega.Eventually(func() error { |
| 124 | + if err := k8sClient.Get(ctx, jobLookupKey, createdJob); err != nil { |
| 125 | + return err |
| 126 | + } |
| 127 | + createdJob.Labels["kueue.x-k8s.io/queue-name"] = "main" |
| 128 | + return k8sClient.Update(ctx, createdJob) |
| 129 | + }, util.LongTimeout, util.Interval).Should(gomega.Succeed()) |
| 130 | + }) |
| 131 | + ginkgo.By("verifying that the job is unsuspended", func() { |
| 132 | + gomega.Eventually(func(g gomega.Gomega) { |
| 133 | + g.Expect(k8sClient.Get(ctx, jobLookupKey, createdJob)).Should(gomega.Succeed()) |
| 134 | + g.Expect(ptr.Deref(createdJob.Spec.Suspend, false)).To(gomega.BeFalse()) |
| 135 | + }, util.LongTimeout, util.Interval).Should(gomega.Succeed()) |
| 136 | + }) |
| 137 | + ginkgo.By("verifying that the job has been admitted", func() { |
| 138 | + wlLookupKey := types.NamespacedName{Name: workloadjob.GetWorkloadNameForJob(testJob.Name, testJob.UID), Namespace: ns.Name} |
| 139 | + createdWorkload := &kueue.Workload{} |
| 140 | + gomega.Eventually(func(g gomega.Gomega) { |
| 141 | + g.Expect(k8sClient.Get(ctx, wlLookupKey, createdWorkload)).Should(gomega.Succeed()) |
| 142 | + g.Expect(createdWorkload.Status.Admission).ShouldNot(gomega.BeNil()) |
| 143 | + }, util.LongTimeout, util.Interval).Should(gomega.Succeed()) |
| 144 | + }) |
| 145 | + }) |
| 146 | + }) |
| 147 | +}) |
0 commit comments