|
| 1 | +/* |
| 2 | +Copyright 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 e2e |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/onsi/ginkgo/v2" |
| 21 | + "github.com/onsi/gomega" |
| 22 | + corev1 "k8s.io/api/core/v1" |
| 23 | + rbacv1 "k8s.io/api/rbac/v1" |
| 24 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 25 | + "k8s.io/apimachinery/pkg/types" |
| 26 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 27 | + kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1" |
| 28 | + sparkapplication "sigs.k8s.io/kueue/pkg/controller/jobs/sparkapplication" |
| 29 | + testing "sigs.k8s.io/kueue/pkg/util/testing" |
| 30 | + sparkapplicationtesting "sigs.k8s.io/kueue/pkg/util/testingjobs/sparkapplication" |
| 31 | + "sigs.k8s.io/kueue/test/util" |
| 32 | + |
| 33 | + sparkv1beta2 "github.com/kubeflow/spark-operator/v2/api/v1beta2" |
| 34 | +) |
| 35 | + |
| 36 | +var _ = ginkgo.Describe("SparkApplication integration", func() { |
| 37 | + const ( |
| 38 | + resourceFlavorName = "sparkapplication-rf" |
| 39 | + clusterQueueName = "sparkapplication-cq" |
| 40 | + localQueueName = "sparkapplication-lq" |
| 41 | + serviceAccountName = "sparkapplication-sa" |
| 42 | + roleBindingName = "sparkapplication-sa-edit" |
| 43 | + ) |
| 44 | + |
| 45 | + var ( |
| 46 | + ns *corev1.Namespace |
| 47 | + rf *kueue.ResourceFlavor |
| 48 | + cq *kueue.ClusterQueue |
| 49 | + lq *kueue.LocalQueue |
| 50 | + sa *corev1.ServiceAccount |
| 51 | + ) |
| 52 | + |
| 53 | + ginkgo.BeforeEach(func() { |
| 54 | + ns = util.CreateNamespaceFromPrefixWithLog(ctx, k8sClient, "sparkapplication-e2e-") |
| 55 | + |
| 56 | + rf = testing.MakeResourceFlavor(resourceFlavorName).Obj() |
| 57 | + util.MustCreate(ctx, k8sClient, rf) |
| 58 | + |
| 59 | + cq = testing.MakeClusterQueue(clusterQueueName). |
| 60 | + ResourceGroup( |
| 61 | + *testing.MakeFlavorQuotas(resourceFlavorName). |
| 62 | + Resource(corev1.ResourceCPU, "5"). |
| 63 | + Resource(corev1.ResourceMemory, "10Gi"). |
| 64 | + Obj(), |
| 65 | + ). |
| 66 | + Preemption(kueue.ClusterQueuePreemption{ |
| 67 | + WithinClusterQueue: kueue.PreemptionPolicyLowerPriority, |
| 68 | + }). |
| 69 | + Obj() |
| 70 | + util.MustCreate(ctx, k8sClient, cq) |
| 71 | + |
| 72 | + lq = testing.MakeLocalQueue(localQueueName, ns.Name).ClusterQueue(cq.Name).Obj() |
| 73 | + util.MustCreate(ctx, k8sClient, lq) |
| 74 | + |
| 75 | + sa = &corev1.ServiceAccount{ |
| 76 | + ObjectMeta: metav1.ObjectMeta{ |
| 77 | + Name: serviceAccountName, |
| 78 | + Namespace: ns.Name, |
| 79 | + }, |
| 80 | + } |
| 81 | + util.MustCreate(ctx, k8sClient, sa) |
| 82 | + |
| 83 | + rb := &rbacv1.RoleBinding{ |
| 84 | + ObjectMeta: metav1.ObjectMeta{ |
| 85 | + Name: roleBindingName, |
| 86 | + Namespace: ns.Name, |
| 87 | + }, |
| 88 | + Subjects: []rbacv1.Subject{ |
| 89 | + { |
| 90 | + Kind: rbacv1.ServiceAccountKind, |
| 91 | + Name: serviceAccountName, |
| 92 | + Namespace: ns.Name, |
| 93 | + }, |
| 94 | + }, |
| 95 | + RoleRef: rbacv1.RoleRef{ |
| 96 | + Kind: "ClusterRole", |
| 97 | + Name: "edit", |
| 98 | + APIGroup: rbacv1.GroupName, |
| 99 | + }, |
| 100 | + } |
| 101 | + util.MustCreate(ctx, k8sClient, rb) |
| 102 | + }) |
| 103 | + |
| 104 | + ginkgo.AfterEach(func() { |
| 105 | + gomega.Expect(util.DeleteAllSparkApplicationsInNamespace(ctx, k8sClient, ns)).To(gomega.Succeed()) |
| 106 | + gomega.Expect(util.DeleteNamespace(ctx, k8sClient, ns)).To(gomega.Succeed()) |
| 107 | + util.ExpectObjectToBeDeleted(ctx, k8sClient, cq, true) |
| 108 | + util.ExpectObjectToBeDeleted(ctx, k8sClient, rf, true) |
| 109 | + util.ExpectAllPodsInNamespaceDeleted(ctx, k8sClient, ns) |
| 110 | + }) |
| 111 | + |
| 112 | + ginkgo.When("SparkApplication created", func() { |
| 113 | + ginkgo.It("should run if admitted", func() { |
| 114 | + sparkApp := sparkapplicationtesting.MakeSparkApplication("sparkapplication-simple", ns.Name). |
| 115 | + DriverServiceAccount(sa.Name). |
| 116 | + DriverCoreRequest("1"). |
| 117 | + DriverMemoryRequest("512m"). // 512MB |
| 118 | + ExecutorServiceAccount(sa.Name). |
| 119 | + ExecutorCoreRequest("1"). |
| 120 | + ExecutorMemoryRequest("512m"). // 512MB |
| 121 | + ExecutorInstances(1). |
| 122 | + Queue(lq.Name). |
| 123 | + Obj() |
| 124 | + |
| 125 | + ginkgo.By("Create a SparkApplicatioon", func() { |
| 126 | + util.MustCreate(ctx, k8sClient, sparkApp) |
| 127 | + }) |
| 128 | + |
| 129 | + ginkgo.By("Waiting for SparkApplication to be Running", func() { |
| 130 | + createdSparkApp := &sparkv1beta2.SparkApplication{} |
| 131 | + |
| 132 | + gomega.Eventually(func(g gomega.Gomega) { |
| 133 | + // Fetch the SparkApplication object |
| 134 | + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(sparkApp), createdSparkApp) |
| 135 | + g.Expect(err).ToNot(gomega.HaveOccurred(), "Failed to fetch SparkApplication") |
| 136 | + |
| 137 | + // Ensure SparkApplication's AppState.State is Running |
| 138 | + g.Expect(createdSparkApp.Status.AppState.State).To(gomega.Equal(sparkv1beta2.ApplicationStateRunning)) |
| 139 | + }, util.LongTimeout, util.Interval).Should(gomega.Succeed()) |
| 140 | + }) |
| 141 | + |
| 142 | + wlLookupKey := types.NamespacedName{ |
| 143 | + Name: sparkapplication.GetWorkloadNameForSparkApplication(sparkApp.Name, sparkApp.UID), |
| 144 | + Namespace: ns.Name, |
| 145 | + } |
| 146 | + createdWorkload := &kueue.Workload{} |
| 147 | + ginkgo.By("Check workload is created", func() { |
| 148 | + gomega.Expect(k8sClient.Get(ctx, wlLookupKey, createdWorkload)).To(gomega.Succeed()) |
| 149 | + }) |
| 150 | + |
| 151 | + ginkgo.By("Check workload is admitted", func() { |
| 152 | + util.ExpectWorkloadsToBeAdmitted(ctx, k8sClient, createdWorkload) |
| 153 | + }) |
| 154 | + |
| 155 | + ginkgo.By("Check workload is finished", func() { |
| 156 | + util.ExpectWorkloadToFinish(ctx, k8sClient, wlLookupKey) |
| 157 | + }) |
| 158 | + |
| 159 | + ginkgo.By("Delete the SparkApplication", func() { |
| 160 | + util.ExpectObjectToBeDeleted(ctx, k8sClient, sparkApp, true) |
| 161 | + }) |
| 162 | + |
| 163 | + ginkgo.By("Check workload is deleted", func() { |
| 164 | + util.ExpectObjectToBeDeletedWithTimeout(ctx, k8sClient, createdWorkload, false, util.LongTimeout) |
| 165 | + }) |
| 166 | + }) |
| 167 | + }) |
| 168 | +}) |
0 commit comments