-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kuma-cp) probes without inbound (#1199)
Do `redirect` for probes that don't have inbound Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
- Loading branch information
1 parent
304f36b
commit f458cf0
Showing
5 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package routes | ||
|
||
import ( | ||
envoy_route "github.com/envoyproxy/go-control-plane/envoy/api/v2/route" | ||
) | ||
|
||
// Redirect for paths that match to matchPath returns 301 status code with new port and path | ||
func Redirect(matchPath, newPath string, allowGetOnly bool, port uint32) VirtualHostBuilderOpt { | ||
return VirtualHostBuilderOptFunc(func(config *VirtualHostBuilderConfig) { | ||
config.Add(&RedirectConfigurer{ | ||
matchPath: matchPath, | ||
newPath: newPath, | ||
port: port, | ||
allowGetOnly: allowGetOnly, | ||
}) | ||
}) | ||
} | ||
|
||
type RedirectConfigurer struct { | ||
matchPath string | ||
newPath string | ||
port uint32 | ||
allowGetOnly bool | ||
} | ||
|
||
func (c RedirectConfigurer) Configure(virtualHost *envoy_route.VirtualHost) error { | ||
var headersMatcher []*envoy_route.HeaderMatcher | ||
if c.allowGetOnly { | ||
headersMatcher = []*envoy_route.HeaderMatcher{ | ||
{ | ||
Name: ":method", | ||
HeaderMatchSpecifier: &envoy_route.HeaderMatcher_ExactMatch{ | ||
ExactMatch: "GET", | ||
}, | ||
}, | ||
} | ||
} | ||
virtualHost.Routes = append(virtualHost.Routes, &envoy_route.Route{ | ||
Match: &envoy_route.RouteMatch{ | ||
PathSpecifier: &envoy_route.RouteMatch_Path{ | ||
Path: c.matchPath, | ||
}, | ||
Headers: headersMatcher, | ||
}, | ||
Action: &envoy_route.Route_Redirect{ | ||
Redirect: &envoy_route.RedirectAction{ | ||
PortRedirect: c.port, | ||
PathRewriteSpecifier: &envoy_route.RedirectAction_PathRedirect{ | ||
PathRedirect: c.newPath, | ||
}, | ||
}, | ||
}, | ||
}) | ||
return nil | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
resources: | ||
- name: probe:listener | ||
resource: | ||
'@type': type.googleapis.com/envoy.api.v2.Listener | ||
address: | ||
socketAddress: | ||
portValue: 9000 | ||
filterChains: | ||
- filters: | ||
- name: envoy.filters.network.http_connection_manager | ||
typedConfig: | ||
'@type': type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager | ||
httpFilters: | ||
- name: envoy.filters.http.router | ||
routeConfig: | ||
virtualHosts: | ||
- domains: | ||
- '*' | ||
name: probe | ||
routes: | ||
- match: | ||
headers: | ||
- exactMatch: GET | ||
name: :method | ||
path: /8080/healthz/probe | ||
redirect: | ||
pathRedirect: /healthz/probe | ||
portRedirect: 8080 | ||
statPrefix: probe_listener | ||
name: probe:listener | ||
trafficDirection: INBOUND |