Skip to content

Commit

Permalink
Use FQDN in the host field of Istio resources (#4408)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysk24ok committed Feb 17, 2023
1 parent 93431cb commit 8d0d70e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions operator/controllers/seldondeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ func init() {
istio_networking.GatewayUnmarshaler.AllowUnknownFields = true
}

func createFqdn(svcName string, namespace string) string {
return svcName + "." + namespace + ".svc.cluster.local"
}

func createAddressableResource(mlDep *machinelearningv1.SeldonDeployment, namespace string, externalPorts []httpGrpcPorts) (*machinelearningv1.SeldonAddressable, error) {
// It was an explicit design decision to expose the service name instead of the ingress
// Currently there will only be a URL for the first predictor, and assumes always REST
firstPredictor := &mlDep.Spec.Predictors[0]
sdepSvcName := machinelearningv1.GetPredictorKey(mlDep, firstPredictor)
addressableHost := sdepSvcName + "." + namespace + ".svc.cluster.local" + ":" + strconv.Itoa(externalPorts[0].httpPort)
addressableHost := createFqdn(sdepSvcName, namespace) + ":" + strconv.Itoa(externalPorts[0].httpPort)
addressablePath := utils.GetPredictionPath(mlDep)
addressableUrl := url.URL{Scheme: "http", Host: addressableHost, Path: addressablePath}

Expand Down Expand Up @@ -294,14 +298,15 @@ func createIstioResources(mlDep *machinelearningv1.SeldonDeployment,

p := mlDep.Spec.Predictors[i]
pSvcName := machinelearningv1.GetPredictorKey(mlDep, &p)
pSvcFqdn := createFqdn(pSvcName, namespace)

drule := &istio.DestinationRule{
ObjectMeta: metav1.ObjectMeta{
Name: pSvcName,
Namespace: namespace,
},
Spec: istio_networking.DestinationRule{
Host: pSvcName,
Host: pSvcFqdn,
Subsets: []*istio_networking.Subset{
{
Name: p.Name,
Expand All @@ -327,15 +332,15 @@ func createIstioResources(mlDep *machinelearningv1.SeldonDeployment,
//if there's a shadow then add a mirror section to the VirtualService

vsvc.Spec.Http[0].Mirror = &istio_networking.Destination{
Host: pSvcName,
Host: pSvcFqdn,
Subset: p.Name,
Port: &istio_networking.PortSelector{
Number: uint32(ports[i].httpPort),
},
}

vsvc.Spec.Http[1].Mirror = &istio_networking.Destination{
Host: pSvcName,
Host: pSvcFqdn,
Subset: p.Name,
Port: &istio_networking.PortSelector{
Number: uint32(ports[i].grpcPort),
Expand All @@ -360,7 +365,7 @@ func createIstioResources(mlDep *machinelearningv1.SeldonDeployment,
//so not by tag - different destinations (like https://istio.io/docs/tasks/traffic-management/traffic-shifting/) distinguished by host
routesHttp[routesIdx] = &istio_networking.HTTPRouteDestination{
Destination: &istio_networking.Destination{
Host: pSvcName,
Host: pSvcFqdn,
Subset: p.Name,
Port: &istio_networking.PortSelector{
Number: uint32(ports[i].httpPort),
Expand All @@ -370,7 +375,7 @@ func createIstioResources(mlDep *machinelearningv1.SeldonDeployment,
}
routesGrpc[routesIdx] = &istio_networking.HTTPRouteDestination{
Destination: &istio_networking.Destination{
Host: pSvcName,
Host: pSvcFqdn,
Subset: p.Name,
Port: &istio_networking.PortSelector{
Number: uint32(ports[i].grpcPort),
Expand Down

0 comments on commit 8d0d70e

Please sign in to comment.