@@ -95,7 +95,7 @@ var _ = ginkgo.Describe("JobSet", func() {
95
95
gomega .Expect (k8sClient .Create (ctx , js )).Should (gomega .Succeed ())
96
96
97
97
// We'll need to retry getting this newly created jobset, given that creation may not immediately happen.
98
- gomega .Eventually (k8sClient .Get (ctx , types.NamespacedName {Name : js .Name , Namespace : js .Namespace }, & jobset.JobSet {}), timeout , interval ).Should (gomega .Succeed ())
98
+ gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : js .Name , Namespace : js .Namespace }, & jobset.JobSet {}), timeout , interval ).Should (gomega .Succeed ())
99
99
100
100
ginkgo .By ("checking all jobs were created successfully" )
101
101
gomega .Eventually (util .NumJobs , timeout , interval ).WithArguments (ctx , k8sClient , js ).Should (gomega .Equal (util .NumExpectedJobs (js )))
@@ -105,6 +105,35 @@ var _ = ginkgo.Describe("JobSet", func() {
105
105
util .JobSetCompleted (ctx , k8sClient , js , timeout )
106
106
})
107
107
})
108
+ ginkgo .When ("ttl seconds after finished is set" , func () {
109
+ ginkgo .It ("should clean up the completed jobset after configured ttl seconds expire" , func () {
110
+ ctx := context .Background ()
111
+
112
+ // Create JobSet.
113
+ testFinalizer := "fake.example.com/blockDeletion"
114
+ ginkgo .By ("creating jobset with ttl seconds after finished" )
115
+ js := sleepTestJobSet (ns ).Finalizers ([]string {testFinalizer }).TTLSecondsAfterFinished (5 ).Obj ()
116
+
117
+ // Verify jobset created successfully.
118
+ ginkgo .By ("checking that jobset creation succeeds" )
119
+ gomega .Expect (k8sClient .Create (ctx , js )).Should (gomega .Succeed ())
120
+
121
+ // Check jobset status if specified.
122
+ ginkgo .By ("checking jobset condition" )
123
+ util .JobSetCompleted (ctx , k8sClient , js , timeout )
124
+
125
+ // We get the latest version of the jobset before removing the finalizer
126
+ var fresh jobset.JobSet
127
+ gomega .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : js .Name , Namespace : js .Namespace }, & fresh )).Should (gomega .Succeed ())
128
+
129
+ // We remove the jobset finalizer, so it can get deleted when ttl expires.
130
+ util .RemoveJobSetFinalizer (ctx , k8sClient , & fresh , testFinalizer )
131
+
132
+ // Check jobset is cleaned up after ttl seconds.
133
+ ginkgo .By ("checking jobset is cleaned up after ttl seconds" )
134
+ util .JobSetDeleted (ctx , k8sClient , & fresh , timeout )
135
+ })
136
+ })
108
137
109
138
}) // end of Describe
110
139
@@ -197,3 +226,25 @@ func pingTestJobSetSubdomain(ns *corev1.Namespace) *testing.JobSetWrapper {
197
226
Replicas (int32 (replicas )).
198
227
Obj ())
199
228
}
229
+
230
+ func sleepTestJobSet (ns * corev1.Namespace ) * testing.JobSetWrapper {
231
+ jsName := "js"
232
+ rjobName := "rjob"
233
+ replicas := 4
234
+ return testing .MakeJobSet (jsName , ns .Name ).
235
+ ReplicatedJob (testing .MakeReplicatedJob (rjobName ).
236
+ Job (testing .MakeJobTemplate ("job" , ns .Name ).
237
+ PodSpec (corev1.PodSpec {
238
+ RestartPolicy : "Never" ,
239
+ Containers : []corev1.Container {
240
+ {
241
+ Name : "sleep-test-container" ,
242
+ Image : "bash:latest" ,
243
+ Command : []string {"bash" , "-c" },
244
+ Args : []string {"sleep 20" },
245
+ },
246
+ },
247
+ }).Obj ()).
248
+ Replicas (int32 (replicas )).
249
+ Obj ())
250
+ }
0 commit comments