Skip to content

Commit 2b6be1a

Browse files
committed
merge test5 to test1
1 parent 9f62660 commit 2b6be1a

File tree

1 file changed

+40
-56
lines changed

1 file changed

+40
-56
lines changed

pkg/controller.v1beta1/suggestion/suggestion_controller_test.go

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestReconcile(t *testing.T) {
132132
}
133133
g.Expect(c.Create(context.TODO(), kubeflowNS)).NotTo(gomega.HaveOccurred())
134134
// Test 1 - Regural suggestion run
135-
// Create ConfigMap with suggestion data.
135+
// Create ConfigMap with suggestion and early stopping data.
136136
g.Expect(c.Create(context.TODO(), configMap)).NotTo(gomega.HaveOccurred())
137137
// Create the suggestion
138138
g.Expect(c.Create(context.TODO(), instance)).NotTo(gomega.HaveOccurred())
@@ -162,6 +162,26 @@ func TestReconcile(t *testing.T) {
162162
return c.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: resourceName}, &corev1.PersistentVolumeClaim{})
163163
}, timeout).Should(gomega.Succeed())
164164

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+
165185
// Manually change ready deployment status
166186
suggestionDeploy.Status = appsv1.DeploymentStatus{
167187
Conditions: []appsv1.DeploymentCondition{
@@ -246,24 +266,10 @@ func TestReconcile(t *testing.T) {
246266
// Test 4 - Update status condition for empty experiment
247267
g.Expect(r.updateStatusCondition(&suggestionsv1beta1.Suggestion{}, oldS)).To(gomega.HaveOccurred())
248268

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+
}
263270

264-
// Create the suggestion
265-
instance = newFakeInstance()
266-
instance.Spec.EarlyStopping = &commonv1beta1.EarlyStoppingSpec{
271+
func newFakeInstance() *suggestionsv1beta1.Suggestion {
272+
earlyStoppingSpec := &commonv1beta1.EarlyStoppingSpec{
267273
AlgorithmName: "median-stop",
268274
AlgorithmSettings: []commonv1beta1.EarlyStoppingSetting{
269275
{
@@ -276,41 +282,6 @@ func TestReconcile(t *testing.T) {
276282
},
277283
},
278284
}
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 {
314285
return &suggestionsv1beta1.Suggestion{
315286
ObjectMeta: metav1.ObjectMeta{
316287
Name: suggestionName,
@@ -321,23 +292,36 @@ func newFakeInstance() *suggestionsv1beta1.Suggestion {
321292
Algorithm: &commonv1beta1.AlgorithmSpec{
322293
AlgorithmName: "random",
323294
},
324-
ResumePolicy: experimentsv1beta1.FromVolume,
295+
ResumePolicy: experimentsv1beta1.FromVolume,
296+
EarlyStopping: earlyStoppingSpec,
325297
},
326298
}
327299
}
328300

329301
func newKatibConfigMapInstance() *corev1.ConfigMap {
302+
// Create suggestion config
330303
suggestionConfig := map[string]map[string]string{
331304
"random": {"image": suggestionImage},
332305
}
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+
334317
return &corev1.ConfigMap{
335318
ObjectMeta: metav1.ObjectMeta{
336319
Name: katibConfigName,
337320
Namespace: namespace,
338321
},
339322
Data: map[string]string{
340-
"suggestion": string(b),
323+
consts.LabelSuggestionTag: string(bSuggestionConfig),
324+
consts.LabelEarlyStoppingTag: string(bEarlyStopping),
341325
},
342326
}
343327
}

0 commit comments

Comments
 (0)