Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions services/core/fuse/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
address: localhost
port: 10000
61 changes: 51 additions & 10 deletions services/core/fuse/control_plane/controller.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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{}
Expand All @@ -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,
Expand All @@ -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{
Expand Down
7 changes: 1 addition & 6 deletions services/core/fuse/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions services/core/fuse/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion services/core/fuse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {

defer chassis.New(logger).
Register(chassis.RegistrationOptions{
Namespace: "fuse",
Namespace: "core",
}).
WithRPCHandler(xdsServer).
WithRPCHandler(controlPlaneRPC).
Expand Down
Loading