Skip to content

Commit

Permalink
feat(svc): Add predictorSpec annotations to service
Browse files Browse the repository at this point in the history
Capture predictorSpec annotations and apply them to the created
services.

Contributes to #2590

Signed-off-by: Nick Groszewski <[email protected]>
  • Loading branch information
groszewn committed Nov 15, 2020
1 parent 3d26288 commit d5b44c1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions operator/controllers/seldondeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ func createPredictorService(pSvcName string, seldonId string, p *machinelearning
machinelearningv1.Label_seldon_id: seldonId,
machinelearningv1.Label_managed_by: machinelearningv1.Label_value_seldon,
},
Annotations: map[string]string{},
},
Spec: corev1.ServiceSpec{
Selector: map[string]string{machinelearningv1.Label_seldon_app: pSvcName},
Expand All @@ -744,7 +745,6 @@ func createPredictorService(pSvcName string, seldonId string, p *machinelearning
}

if utils.GetEnv("AMBASSADOR_ENABLED", "false") == "true" {
psvc.Annotations = make(map[string]string)
//Create top level Service
ambassadorConfig, err := getAmbassadorConfigs(mlDep, p, pSvcName, engine_http_port, engine_grpc_port, isExplainer)
if err != nil {
Expand All @@ -756,6 +756,10 @@ func createPredictorService(pSvcName string, seldonId string, p *machinelearning
log.Info("Creating Headless SVC")
psvc.Spec.ClusterIP = "None"
}
// Add annotations from predictorspec
for k, v := range p.Annotations {
psvc.Annotations[k] = v
}
return psvc, err
}

Expand Down Expand Up @@ -810,9 +814,10 @@ func createContainerService(deploy *appsv1.Deployment,

svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: containerServiceValue,
Namespace: namespace,
Labels: map[string]string{containerServiceKey: containerServiceValue, machinelearningv1.Label_seldon_id: seldonId},
Name: containerServiceValue,
Namespace: namespace,
Labels: map[string]string{containerServiceKey: containerServiceValue, machinelearningv1.Label_seldon_id: seldonId},
Annotations: map[string]string{},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
Expand All @@ -832,6 +837,11 @@ func createContainerService(deploy *appsv1.Deployment,
deploy.Spec.Selector.MatchLabels[containerServiceKey] = containerServiceValue
deploy.Spec.Template.ObjectMeta.Labels[containerServiceKey] = containerServiceValue

// Add annotations from predictorspec
for k, v := range p.Annotations {
svc.Annotations[k] = v
}

if existingPort == nil || con.Ports == nil {
con.Ports = append(con.Ports, corev1.ContainerPort{Name: portType, ContainerPort: portNum, Protocol: corev1.ProtocolTCP})
}
Expand Down

0 comments on commit d5b44c1

Please sign in to comment.