Skip to content

Commit 97acc79

Browse files
committed
fix dataplane tests
1 parent 87bce07 commit 97acc79

File tree

3 files changed

+87
-7
lines changed

3 files changed

+87
-7
lines changed

internal/mode/static/state/dataplane/configuration.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func BuildConfiguration(
4646
upstreams := buildUpstreams(ctx, g.Gateway.Listeners, serviceResolver, baseHTTPConfig.IPFamily)
4747
httpServers, sslServers := buildServers(g, generator)
4848
passthroughServers := buildPassthroughServers(g)
49-
streamUpstreams := buildStreamUpstreams(ctx, g.Gateway.Listeners, serviceResolver)
49+
streamUpstreams := buildStreamUpstreams(ctx, g.Gateway.Listeners, serviceResolver, baseHTTPConfig.IPFamily)
5050
backendGroups := buildBackendGroups(append(httpServers, sslServers...))
5151
keyPairs := buildSSLKeyPairs(g.ReferencedSecrets, g.Gateway.Listeners)
5252
certBundles := buildCertBundles(g.ReferencedCaCertConfigMaps, backendGroups)
@@ -114,6 +114,7 @@ func buildStreamUpstreams(
114114
ctx context.Context,
115115
listeners []*graph.Listener,
116116
resolver resolver.ServiceResolver,
117+
ipFamily IPFamilyType,
117118
) []Upstream {
118119
// There can be duplicate upstreams if multiple routes reference the same upstream.
119120
// We use a map to deduplicate them.
@@ -144,7 +145,9 @@ func buildStreamUpstreams(
144145

145146
var errMsg string
146147

147-
eps, err := resolver.Resolve(ctx, br.SvcNsName, br.ServicePort)
148+
allowedAddressType := getAllowedAddressType(ipFamily)
149+
150+
eps, err := resolver.Resolve(ctx, br.SvcNsName, br.ServicePort, allowedAddressType)
148151
if err != nil {
149152
errMsg = err.Error()
150153
}

internal/mode/static/state/dataplane/configuration_test.go

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,47 @@ func TestBuildConfiguration(t *testing.T) {
408408
pathAndType{path: "/valid", pathType: prefix}, pathAndType{path: invalidMatchesPath, pathType: prefix},
409409
)
410410

411+
tlsTR1 := graph.L4Route{
412+
Spec: graph.L4RouteSpec{
413+
Hostnames: []v1.Hostname{"app.example.com", "cafe.example.com"},
414+
BackendRef: graph.BackendRef{
415+
SvcNsName: types.NamespacedName{
416+
Namespace: "default",
417+
Name: "secure-app",
418+
},
419+
ServicePort: apiv1.ServicePort{
420+
Name: "https",
421+
Protocol: "TCP",
422+
Port: 8443,
423+
TargetPort: intstr.IntOrString{
424+
Type: intstr.Int,
425+
IntVal: 8443,
426+
},
427+
},
428+
Valid: true,
429+
},
430+
},
431+
Valid: true,
432+
}
433+
434+
tlsTR2 := graph.L4Route{
435+
Spec: graph.L4RouteSpec{
436+
Hostnames: []v1.Hostname{"test.example.com"},
437+
BackendRef: graph.BackendRef{},
438+
},
439+
Valid: true,
440+
}
441+
442+
TR1Key := graph.L4RouteKey{NamespacedName: types.NamespacedName{
443+
Namespace: "default",
444+
Name: "secure-app",
445+
}}
446+
447+
TR2Key := graph.L4RouteKey{NamespacedName: types.NamespacedName{
448+
Namespace: "default",
449+
Name: "secure-app2",
450+
}}
451+
411452
httpsHR7, expHTTPSHR7Groups, httpsRouteHR7 := createTestResources(
412453
"https-hr-7",
413454
"foo.example.com", // same as httpsHR3
@@ -596,6 +637,13 @@ func TestBuildConfiguration(t *testing.T) {
596637
},
597638
}
598639

640+
listener443_2 := v1.Listener{
641+
Name: "listener-443-2",
642+
Hostname: (*v1.Hostname)(helpers.GetPointer("*.example.com")),
643+
Port: 443,
644+
Protocol: v1.TLSProtocolType,
645+
}
646+
599647
listener8443 := v1.Listener{
600648
Name: "listener-8443",
601649
Hostname: nil,
@@ -1522,11 +1570,26 @@ func TestBuildConfiguration(t *testing.T) {
15221570
},
15231571
ResolvedSecret: &secret1NsName,
15241572
},
1573+
{
1574+
Name: "listener-443-2",
1575+
Source: listener443_2,
1576+
Valid: true,
1577+
Routes: map[graph.RouteKey]*graph.L7Route{},
1578+
L4Routes: map[graph.L4RouteKey]*graph.L4Route{
1579+
TR1Key: &tlsTR1,
1580+
TR2Key: &tlsTR2,
1581+
},
1582+
ResolvedSecret: &secret1NsName,
1583+
},
15251584
}...)
15261585
g.Routes = map[graph.RouteKey]*graph.L7Route{
15271586
graph.CreateRouteKey(hr6): routeHR6,
15281587
graph.CreateRouteKey(httpsHR6): httpsRouteHR6,
15291588
}
1589+
g.L4Routes = map[graph.L4RouteKey]*graph.L4Route{
1590+
TR1Key: &tlsTR1,
1591+
TR2Key: &tlsTR2,
1592+
}
15301593
g.ReferencedSecrets = map[types.NamespacedName]*graph.Secret{
15311594
secret1NsName: secret1,
15321595
}
@@ -1577,6 +1640,19 @@ func TestBuildConfiguration(t *testing.T) {
15771640
}...)
15781641
conf.Upstreams = []Upstream{fooUpstream}
15791642
conf.BackendGroups = []BackendGroup{expHR6Groups[0], expHTTPSHR6Groups[0]}
1643+
conf.StreamUpstreams = []Upstream{
1644+
{
1645+
Endpoints: fooEndpoints,
1646+
Name: "default_secure-app_8443",
1647+
},
1648+
}
1649+
conf.TLSPassthroughServers = []Layer4VirtualServer{
1650+
{
1651+
Hostname: "app.example.com",
1652+
UpstreamName: "default_secure-app_8443",
1653+
Port: 443,
1654+
},
1655+
}
15801656
return conf
15811657
}),
15821658
msg: "one http and one https listener with routes with valid and invalid rules",
@@ -3217,6 +3293,7 @@ func TestGetAllowedAddressType(t *testing.T) {
32173293
})
32183294
}
32193295
}
3296+
32203297
func TestCreatePassthroughServers(t *testing.T) {
32213298
testGraph := graph.Graph{
32223299
Gateway: &graph.Gateway{
@@ -3409,7 +3486,7 @@ func TestBuildStreamUpstreams(t *testing.T) {
34093486
fakeResolver := resolverfakes.FakeServiceResolver{}
34103487
fakeResolver.ResolveReturns(nil, errors.New("error"))
34113488

3412-
streamUpstreams := buildStreamUpstreams(context.Background(), testGraph.Gateway.Listeners, &fakeResolver)
3489+
streamUpstreams := buildStreamUpstreams(context.Background(), testGraph.Gateway.Listeners, &fakeResolver, Dual)
34133490

34143491
expectedStreamUpstreams := []Upstream{
34153492
{

internal/mode/static/state/graph/route_common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ func buildTLSRoute(
272272

273273
refPath := field.NewPath("spec").Child("rules").Index(0).Child("backendRefs").Index(0)
274274

275-
svcNsName, svcPort, err := getServiceAndPortFromRef(
275+
_, svcPort, err := getIPFamilyAndPortFromRef(
276276
gtr.Spec.Rules[0].BackendRefs[0],
277-
r.Source.GetNamespace(),
277+
types.NamespacedName{Namespace: r.Source.GetNamespace(), Name: r.Source.GetName()},
278278
services,
279279
refPath,
280280
)
281281
if err != nil {
282282
backendRef = BackendRef{
283-
SvcNsName: svcNsName,
283+
SvcNsName: types.NamespacedName{Namespace: r.Source.GetNamespace(), Name: r.Source.GetName()},
284284
ServicePort: svcPort,
285285
Valid: false,
286286
}
@@ -291,7 +291,7 @@ func buildTLSRoute(
291291
}
292292

293293
backendRef = BackendRef{
294-
SvcNsName: svcNsName,
294+
SvcNsName: types.NamespacedName{Namespace: r.Source.GetNamespace(), Name: r.Source.GetName()},
295295
ServicePort: svcPort,
296296
Valid: true,
297297
}

0 commit comments

Comments
 (0)