fix expose paths (#19257)

When testing adding http probes to apps, I ran into some issues which I fixed here:
- The listener should be listening on the exposed listener port, updated that.
- The listener and route names were pointing to the path of the exposed path. In my test, the path was "/" resulting in an empty string path. Also, the path may not be unique across exposed path listeners, so I decided to use the path+exposed port as the unique identifier.
This commit is contained in:
Nitya Dhanushkodi 2023-10-17 14:47:21 -07:00 committed by GitHub
parent 9b719e6dec
commit 51b58cd910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 32 deletions

View File

@ -29,7 +29,7 @@ func (b *Builder) buildExposePaths(workload *pbcatalog.Workload) {
} }
func (b *Builder) addExposePathsListener(workload *pbcatalog.Workload, exposePath *pbmesh.ExposePath) *ListenerBuilder { func (b *Builder) addExposePathsListener(workload *pbcatalog.Workload, exposePath *pbmesh.ExposePath) *ListenerBuilder {
listenerName := fmt.Sprintf("exposed_path_%s", exposePathName(exposePath)) listenerName := exposePathListenerName(exposePath)
listener := &pbproxystate.Listener{ listener := &pbproxystate.Listener{
Name: listenerName, Name: listenerName,
@ -44,7 +44,7 @@ func (b *Builder) addExposePathsListener(workload *pbcatalog.Workload, exposePat
listener.BindAddress = &pbproxystate.Listener_HostPort{ listener.BindAddress = &pbproxystate.Listener_HostPort{
HostPort: &pbproxystate.HostPortAddress{ HostPort: &pbproxystate.HostPortAddress{
Host: meshAddress.Host, Host: meshAddress.Host,
Port: exposePath.LocalPathPort, Port: exposePath.ListenerPort,
}, },
} }
@ -55,7 +55,7 @@ func (b *ListenerBuilder) addExposePathsRouter(exposePath *pbmesh.ExposePath) *L
if b.listener == nil { if b.listener == nil {
return b return b
} }
destinationName := exposePathDestinationName(exposePath) destinationName := exposePathRouteName(exposePath)
var l7Protocol pbproxystate.L7Protocol var l7Protocol pbproxystate.L7Protocol
@ -88,7 +88,7 @@ func (b *ListenerBuilder) addExposePathsRouter(exposePath *pbmesh.ExposePath) *L
} }
func (b *Builder) addExposePathsRoute(exposePath *pbmesh.ExposePath, clusterName string) *Builder { func (b *Builder) addExposePathsRoute(exposePath *pbmesh.ExposePath, clusterName string) *Builder {
routeName := exposePathDestinationName(exposePath) routeName := exposePathRouteName(exposePath)
routeRule := &pbproxystate.RouteRule{ routeRule := &pbproxystate.RouteRule{
Match: &pbproxystate.RouteMatch{ Match: &pbproxystate.RouteMatch{
PathMatch: &pbproxystate.PathMatch{ PathMatch: &pbproxystate.PathMatch{
@ -120,12 +120,22 @@ func (b *Builder) addExposePathsRoute(exposePath *pbmesh.ExposePath, clusterName
func exposePathName(exposePath *pbmesh.ExposePath) string { func exposePathName(exposePath *pbmesh.ExposePath) string {
r := regexp.MustCompile(`[^a-zA-Z0-9]+`) r := regexp.MustCompile(`[^a-zA-Z0-9]+`)
return r.ReplaceAllString(exposePath.Path, "") // The regex removes anything not a letter or number from the path.
path := r.ReplaceAllString(exposePath.Path, "")
return path
} }
func exposePathDestinationName(exposePath *pbmesh.ExposePath) string { func exposePathListenerName(exposePath *pbmesh.ExposePath) string {
path := exposePathName(exposePath) // The path could be empty, so the unique name for this exposed path is the path and listener port.
return fmt.Sprintf("exposed_path_filter_%s_%d", path, exposePath.ListenerPort) pathPort := fmt.Sprintf("%s%d", exposePathName(exposePath), exposePath.ListenerPort)
listenerName := fmt.Sprintf("exposed_path_%s", pathPort)
return listenerName
}
func exposePathRouteName(exposePath *pbmesh.ExposePath) string {
// The path could be empty, so the unique name for this exposed path is the path and listener port.
pathPort := fmt.Sprintf("%s%d", exposePathName(exposePath), exposePath.ListenerPort)
return fmt.Sprintf("exposed_path_route_%s", pathPort)
} }
func exposePathClusterName(exposePath *pbmesh.ExposePath) string { func exposePathClusterName(exposePath *pbmesh.ExposePath) string {

View File

@ -107,16 +107,16 @@
"direction": "DIRECTION_INBOUND", "direction": "DIRECTION_INBOUND",
"hostPort": { "hostPort": {
"host": "10.0.0.1", "host": "10.0.0.1",
"port": 9090 "port": 1234
}, },
"name": "exposed_path_health", "name": "exposed_path_health1234",
"routers": [ "routers": [
{ {
"l7": { "l7": {
"route": { "route": {
"name": "exposed_path_filter_health_1234" "name": "exposed_path_route_health1234"
}, },
"statPrefix": "exposed_path_filter_health_1234", "statPrefix": "exposed_path_route_health1234",
"staticRoute": true "staticRoute": true
} }
} }
@ -126,17 +126,17 @@
"direction": "DIRECTION_INBOUND", "direction": "DIRECTION_INBOUND",
"hostPort": { "hostPort": {
"host": "10.0.0.1", "host": "10.0.0.1",
"port": 9091 "port": 1235
}, },
"name": "exposed_path_GetHealth", "name": "exposed_path_GetHealth1235",
"routers": [ "routers": [
{ {
"l7": { "l7": {
"protocol": "L7_PROTOCOL_HTTP2", "protocol": "L7_PROTOCOL_HTTP2",
"route": { "route": {
"name": "exposed_path_filter_GetHealth_1235" "name": "exposed_path_route_GetHealth1235"
}, },
"statPrefix": "exposed_path_filter_GetHealth_1235", "statPrefix": "exposed_path_route_GetHealth1235",
"staticRoute": true "staticRoute": true
} }
} }
@ -144,13 +144,13 @@
} }
], ],
"routes": { "routes": {
"exposed_path_filter_GetHealth_1235": { "exposed_path_route_GetHealth1235": {
"virtualHosts": [ "virtualHosts": [
{ {
"domains": [ "domains": [
"*" "*"
], ],
"name": "exposed_path_filter_GetHealth_1235", "name": "exposed_path_route_GetHealth1235",
"routeRules": [ "routeRules": [
{ {
"destination": { "destination": {
@ -168,13 +168,13 @@
} }
] ]
}, },
"exposed_path_filter_health_1234": { "exposed_path_route_health1234": {
"virtualHosts": [ "virtualHosts": [
{ {
"domains": [ "domains": [
"*" "*"
], ],
"name": "exposed_path_filter_health_1234", "name": "exposed_path_route_health1234",
"routeRules": [ "routeRules": [
{ {
"destination": { "destination": {

View File

@ -169,16 +169,16 @@
"direction": "DIRECTION_INBOUND", "direction": "DIRECTION_INBOUND",
"hostPort": { "hostPort": {
"host": "10.0.0.1", "host": "10.0.0.1",
"port": 9090 "port": 1234
}, },
"name": "exposed_path_health", "name": "exposed_path_health1234",
"routers": [ "routers": [
{ {
"l7": { "l7": {
"route": { "route": {
"name": "exposed_path_filter_health_1234" "name": "exposed_path_route_health1234"
}, },
"statPrefix": "exposed_path_filter_health_1234", "statPrefix": "exposed_path_route_health1234",
"staticRoute": true "staticRoute": true
} }
} }
@ -188,17 +188,17 @@
"direction": "DIRECTION_INBOUND", "direction": "DIRECTION_INBOUND",
"hostPort": { "hostPort": {
"host": "10.0.0.1", "host": "10.0.0.1",
"port": 9091 "port": 1235
}, },
"name": "exposed_path_GetHealth", "name": "exposed_path_GetHealth1235",
"routers": [ "routers": [
{ {
"l7": { "l7": {
"protocol": "L7_PROTOCOL_HTTP2", "protocol": "L7_PROTOCOL_HTTP2",
"route": { "route": {
"name": "exposed_path_filter_GetHealth_1235" "name": "exposed_path_route_GetHealth1235"
}, },
"statPrefix": "exposed_path_filter_GetHealth_1235", "statPrefix": "exposed_path_route_GetHealth1235",
"staticRoute": true "staticRoute": true
} }
} }
@ -206,13 +206,13 @@
} }
], ],
"routes": { "routes": {
"exposed_path_filter_GetHealth_1235": { "exposed_path_route_GetHealth1235": {
"virtualHosts": [ "virtualHosts": [
{ {
"domains": [ "domains": [
"*" "*"
], ],
"name": "exposed_path_filter_GetHealth_1235", "name": "exposed_path_route_GetHealth1235",
"routeRules": [ "routeRules": [
{ {
"destination": { "destination": {
@ -230,13 +230,13 @@
} }
] ]
}, },
"exposed_path_filter_health_1234": { "exposed_path_route_health1234": {
"virtualHosts": [ "virtualHosts": [
{ {
"domains": [ "domains": [
"*" "*"
], ],
"name": "exposed_path_filter_health_1234", "name": "exposed_path_route_health1234",
"routeRules": [ "routeRules": [
{ {
"destination": { "destination": {