Skip to content

Commit

Permalink
Merge pull request #1970 from chengchengpei/cpei/fix_noEngine
Browse files Browse the repository at this point in the history
fixed noEngine
  • Loading branch information
axsaucedo authored Jul 15, 2020
2 parents cbd86d5 + 4558aa3 commit 3730769
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 3 deletions.
143 changes: 143 additions & 0 deletions operator/controllers/noengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
6 changes: 3 additions & 3 deletions operator/controllers/seldondeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (r *SeldonDeploymentReconciler) createComponents(mlDep *machinelearningv1.S
// Attempt to set httpAllowed and grpcAllowed to false if we have an noEngine predictor
for i := 0; i < len(mlDep.Spec.Predictors); i++ {
p := mlDep.Spec.Predictors[i]
_, noEngine := p.Annotations[machinelearningv1.ANNOTATION_NO_ENGINE]
noEngine := strings.ToLower(p.Annotations[machinelearningv1.ANNOTATION_NO_ENGINE]) == "true"
if noEngine && len(p.ComponentSpecs) > 0 && len(p.ComponentSpecs[0].Spec.Containers) > 0 {
pu := machinelearningv1.GetPredictiveUnit(&p.Graph, p.ComponentSpecs[0].Spec.Containers[0].Name)
if pu != nil {
Expand All @@ -393,11 +393,11 @@ func (r *SeldonDeploymentReconciler) createComponents(mlDep *machinelearningv1.S

for i := 0; i < len(mlDep.Spec.Predictors); i++ {
p := mlDep.Spec.Predictors[i]
_, noEngine := p.Annotations[machinelearningv1.ANNOTATION_NO_ENGINE]
noEngine := strings.ToLower(p.Annotations[machinelearningv1.ANNOTATION_NO_ENGINE]) == "true"
pSvcName := machinelearningv1.GetPredictorKey(mlDep, &p)
log.Info("pSvcName", "val", pSvcName)
// Add engine deployment if separate
_, hasSeparateEnginePod := mlDep.Spec.Annotations[machinelearningv1.ANNOTATION_SEPARATE_ENGINE]
hasSeparateEnginePod := strings.ToLower(mlDep.Spec.Annotations[machinelearningv1.ANNOTATION_SEPARATE_ENGINE]) == "true"
if hasSeparateEnginePod && !noEngine {
deploy, err := createEngineDeployment(mlDep, &p, pSvcName, engine_http_port, engine_grpc_port)
if err != nil {
Expand Down

0 comments on commit 3730769

Please sign in to comment.