Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apis/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 82 additions & 13 deletions pkg/controller.v1beta1/suggestion/suggestion_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package suggestion
import (
"context"
"encoding/json"
"github.com/kubeflow/katib/pkg/controller.v1beta1/util"
"github.com/kubeflow/katib/pkg/util/v1beta1/katibconfig"
rbacv1 "k8s.io/api/rbac/v1"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -100,19 +103,7 @@ func TestReconcile(t *testing.T) {
mockSuggestionClient.EXPECT().ValidateAlgorithmSettings(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
mockSuggestionClient.EXPECT().SyncAssignments(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()

instance := &suggestionsv1beta1.Suggestion{
ObjectMeta: metav1.ObjectMeta{
Name: suggestionName,
Namespace: namespace,
},
Spec: suggestionsv1beta1.SuggestionSpec{
Requests: 1,
Algorithm: &commonv1beta1.AlgorithmSpec{
AlgorithmName: "random",
},
ResumePolicy: experimentsv1beta1.FromVolume,
},
}
instance := newFakeInstance()

trial := &trialsv1beta1.Trial{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -255,6 +246,84 @@ func TestReconcile(t *testing.T) {
// Test 4 - Update status condition for empty experiment
g.Expect(r.updateStatusCondition(&suggestionsv1beta1.Suggestion{}, oldS)).To(gomega.HaveOccurred())

// test 5 - Early Stopping Suggestion run
// Create early stopping config
jsonConfigEarlyStopping := map[string]katibconfig.EarlyStoppingConfig{
"median-stop": {
Image: "test-image",
ImagePullPolicy: corev1.PullAlways,
},
}
bEarlyStopping, err := json.Marshal(jsonConfigEarlyStopping)
g.Expect(err).NotTo(gomega.HaveOccurred())

// Add early stopping config to Katib config
configMap.Data[consts.LabelEarlyStoppingTag] = string(bEarlyStopping)
g.Expect(c.Update(context.TODO(), configMap)).NotTo(gomega.HaveOccurred())

// Create the suggestion
instance = newFakeInstance()
instance.Spec.EarlyStopping = &commonv1beta1.EarlyStoppingSpec{
AlgorithmName: "median-stop",
AlgorithmSettings: []commonv1beta1.EarlyStoppingSetting{
{
Name: "min_trials_required",
Value: "3",
},
{
Name: "start_step",
Value: "5",
},
},
}
g.Expect(c.Create(context.TODO(), instance)).NotTo(gomega.HaveOccurred())

// Expect that deployment with appropriate name and image is created
suggestionDeploy = &appsv1.Deployment{}
g.Eventually(func() bool {
if err = c.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: resourceName}, suggestionDeploy); err != nil {
return false
}
return len(suggestionDeploy.Spec.Template.Spec.Containers) > 0 &&
suggestionDeploy.Spec.Template.Spec.Containers[0].Image == suggestionImage
}, timeout).Should(gomega.BeTrue())

rbacName := util.GetSuggestionRBACName(instance)

// Expect that serviceAccount with appropriate name is created
suggestionServiceAccount := &corev1.ServiceAccount{}
g.Eventually(func() error {
return c.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: rbacName}, suggestionServiceAccount)
}, timeout).Should(gomega.Succeed())

// Expect that Role with appropriate name is created
suggestionRole := &rbacv1.Role{}
g.Eventually(func() error {
return c.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: rbacName}, suggestionRole)
}, timeout).Should(gomega.Succeed())

// Expect that RoleBinding with appropriate name is created
suggestionRoleBinding := &rbacv1.RoleBinding{}
g.Eventually(func() error {
return c.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: rbacName}, suggestionRoleBinding)
}, timeout).Should(gomega.Succeed())

}

func newFakeInstance() *suggestionsv1beta1.Suggestion {
return &suggestionsv1beta1.Suggestion{
ObjectMeta: metav1.ObjectMeta{
Name: suggestionName,
Namespace: namespace,
},
Spec: suggestionsv1beta1.SuggestionSpec{
Requests: 1,
Algorithm: &commonv1beta1.AlgorithmSpec{
AlgorithmName: "random",
},
ResumePolicy: experimentsv1beta1.FromVolume,
},
}
}

func newKatibConfigMapInstance() *corev1.ConfigMap {
Expand Down