Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kuma-cp) add virtual host domain name configurer #2590

Merged
merged 1 commit into from
Aug 18, 2021
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
12 changes: 12 additions & 0 deletions pkg/xds/envoy/routes/configurers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ func CommonVirtualHost(name string) VirtualHostBuilderOpt {
)
}

func DomainNames(domainNames ...string) VirtualHostBuilderOpt {
if len(domainNames) == 0 {
return VirtualHostBuilderOptFunc(nil)
}

return AddVirtualHostConfigurer(
v3.VirtualHostMustConfigureFunc(func(vh *envoy_route.VirtualHost) {
vh.Domains = domainNames
}),
)
}

func Routes(routes envoy_common.Routes) VirtualHostBuilderOpt {
return AddVirtualHostConfigurer(
&v3.RoutesConfigurer{
Expand Down
4 changes: 3 additions & 1 deletion pkg/xds/envoy/routes/virtual_host_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ func (c *VirtualHostBuilderConfig) AddV3(configurer v3.VirtualHostConfigurer) {
type VirtualHostBuilderOptFunc func(config *VirtualHostBuilderConfig)

func (f VirtualHostBuilderOptFunc) ApplyTo(config *VirtualHostBuilderConfig) {
f(config)
if f != nil {
f(config)
}
}

// AddVirtualHostConfigurer production an option that adds the given
Expand Down
34 changes: 30 additions & 4 deletions pkg/xds/envoy/routes/virtual_host_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (

var _ = Describe("RouteConfigurationVirtualHostConfigurer", func() {

type Opt = VirtualHostBuilderOpt
type testCase struct {
virtualHostName string
expected string
opts []Opt
expected string
}

Context("V3", func() {
Expand All @@ -23,7 +24,7 @@ var _ = Describe("RouteConfigurationVirtualHostConfigurer", func() {
// when
routeConfiguration, err := NewRouteConfigurationBuilder(envoy.APIV3).
Configure(VirtualHost(NewVirtualHostBuilder(envoy.APIV3).
Configure(CommonVirtualHost(given.virtualHostName)))).
Configure(given.opts...))).
Build()
// then
Expect(err).ToNot(HaveOccurred())
Expand All @@ -36,7 +37,32 @@ var _ = Describe("RouteConfigurationVirtualHostConfigurer", func() {
Expect(actual).To(MatchYAML(given.expected))
},
Entry("basic virtual host", testCase{
virtualHostName: "backend",
opts: []Opt{CommonVirtualHost("backend")},
expected: `
virtualHosts:
- domains:
- '*'
name: backend
`,
}),
Entry("virtual host with domains", testCase{
opts: []Opt{
CommonVirtualHost("backend"),
DomainNames("foo.example.com", "bar.example.com"),
},
expected: `
virtualHosts:
- domains:
- foo.example.com
- bar.example.com
name: backend
`,
}),
Entry("virtual host with empty domains", testCase{
opts: []Opt{
CommonVirtualHost("backend"),
DomainNames(),
},
expected: `
virtualHosts:
- domains:
Expand Down