@@ -132,7 +132,7 @@ func TestReconcile(t *testing.T) {
132
132
}
133
133
g .Expect (c .Create (context .TODO (), kubeflowNS )).NotTo (gomega .HaveOccurred ())
134
134
// Test 1 - Regural suggestion run
135
- // Create ConfigMap with suggestion data.
135
+ // Create ConfigMap with suggestion and early stopping data.
136
136
g .Expect (c .Create (context .TODO (), configMap )).NotTo (gomega .HaveOccurred ())
137
137
// Create the suggestion
138
138
g .Expect (c .Create (context .TODO (), instance )).NotTo (gomega .HaveOccurred ())
@@ -162,6 +162,26 @@ func TestReconcile(t *testing.T) {
162
162
return c .Get (context .TODO (), types.NamespacedName {Namespace : namespace , Name : resourceName }, & corev1.PersistentVolumeClaim {})
163
163
}, timeout ).Should (gomega .Succeed ())
164
164
165
+ rbacName := util .GetSuggestionRBACName (instance )
166
+
167
+ // Expect that serviceAccount with appropriate name is created
168
+ suggestionServiceAccount := & corev1.ServiceAccount {}
169
+ g .Eventually (func () error {
170
+ return c .Get (context .TODO (), types.NamespacedName {Namespace : namespace , Name : rbacName }, suggestionServiceAccount )
171
+ }, timeout ).Should (gomega .Succeed ())
172
+
173
+ // Expect that Role with appropriate name is created
174
+ suggestionRole := & rbacv1.Role {}
175
+ g .Eventually (func () error {
176
+ return c .Get (context .TODO (), types.NamespacedName {Namespace : namespace , Name : rbacName }, suggestionRole )
177
+ }, timeout ).Should (gomega .Succeed ())
178
+
179
+ // Expect that RoleBinding with appropriate name is created
180
+ suggestionRoleBinding := & rbacv1.RoleBinding {}
181
+ g .Eventually (func () error {
182
+ return c .Get (context .TODO (), types.NamespacedName {Namespace : namespace , Name : rbacName }, suggestionRoleBinding )
183
+ }, timeout ).Should (gomega .Succeed ())
184
+
165
185
// Manually change ready deployment status
166
186
suggestionDeploy .Status = appsv1.DeploymentStatus {
167
187
Conditions : []appsv1.DeploymentCondition {
@@ -246,24 +266,10 @@ func TestReconcile(t *testing.T) {
246
266
// Test 4 - Update status condition for empty experiment
247
267
g .Expect (r .updateStatusCondition (& suggestionsv1beta1.Suggestion {}, oldS )).To (gomega .HaveOccurred ())
248
268
249
- // test 5 - Early Stopping Suggestion run
250
- // Create early stopping config
251
- jsonConfigEarlyStopping := map [string ]katibconfig.EarlyStoppingConfig {
252
- "median-stop" : {
253
- Image : "test-image" ,
254
- ImagePullPolicy : corev1 .PullAlways ,
255
- },
256
- }
257
- bEarlyStopping , err := json .Marshal (jsonConfigEarlyStopping )
258
- g .Expect (err ).NotTo (gomega .HaveOccurred ())
259
-
260
- // Add early stopping config to Katib config
261
- configMap .Data [consts .LabelEarlyStoppingTag ] = string (bEarlyStopping )
262
- g .Expect (c .Update (context .TODO (), configMap )).NotTo (gomega .HaveOccurred ())
269
+ }
263
270
264
- // Create the suggestion
265
- instance = newFakeInstance ()
266
- instance .Spec .EarlyStopping = & commonv1beta1.EarlyStoppingSpec {
271
+ func newFakeInstance () * suggestionsv1beta1.Suggestion {
272
+ earlyStoppingSpec := & commonv1beta1.EarlyStoppingSpec {
267
273
AlgorithmName : "median-stop" ,
268
274
AlgorithmSettings : []commonv1beta1.EarlyStoppingSetting {
269
275
{
@@ -276,41 +282,6 @@ func TestReconcile(t *testing.T) {
276
282
},
277
283
},
278
284
}
279
- g .Expect (c .Create (context .TODO (), instance )).NotTo (gomega .HaveOccurred ())
280
-
281
- // Expect that deployment with appropriate name and image is created
282
- suggestionDeploy = & appsv1.Deployment {}
283
- g .Eventually (func () bool {
284
- if err = c .Get (context .TODO (), types.NamespacedName {Namespace : namespace , Name : resourceName }, suggestionDeploy ); err != nil {
285
- return false
286
- }
287
- return len (suggestionDeploy .Spec .Template .Spec .Containers ) > 0 &&
288
- suggestionDeploy .Spec .Template .Spec .Containers [0 ].Image == suggestionImage
289
- }, timeout ).Should (gomega .BeTrue ())
290
-
291
- rbacName := util .GetSuggestionRBACName (instance )
292
-
293
- // Expect that serviceAccount with appropriate name is created
294
- suggestionServiceAccount := & corev1.ServiceAccount {}
295
- g .Eventually (func () error {
296
- return c .Get (context .TODO (), types.NamespacedName {Namespace : namespace , Name : rbacName }, suggestionServiceAccount )
297
- }, timeout ).Should (gomega .Succeed ())
298
-
299
- // Expect that Role with appropriate name is created
300
- suggestionRole := & rbacv1.Role {}
301
- g .Eventually (func () error {
302
- return c .Get (context .TODO (), types.NamespacedName {Namespace : namespace , Name : rbacName }, suggestionRole )
303
- }, timeout ).Should (gomega .Succeed ())
304
-
305
- // Expect that RoleBinding with appropriate name is created
306
- suggestionRoleBinding := & rbacv1.RoleBinding {}
307
- g .Eventually (func () error {
308
- return c .Get (context .TODO (), types.NamespacedName {Namespace : namespace , Name : rbacName }, suggestionRoleBinding )
309
- }, timeout ).Should (gomega .Succeed ())
310
-
311
- }
312
-
313
- func newFakeInstance () * suggestionsv1beta1.Suggestion {
314
285
return & suggestionsv1beta1.Suggestion {
315
286
ObjectMeta : metav1.ObjectMeta {
316
287
Name : suggestionName ,
@@ -321,23 +292,36 @@ func newFakeInstance() *suggestionsv1beta1.Suggestion {
321
292
Algorithm : & commonv1beta1.AlgorithmSpec {
322
293
AlgorithmName : "random" ,
323
294
},
324
- ResumePolicy : experimentsv1beta1 .FromVolume ,
295
+ ResumePolicy : experimentsv1beta1 .FromVolume ,
296
+ EarlyStopping : earlyStoppingSpec ,
325
297
},
326
298
}
327
299
}
328
300
329
301
func newKatibConfigMapInstance () * corev1.ConfigMap {
302
+ // Create suggestion config
330
303
suggestionConfig := map [string ]map [string ]string {
331
304
"random" : {"image" : suggestionImage },
332
305
}
333
- b , _ := json .Marshal (suggestionConfig )
306
+ bSuggestionConfig , _ := json .Marshal (suggestionConfig )
307
+
308
+ // Create early stopping config
309
+ jsonConfigEarlyStopping := map [string ]katibconfig.EarlyStoppingConfig {
310
+ "median-stop" : {
311
+ Image : "test-image" ,
312
+ ImagePullPolicy : corev1 .PullAlways ,
313
+ },
314
+ }
315
+ bEarlyStopping , _ := json .Marshal (jsonConfigEarlyStopping )
316
+
334
317
return & corev1.ConfigMap {
335
318
ObjectMeta : metav1.ObjectMeta {
336
319
Name : katibConfigName ,
337
320
Namespace : namespace ,
338
321
},
339
322
Data : map [string ]string {
340
- "suggestion" : string (b ),
323
+ consts .LabelSuggestionTag : string (bSuggestionConfig ),
324
+ consts .LabelEarlyStoppingTag : string (bEarlyStopping ),
341
325
},
342
326
}
343
327
}
0 commit comments