diff --git a/operator/controllers/noengine_test.go b/operator/controllers/noengine_test.go index 796516f54f..b99ae5cecd 100644 --- a/operator/controllers/noengine_test.go +++ b/operator/controllers/noengine_test.go @@ -86,3 +86,146 @@ var _ = Describe("Create a Seldon Deployment without engine", func() { }) }) + +var _ = Describe("Create a Seldon Deployment with engine", func() { + const timeout = time.Second * 30 + const interval = time.Second * 1 + By("Creating a resource") + It("should create a resource with defaults", func() { + Expect(k8sClient).NotTo(BeNil()) + var modelType = machinelearningv1.MODEL + key := types.NamespacedName{ + Name: "dep2-1", + Namespace: "default", + } + instance := &machinelearningv1.SeldonDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: key.Name, + Namespace: key.Namespace, + }, + Spec: machinelearningv1.SeldonDeploymentSpec{ + Name: "mydep2-1", + Predictors: []machinelearningv1.PredictorSpec{ + { + Annotations: map[string]string{ + "seldon.io/no-engine": "false", + }, + Name: "p1", + ComponentSpecs: []*machinelearningv1.SeldonPodSpec{ + { + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Image: "seldonio/mock_classifier:1.0", + Name: "classifier", + }, + }, + }, + }, + }, + Graph: machinelearningv1.PredictiveUnit{ + Name: "classifier", + Type: &modelType, + }, + }, + }, + }, + } + + // Run Defaulter + instance.Default() + + Expect(k8sClient.Create(context.Background(), instance)).Should(Succeed()) + //time.Sleep(time.Second * 5) + + fetched := &machinelearningv1.SeldonDeployment{} + Eventually(func() error { + err := k8sClient.Get(context.Background(), key, fetched) + return err + }, timeout, interval).Should(BeNil()) + Expect(fetched.Name).Should(Equal("dep2-1")) + + depKey := types.NamespacedName{ + Name: machinelearningv1.GetDeploymentName(instance, instance.Spec.Predictors[0], instance.Spec.Predictors[0].ComponentSpecs[0], 0), + Namespace: "default", + } + depFetched := &appsv1.Deployment{} + Eventually(func() error { + err := k8sClient.Get(context.Background(), depKey, depFetched) + return err + }, timeout, interval).Should(BeNil()) + Expect(len(depFetched.Spec.Template.Spec.Containers)).Should(Equal(2)) + + Expect(k8sClient.Delete(context.Background(), instance)).Should(Succeed()) + }) +}) + +var _ = Describe("Create a Seldon Deployment without seldon.io/no-engine annotation", func() { + const timeout = time.Second * 30 + const interval = time.Second * 1 + By("Creating a resource") + It("should create a resource with defaults", func() { + Expect(k8sClient).NotTo(BeNil()) + var modelType = machinelearningv1.MODEL + key := types.NamespacedName{ + Name: "dep2-2", + Namespace: "default", + } + instance := &machinelearningv1.SeldonDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: key.Name, + Namespace: key.Namespace, + }, + Spec: machinelearningv1.SeldonDeploymentSpec{ + Name: "mydep2-2", + Predictors: []machinelearningv1.PredictorSpec{ + { + Name: "p1", + ComponentSpecs: []*machinelearningv1.SeldonPodSpec{ + { + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Image: "seldonio/mock_classifier:1.0", + Name: "classifier", + }, + }, + }, + }, + }, + Graph: machinelearningv1.PredictiveUnit{ + Name: "classifier", + Type: &modelType, + }, + }, + }, + }, + } + + // Run Defaulter + instance.Default() + + Expect(k8sClient.Create(context.Background(), instance)).Should(Succeed()) + //time.Sleep(time.Second * 5) + + fetched := &machinelearningv1.SeldonDeployment{} + Eventually(func() error { + err := k8sClient.Get(context.Background(), key, fetched) + return err + }, timeout, interval).Should(BeNil()) + Expect(fetched.Name).Should(Equal("dep2-2")) + + depKey := types.NamespacedName{ + Name: machinelearningv1.GetDeploymentName(instance, instance.Spec.Predictors[0], instance.Spec.Predictors[0].ComponentSpecs[0], 0), + Namespace: "default", + } + depFetched := &appsv1.Deployment{} + Eventually(func() error { + err := k8sClient.Get(context.Background(), depKey, depFetched) + return err + }, timeout, interval).Should(BeNil()) + Expect(len(depFetched.Spec.Template.Spec.Containers)).Should(Equal(2)) + + Expect(k8sClient.Delete(context.Background(), instance)).Should(Succeed()) + }) +})