Skip to content

Commit

Permalink
backport of commit f5491d7
Browse files Browse the repository at this point in the history
  • Loading branch information
ndhanushkodi committed Oct 17, 2023
1 parent a0e0f50 commit 5a16a3c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (b *Builder) buildExposePaths(workload *pbcatalog.Workload) {
}

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{
Name: listenerName,
Expand All @@ -44,7 +44,7 @@ func (b *Builder) addExposePathsListener(workload *pbcatalog.Workload, exposePat
listener.BindAddress = &pbproxystate.Listener_HostPort{
HostPort: &pbproxystate.HostPortAddress{
Host: meshAddress.Host,
Port: exposePath.LocalPathPort,
Port: exposePath.ListenerPort,
},
}

Expand Down Expand Up @@ -120,12 +120,21 @@ func (b *Builder) addExposePathsRoute(exposePath *pbmesh.ExposePath, clusterName

func exposePathName(exposePath *pbmesh.ExposePath) string {
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 exposePathListenerName(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)
listenerName := fmt.Sprintf("exposed_path_%s", pathPort)
return listenerName
}

func exposePathDestinationName(exposePath *pbmesh.ExposePath) string {
path := exposePathName(exposePath)
return fmt.Sprintf("exposed_path_filter_%s_%d", path, exposePath.ListenerPort)
// The destination of the expose path is to the local port.
return fmt.Sprintf("exposed_path_destination_%s%d", exposePathName(exposePath), exposePath.LocalPathPort)
}

func exposePathClusterName(exposePath *pbmesh.ExposePath) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@
"direction": "DIRECTION_INBOUND",
"hostPort": {
"host": "10.0.0.1",
"port": 9090
"port": 1234
},
"name": "exposed_path_health",
"name": "exposed_path_health1234",
"routers": [
{
"l7": {
"route": {
"name": "exposed_path_filter_health_1234"
"name": "exposed_path_destination_health9090"
},
"statPrefix": "exposed_path_filter_health_1234",
"statPrefix": "exposed_path_destination_health9090",
"staticRoute": true
}
}
Expand All @@ -126,31 +126,31 @@
"direction": "DIRECTION_INBOUND",
"hostPort": {
"host": "10.0.0.1",
"port": 9091
"port": 1235
},
"name": "exposed_path_GetHealth",
"name": "exposed_path_GetHealth1235",
"routers": [
{
"l7": {
"protocol": "L7_PROTOCOL_HTTP2",
"route": {
"name": "exposed_path_filter_GetHealth_1235"
"name": "exposed_path_destination_GetHealth9091"
},
"statPrefix": "exposed_path_filter_GetHealth_1235",
"statPrefix": "exposed_path_destination_GetHealth9091",
"staticRoute": true
}
}
]
}
],
"routes": {
"exposed_path_filter_GetHealth_1235": {
"exposed_path_destination_GetHealth9091": {
"virtualHosts": [
{
"domains": [
"*"
],
"name": "exposed_path_filter_GetHealth_1235",
"name": "exposed_path_destination_GetHealth9091",
"routeRules": [
{
"destination": {
Expand All @@ -168,13 +168,13 @@
}
]
},
"exposed_path_filter_health_1234": {
"exposed_path_destination_health9090": {
"virtualHosts": [
{
"domains": [
"*"
],
"name": "exposed_path_filter_health_1234",
"name": "exposed_path_destination_health9090",
"routeRules": [
{
"destination": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@
"direction": "DIRECTION_INBOUND",
"hostPort": {
"host": "10.0.0.1",
"port": 9090
"port": 1234
},
"name": "exposed_path_health",
"name": "exposed_path_health1234",
"routers": [
{
"l7": {
"route": {
"name": "exposed_path_filter_health_1234"
"name": "exposed_path_destination_health9090"
},
"statPrefix": "exposed_path_filter_health_1234",
"statPrefix": "exposed_path_destination_health9090",
"staticRoute": true
}
}
Expand All @@ -188,31 +188,31 @@
"direction": "DIRECTION_INBOUND",
"hostPort": {
"host": "10.0.0.1",
"port": 9091
"port": 1235
},
"name": "exposed_path_GetHealth",
"name": "exposed_path_GetHealth1235",
"routers": [
{
"l7": {
"protocol": "L7_PROTOCOL_HTTP2",
"route": {
"name": "exposed_path_filter_GetHealth_1235"
"name": "exposed_path_destination_GetHealth9091"
},
"statPrefix": "exposed_path_filter_GetHealth_1235",
"statPrefix": "exposed_path_destination_GetHealth9091",
"staticRoute": true
}
}
]
}
],
"routes": {
"exposed_path_filter_GetHealth_1235": {
"exposed_path_destination_GetHealth9091": {
"virtualHosts": [
{
"domains": [
"*"
],
"name": "exposed_path_filter_GetHealth_1235",
"name": "exposed_path_destination_GetHealth9091",
"routeRules": [
{
"destination": {
Expand All @@ -230,13 +230,13 @@
}
]
},
"exposed_path_filter_health_1234": {
"exposed_path_destination_health9090": {
"virtualHosts": [
{
"domains": [
"*"
],
"name": "exposed_path_filter_health_1234",
"name": "exposed_path_destination_health9090",
"routeRules": [
{
"destination": {
Expand Down

0 comments on commit 5a16a3c

Please sign in to comment.