Skip to content

Commit 6847878

Browse files
Wei WengWei Weng
authored andcommitted
test job
Signed-off-by: Wei Weng <[email protected]>
1 parent 4498d35 commit 6847878

File tree

1 file changed

+47
-25
lines changed

1 file changed

+47
-25
lines changed

test/e2e/resource_placement_hub_workload_test.go

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
. "github.com/onsi/ginkgo/v2"
2323
. "github.com/onsi/gomega"
2424
appsv1 "k8s.io/api/apps/v1"
25+
batchv1 "k8s.io/api/batch/v1"
2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/apimachinery/pkg/types"
2728
"k8s.io/utils/ptr"
@@ -33,24 +34,24 @@ var _ = Describe("placing workloads using a CRP with PickAll policy", Label("res
3334
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
3435
var testDeployment appsv1.Deployment
3536
var testDaemonSet appsv1.DaemonSet
36-
var testStatefulSet appsv1.StatefulSet
37+
var testJob batchv1.Job
3738

3839
BeforeAll(func() {
3940
// Read the test manifests
4041
readDeploymentTestManifest(&testDeployment)
4142
readDaemonSetTestManifest(&testDaemonSet)
42-
readStatefulSetTestManifest(&testStatefulSet, false)
43+
readJobTestManifest(&testJob)
4344
workNamespace := appNamespace()
4445

4546
// Create namespace and workloads
4647
By("creating namespace and workloads")
4748
Expect(hubClient.Create(ctx, &workNamespace)).To(Succeed(), "Failed to create namespace %s", workNamespace.Name)
4849
testDeployment.Namespace = workNamespace.Name
4950
testDaemonSet.Namespace = workNamespace.Name
50-
testStatefulSet.Namespace = workNamespace.Name
51+
testJob.Namespace = workNamespace.Name
5152
Expect(hubClient.Create(ctx, &testDeployment)).To(Succeed(), "Failed to create test deployment %s", testDeployment.Name)
5253
Expect(hubClient.Create(ctx, &testDaemonSet)).To(Succeed(), "Failed to create test daemonset %s", testDaemonSet.Name)
53-
Expect(hubClient.Create(ctx, &testStatefulSet)).To(Succeed(), "Failed to create test statefulset %s", testStatefulSet.Name)
54+
Expect(hubClient.Create(ctx, &testJob)).To(Succeed(), "Failed to create test job %s", testJob.Name)
5455

5556
// Create the CRP that selects the namespace
5657
By("creating CRP that selects the namespace")
@@ -96,14 +97,17 @@ var _ = Describe("placing workloads using a CRP with PickAll policy", Label("res
9697
Namespace: workNamespace.Name,
9798
},
9899
{
99-
Group: "apps",
100+
Group: "batch",
100101
Version: "v1",
101-
Kind: "StatefulSet",
102-
Name: testStatefulSet.Name,
102+
Kind: "Job",
103+
Name: testJob.Name,
103104
Namespace: workNamespace.Name,
104105
},
105106
}
106-
crpStatusUpdatedActual := crpStatusUpdatedActual(wantSelectedResources, allMemberClusterNames, nil, "0")
107+
// Use customizedPlacementStatusUpdatedActual with resourceIsTrackable=false
108+
// because Jobs don't have availability tracking like Deployments/DaemonSets do
109+
crpKey := types.NamespacedName{Name: crpName}
110+
crpStatusUpdatedActual := customizedPlacementStatusUpdatedActual(crpKey, wantSelectedResources, allMemberClusterNames, nil, "0", false)
107111
Eventually(crpStatusUpdatedActual, workloadEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to update CRP status as expected")
108112
})
109113

@@ -157,26 +161,23 @@ var _ = Describe("placing workloads using a CRP with PickAll policy", Label("res
157161
"Hub daemonset should be ready before placement")
158162
})
159163

160-
It("should verify hub statefulset is ready", func() {
161-
By("checking hub statefulset status")
164+
It("should verify hub job exists", func() {
165+
By("checking hub job status")
162166
Eventually(func() error {
163-
var hubStatefulSet appsv1.StatefulSet
167+
var hubJob batchv1.Job
164168
if err := hubClient.Get(ctx, types.NamespacedName{
165-
Name: testStatefulSet.Name,
166-
Namespace: testStatefulSet.Namespace,
167-
}, &hubStatefulSet); err != nil {
169+
Name: testJob.Name,
170+
Namespace: testJob.Namespace,
171+
}, &hubJob); err != nil {
168172
return err
169173
}
170-
// Verify statefulset is ready in hub cluster
171-
if hubStatefulSet.Status.ReadyReplicas != *hubStatefulSet.Spec.Replicas {
172-
return fmt.Errorf("hub statefulset not ready: %d/%d replicas ready", hubStatefulSet.Status.ReadyReplicas, *hubStatefulSet.Spec.Replicas)
173-
}
174-
if hubStatefulSet.Status.UpdatedReplicas != *hubStatefulSet.Spec.Replicas {
175-
return fmt.Errorf("hub statefulset not updated: %d/%d replicas updated", hubStatefulSet.Status.UpdatedReplicas, *hubStatefulSet.Spec.Replicas)
174+
// Check if job has completed successfully
175+
if hubJob.Status.Succeeded == 0 {
176+
return fmt.Errorf("hub job not completed: %d succeeded", hubJob.Status.Succeeded)
176177
}
177178
return nil
178179
}, workloadEventuallyDuration, eventuallyInterval).Should(Succeed(),
179-
"Hub statefulset should be ready before placement")
180+
"Hub job should complete successfully")
180181
})
181182

182183
It("should place the deployment on all member clusters", func() {
@@ -197,12 +198,33 @@ var _ = Describe("placing workloads using a CRP with PickAll policy", Label("res
197198
}
198199
})
199200

200-
It("should place the statefulset on all member clusters", func() {
201-
By("verifying statefulset is placed and ready on all member clusters")
201+
It("should place the job on all member clusters", func() {
202+
By("verifying job is placed on all member clusters")
202203
for idx := range allMemberClusters {
203204
memberCluster := allMemberClusters[idx]
204-
statefulsetPlacedActual := waitForStatefulSetPlacementToReady(memberCluster, &testStatefulSet)
205-
Eventually(statefulsetPlacedActual, workloadEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place statefulset on member cluster %s", memberCluster.ClusterName)
205+
jobPlacedActual := waitForJobToBePlaced(memberCluster, &testJob)
206+
Eventually(jobPlacedActual, workloadEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to place job on member cluster %s", memberCluster.ClusterName)
207+
}
208+
})
209+
210+
It("should verify job completes successfully on all clusters", func() {
211+
By("checking job completion status on each cluster")
212+
for _, cluster := range allMemberClusters {
213+
Eventually(func() error {
214+
var placedJob batchv1.Job
215+
if err := cluster.KubeClient.Get(ctx, types.NamespacedName{
216+
Name: testJob.Name,
217+
Namespace: testJob.Namespace,
218+
}, &placedJob); err != nil {
219+
return err
220+
}
221+
// Check if job has completed successfully
222+
if placedJob.Status.Succeeded == 0 {
223+
return fmt.Errorf("job not completed: %d/%d succeeded", placedJob.Status.Succeeded, *placedJob.Spec.Completions)
224+
}
225+
return nil
226+
}, workloadEventuallyDuration, eventuallyInterval).Should(Succeed(),
227+
"Job should complete successfully on cluster %s", cluster.ClusterName)
206228
}
207229
})
208230

0 commit comments

Comments
 (0)