Skip to content

Commit

Permalink
Fix labelling panic for prepackaged servers (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
ukclivecox authored Mar 25, 2020
1 parent 371655b commit 0caa9db
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
3 changes: 3 additions & 0 deletions operator/apis/machinelearning/v1/seldondeployment_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func addDefaultsToGraph(pu *PredictiveUnit) {
if pu.Implementation == nil {
im := UNKNOWN_IMPLEMENTATION
pu.Implementation = &im
} else if IsPrepack(pu) {
ty := MODEL
pu.Type = &ty
}
for i := 0; i < len(pu.Children); i++ {
addDefaultsToGraph(&pu.Children[i])
Expand Down
26 changes: 26 additions & 0 deletions operator/apis/machinelearning/v1/seldondeployment_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,32 @@ func TestMetricsPortAddedToTwoPrepacked(t *testing.T) {
g.Expect(pu.Endpoint.Type).To(Equal(REST))
}

func TestDefaultPrepackagedServerType(t *testing.T) {
g := NewGomegaWithT(t)
scheme := runtime.NewScheme()
C = fake.NewFakeClientWithScheme(scheme)
impl := PredictiveUnitImplementation(constants.PrePackedServerTensorflow)
spec := &SeldonDeploymentSpec{
Predictors: []PredictorSpec{
{
Name: "p1",
Graph: &PredictiveUnit{
Name: "classifier",
Implementation: &impl,
},
},
},
}

spec.DefaultSeldonDeployment("mydep", "default")

// Graph
pu := GetPredictiveUnit(spec.Predictors[0].Graph, "classifier")
g.Expect(pu).ToNot(BeNil())
g.Expect(pu.Endpoint.Type).To(Equal(REST))
g.Expect(*pu.Type).To(Equal(MODEL))
}

func TestValidateSingleModel(t *testing.T) {
g := NewGomegaWithT(t)
spec := &SeldonDeploymentSpec{
Expand Down
24 changes: 13 additions & 11 deletions operator/controllers/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import (
)

func addLabelsToService(svc *corev1.Service, pu *machinelearningv1.PredictiveUnit, p machinelearningv1.PredictorSpec) {
switch *pu.Type {
case machinelearningv1.ROUTER:
svc.Labels[machinelearningv1.Label_router] = "true"
case machinelearningv1.COMBINER:
svc.Labels[machinelearningv1.Label_combiner] = "true"
case machinelearningv1.MODEL:
svc.Labels[machinelearningv1.Label_model] = "true"
case machinelearningv1.TRANSFORMER:
svc.Labels[machinelearningv1.Label_transformer] = "true"
case machinelearningv1.OUTPUT_TRANSFORMER:
svc.Labels[machinelearningv1.Label_output_transformer] = "true"
if pu.Type != nil {
switch *pu.Type {
case machinelearningv1.ROUTER:
svc.Labels[machinelearningv1.Label_router] = "true"
case machinelearningv1.COMBINER:
svc.Labels[machinelearningv1.Label_combiner] = "true"
case machinelearningv1.MODEL:
svc.Labels[machinelearningv1.Label_model] = "true"
case machinelearningv1.TRANSFORMER:
svc.Labels[machinelearningv1.Label_transformer] = "true"
case machinelearningv1.OUTPUT_TRANSFORMER:
svc.Labels[machinelearningv1.Label_output_transformer] = "true"
}
}
if p.Shadow != true && (p.Traffic >= 50 || p.Traffic == 0) {
svc.Labels[machinelearningv1.Label_default] = "true"
Expand Down

0 comments on commit 0caa9db

Please sign in to comment.