Skip to content

Commit

Permalink
feat(kuma-cp) add virtual host domain name configurer
Browse files Browse the repository at this point in the history
Signed-off-by: James Peach <james.peach@konghq.com>
  • Loading branch information
jpeach committed Aug 17, 2021
1 parent a931218 commit f33ddb6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
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

0 comments on commit f33ddb6

Please sign in to comment.