in pkg/gateway/model_build_lattice_service.go [105:173]
func (t *latticeServiceModelBuildTask) buildLatticeService(ctx context.Context) (*model.Service, error) {
var routeType core.RouteType
switch t.route.(type) {
case *core.HTTPRoute:
routeType = core.HttpRouteType
case *core.GRPCRoute:
routeType = core.GrpcRouteType
case *core.TLSRoute:
routeType = core.TlsRouteType
default:
return nil, fmt.Errorf("unsupported route type: %T", t.route)
}
spec := model.ServiceSpec{
ServiceTagFields: model.ServiceTagFields{
RouteName: t.route.Name(),
RouteNamespace: t.route.Namespace(),
RouteType: routeType,
},
}
for _, parentRef := range t.route.Spec().ParentRefs() {
gw := &gwv1.Gateway{}
parentNamespace := t.route.Namespace()
if parentRef.Namespace != nil {
parentNamespace = string(*parentRef.Namespace)
}
err := t.client.Get(ctx, client.ObjectKey{Name: string(parentRef.Name), Namespace: parentNamespace}, gw)
if err != nil {
t.log.Infof(ctx, "Ignoring route %s because failed to get gateway %s: %v", t.route.Name(), gw.Spec.GatewayClassName, err)
continue
}
if k8s.IsControlledByLatticeGatewayController(ctx, t.client, gw) {
spec.ServiceNetworkNames = append(spec.ServiceNetworkNames, string(parentRef.Name))
} else {
t.log.Infof(ctx, "Ignoring route %s because gateway %s is not managed by lattice gateway controller", t.route.Name(), gw.Name)
}
}
if config.ServiceNetworkOverrideMode {
spec.ServiceNetworkNames = []string{config.DefaultServiceNetwork}
}
if len(t.route.Spec().Hostnames()) > 0 {
// The 1st hostname will be used as lattice customer-domain-name
spec.CustomerDomainName = string(t.route.Spec().Hostnames()[0])
t.log.Infof(ctx, "Setting customer-domain-name: %s for route %s-%s",
spec.CustomerDomainName, t.route.Name(), t.route.Namespace())
} else {
t.log.Infof(ctx, "No custom-domain-name for route %s-%s",
t.route.Name(), t.route.Namespace())
spec.CustomerDomainName = ""
}
certArn, err := t.getACMCertArn(ctx)
if err != nil {
return nil, err
}
spec.CustomerCertARN = certArn
svc, err := model.NewLatticeService(t.stack, spec)
if err != nil {
return nil, err
}
t.log.Debugf(ctx, "Added service %s to the stack (ID %s)", svc.Spec.LatticeServiceName(), svc.ID())
svc.IsDeleted = !t.route.DeletionTimestamp().IsZero()
return svc, nil
}