diff --git a/services/core/fuse/config.yaml b/services/core/fuse/config.yaml index 603da25..6be1c81 100644 --- a/services/core/fuse/config.yaml +++ b/services/core/fuse/config.yaml @@ -2,12 +2,18 @@ service: name: fuse domain: core entrypoint: http://localhost:2221 - advertise_address: 127.0.0.1 + + logging: + level: debug + network: - port: 18000 + bind_port: 18000 + internal: + host: localhost + port: 18000 fuse: address: http://localhost:18000 listener: - address: 0.0.0.0 - port: 10000 \ No newline at end of file + address: localhost + port: 10000 diff --git a/services/core/fuse/control_plane/controller.go b/services/core/fuse/control_plane/controller.go index fd44dfc..5c9bf3a 100644 --- a/services/core/fuse/control_plane/controller.go +++ b/services/core/fuse/control_plane/controller.go @@ -1,10 +1,11 @@ package control_plane import ( + "cmp" "context" "errors" - "fmt" "net/http" + "slices" "time" ntv1 "github.com/steady-bytes/draft/api/core/control_plane/networking/v1" @@ -307,7 +308,14 @@ func makeCluster(r *ntv1.Route, loadAssignment *endpoint.ClusterLoadAssignment) // // `nt_route` :route configuration that is being added to the snapshot. func makeRouterConfig(routes map[string]*anypb.Any) *route.RouteConfiguration { - var virtualHosts []*route.VirtualHost + var ( + virtualHosts []*route.VirtualHost + defaultVirtualHost = &route.VirtualHost{ + Name: "default", + Domains: []string{"*"}, + Routes: []*route.Route{}, + } + ) for _, rt := range routes { r := &ntv1.Route{} @@ -316,13 +324,9 @@ func makeRouterConfig(routes map[string]*anypb.Any) *route.RouteConfiguration { return nil } - http := fmt.Sprintf("%s:80", r.Match.Host) - https := fmt.Sprintf("%s:443", r.Match.Host) - - virtualHosts = append(virtualHosts, &route.VirtualHost{ - Name: r.Name, - Domains: []string{r.Match.Host, http, https}, - Routes: []*route.Route{{ + // if no host is requested, add to default host + if r.Match.Host == "" { + defaultVirtualHost.Routes = append(defaultVirtualHost.Routes, &route.Route{ Match: &route.RouteMatch{ PathSpecifier: &route.RouteMatch_Prefix{ Prefix: r.Match.Prefix, @@ -338,7 +342,44 @@ func makeRouterConfig(routes map[string]*anypb.Any) *route.RouteConfiguration { }, }, TypedPerFilterConfig: map[string]*anypb.Any{}, - }}}) + }) + } else { + virtualHosts = append(virtualHosts, &route.VirtualHost{ + Name: r.Name, + Domains: []string{r.Match.Host}, + Routes: []*route.Route{{ + Match: &route.RouteMatch{ + PathSpecifier: &route.RouteMatch_Prefix{ + Prefix: r.Match.Prefix, + }, + }, + Action: &route.Route_Route{ + Route: &route.RouteAction{ + ClusterSpecifier: &route.RouteAction_Cluster{ + Cluster: clusterName(r), + }, + // disable with 0 value + Timeout: &durationpb.Duration{}, + }, + }, + TypedPerFilterConfig: map[string]*anypb.Any{}, + }}}) + } + } + + // only include the default virtual host if it's being used + if len(defaultVirtualHost.Routes) > 0 { + virtualHosts = append(virtualHosts, defaultVirtualHost) + } + + // TODO: This is a bit of a hack to force simple prefixes like "/" to be pushed to the last place in the routes slice. + // Doing this is important since you might have multiple services (routes) attached to a single host with + // one hosting a web-client with a prefix of "/" and others hosting APIs with prefixes like "/examples.crud.v1.CrudService/". + // This needs to be revisited with a proper pattern defined for enabling developers to define RouteMatch ordering. + for _, vh := range virtualHosts { + slices.SortFunc(vh.Routes, func(a, b *route.Route) int { + return cmp.Compare(b.Match.GetPrefix(), a.Match.GetPrefix()) + }) } return &route.RouteConfiguration{ diff --git a/services/core/fuse/go.mod b/services/core/fuse/go.mod index c3ce3dc..7b1163b 100644 --- a/services/core/fuse/go.mod +++ b/services/core/fuse/go.mod @@ -2,17 +2,12 @@ module github.com/steady-bytes/draft/services/core/fuse go 1.23.2 -// replace ( -// github.com/steady-bytes/draft/api => ../../../api -// github.com/steady-bytes/draft/pkg/chassis => ../../../pkg/chassis -// ) - require ( connectrpc.com/connect v1.16.2 github.com/envoyproxy/go-control-plane v0.12.0 github.com/google/uuid v1.6.0 github.com/steady-bytes/draft/api v1.0.0 - github.com/steady-bytes/draft/pkg/chassis v0.4.1 + github.com/steady-bytes/draft/pkg/chassis v0.4.3 github.com/steady-bytes/draft/pkg/loggers v0.2.3 google.golang.org/protobuf v1.34.2 ) diff --git a/services/core/fuse/go.sum b/services/core/fuse/go.sum index 6effabd..d0273ed 100644 --- a/services/core/fuse/go.sum +++ b/services/core/fuse/go.sum @@ -163,8 +163,8 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/steady-bytes/draft/api v1.0.0 h1:QIvboAJgU0fBOV6BKChLMhHYIjBTR53+LJaR3w3g0NY= github.com/steady-bytes/draft/api v1.0.0/go.mod h1:mlwxjvRiqvwySGdzVmF8voFhMffWq2F7dyd+xt6kENA= -github.com/steady-bytes/draft/pkg/chassis v0.4.1 h1:ZJLaNUyxnhm8vAzvNYDus+xUarczBGNQOtwi12m2EJM= -github.com/steady-bytes/draft/pkg/chassis v0.4.1/go.mod h1:Ee6UcaJ5rJbElW7t0pgryhir3qb12rmHhHKiyrTrdxM= +github.com/steady-bytes/draft/pkg/chassis v0.4.3 h1:M2uCRbPbU8McweZBEQSmehOfyYsa8vkUFjgjhZ/0Wz0= +github.com/steady-bytes/draft/pkg/chassis v0.4.3/go.mod h1:Ee6UcaJ5rJbElW7t0pgryhir3qb12rmHhHKiyrTrdxM= github.com/steady-bytes/draft/pkg/loggers v0.2.3 h1:tZadHH8f9fo+tRHVp3BaJlVYvKlrlX8Hd6LxncUVgAM= github.com/steady-bytes/draft/pkg/loggers v0.2.3/go.mod h1:nXeOQ6lXhsVWHzRqVcJz0JIeSW75ORVN+0izJwwnH+Y= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/services/core/fuse/main.go b/services/core/fuse/main.go index b33f818..d2c8020 100644 --- a/services/core/fuse/main.go +++ b/services/core/fuse/main.go @@ -19,7 +19,7 @@ func main() { defer chassis.New(logger). Register(chassis.RegistrationOptions{ - Namespace: "fuse", + Namespace: "core", }). WithRPCHandler(xdsServer). WithRPCHandler(controlPlaneRPC).