-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(kuma-cp) add route and virtual host configuration helpers (#2517)…
… (#2536) Add configuration helper adaptors for envoy VirtualHost and RouteConfiguration types. Signed-off-by: James Peach <james.peach@konghq.com> (cherry picked from commit 4012ece) Co-authored-by: James Peach <james.peach@konghq.com>
- Loading branch information
1 parent
8e3306c
commit 455b335
Showing
5 changed files
with
88 additions
and
45 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 |
---|---|---|
@@ -1,78 +1,72 @@ | ||
package routes | ||
|
||
import ( | ||
envoy_route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3" | ||
|
||
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1" | ||
envoy_common "github.com/kumahq/kuma/pkg/xds/envoy" | ||
v3 "github.com/kumahq/kuma/pkg/xds/envoy/routes/v3" | ||
) | ||
|
||
func CommonVirtualHost(name string) VirtualHostBuilderOpt { | ||
return VirtualHostBuilderOptFunc(func(config *VirtualHostBuilderConfig) { | ||
config.AddV3(&v3.CommonVirtualHostConfigurer{ | ||
Name: name, | ||
}) | ||
}) | ||
return AddVirtualHostConfigurer( | ||
v3.VirtualHostMustConfigureFunc(func(vh *envoy_route.VirtualHost) { | ||
vh.Name = name | ||
vh.Domains = []string{"*"} | ||
}), | ||
) | ||
} | ||
|
||
func Routes(routes envoy_common.Routes) VirtualHostBuilderOpt { | ||
return VirtualHostBuilderOptFunc(func(config *VirtualHostBuilderConfig) { | ||
config.AddV3(&v3.RoutesConfigurer{ | ||
return AddVirtualHostConfigurer( | ||
&v3.RoutesConfigurer{ | ||
Routes: routes, | ||
}) | ||
}) | ||
} | ||
|
||
// 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.AddV3(&v3.RedirectConfigurer{ | ||
MatchPath: matchPath, | ||
NewPath: newPath, | ||
Port: port, | ||
AllowGetOnly: allowGetOnly, | ||
}) | ||
return AddVirtualHostConfigurer(&v3.RedirectConfigurer{ | ||
MatchPath: matchPath, | ||
NewPath: newPath, | ||
Port: port, | ||
AllowGetOnly: allowGetOnly, | ||
}) | ||
} | ||
|
||
// ResetTagsHeader adds x-kuma-tags header to the RequestHeadersToRemove list. x-kuma-tags header is planned to be used | ||
// internally, so we don't want to expose it to the destination application. | ||
func ResetTagsHeader() RouteConfigurationBuilderOpt { | ||
return RouteConfigurationBuilderOptFunc(func(config *RouteConfigurationBuilderConfig) { | ||
config.AddV3(&v3.ResetTagsHeaderConfigurer{}) | ||
}) | ||
return AddRouteConfigurationConfigurer(&v3.ResetTagsHeaderConfigurer{}) | ||
} | ||
|
||
func TagsHeader(tags mesh_proto.MultiValueTagSet) RouteConfigurationBuilderOpt { | ||
return RouteConfigurationBuilderOptFunc(func(config *RouteConfigurationBuilderConfig) { | ||
config.AddV3(&v3.TagsHeaderConfigurer{ | ||
return AddRouteConfigurationConfigurer( | ||
&v3.TagsHeaderConfigurer{ | ||
Tags: tags, | ||
}) | ||
}) | ||
} | ||
|
||
func Route(matchPath, newPath, cluster string, allowGetOnly bool) VirtualHostBuilderOpt { | ||
return VirtualHostBuilderOptFunc(func(config *VirtualHostBuilderConfig) { | ||
config.AddV3(&v3.RouteConfigurer{ | ||
return AddVirtualHostConfigurer( | ||
&v3.RouteConfigurer{ | ||
MatchPath: matchPath, | ||
NewPath: newPath, | ||
Cluster: cluster, | ||
AllowGetOnly: allowGetOnly, | ||
}) | ||
}) | ||
} | ||
|
||
func VirtualHost(builder *VirtualHostBuilder) RouteConfigurationBuilderOpt { | ||
return RouteConfigurationBuilderOptFunc(func(config *RouteConfigurationBuilderConfig) { | ||
config.AddV3(&RouteConfigurationVirtualHostConfigurerV3{ | ||
return AddRouteConfigurationConfigurer( | ||
&RouteConfigurationVirtualHostConfigurerV3{ | ||
builder: builder, | ||
}) | ||
}) | ||
} | ||
|
||
func CommonRouteConfiguration(name string) RouteConfigurationBuilderOpt { | ||
return RouteConfigurationBuilderOptFunc(func(config *RouteConfigurationBuilderConfig) { | ||
config.AddV3(&v3.CommonRouteConfigurationConfigurer{ | ||
return AddRouteConfigurationConfigurer( | ||
&v3.CommonRouteConfigurationConfigurer{ | ||
Name: name, | ||
}) | ||
}) | ||
} |
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 was deleted.
Oops, something went wrong.
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