Skip to content

Commit 15ef453

Browse files
committed
kate comments
1 parent 00b2a18 commit 15ef453

File tree

7 files changed

+154
-58
lines changed

7 files changed

+154
-58
lines changed

internal/mode/static/nginx/config/servers_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@ func TestExecuteServersForIPFamily(t *testing.T) {
162162
Port: 8443,
163163
},
164164
}
165+
sslServers443 := []dataplane.VirtualServer{
166+
{
167+
IsDefault: true,
168+
Port: 443,
169+
},
170+
{
171+
Hostname: "example.com",
172+
SSL: &dataplane.SSL{
173+
KeyPairID: "test-keypair",
174+
},
175+
Port: 443,
176+
},
177+
}
165178
passThroughServers := []dataplane.Layer4VirtualServer{
166179
{
167180
IsDefault: true,
@@ -198,7 +211,7 @@ func TestExecuteServersForIPFamily(t *testing.T) {
198211
msg: "http, ssl servers, and tls servers with IPv6 IP family",
199212
config: dataplane.Configuration{
200213
HTTPServers: httpServers,
201-
SSLServers: sslServers,
214+
SSLServers: append(sslServers, sslServers443...),
202215
BaseHTTPConfig: dataplane.BaseHTTPConfig{
203216
IPFamily: dataplane.IPv6,
204217
},
@@ -207,12 +220,14 @@ func TestExecuteServersForIPFamily(t *testing.T) {
207220
expectedHTTPConfig: map[string]int{
208221
"listen [::]:8080 default_server;": 1,
209222
"listen [::]:8080;": 1,
223+
"listen [::]:443 ssl default_server;": 1,
224+
"listen [::]:443 ssl;": 1,
210225
"listen unix:/var/run/nginx/https8443.sock ssl;": 1,
211226
"listen unix:/var/run/nginx/https8443.sock ssl default_server;": 1,
212-
"server_name example.com;": 2,
213-
"ssl_certificate /etc/nginx/secrets/test-keypair.pem;": 1,
214-
"ssl_certificate_key /etc/nginx/secrets/test-keypair.pem;": 1,
215-
"ssl_reject_handshake on;": 1,
227+
"server_name example.com;": 3,
228+
"ssl_certificate /etc/nginx/secrets/test-keypair.pem;": 2,
229+
"ssl_certificate_key /etc/nginx/secrets/test-keypair.pem;": 2,
230+
"ssl_reject_handshake on;": 2,
216231
},
217232
},
218233
{

internal/mode/static/nginx/config/stream_servers_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func TestExecuteStreamServersForIPFamily(t *testing.T) {
192192
config dataplane.Configuration
193193
}{
194194
{
195-
msg: "http and ssl servers with IPv4 IP family",
195+
msg: "tls servers with IPv4 IP family",
196196
config: dataplane.Configuration{
197197
BaseHTTPConfig: dataplane.BaseHTTPConfig{
198198
IPFamily: dataplane.IPv4,
@@ -202,10 +202,11 @@ func TestExecuteStreamServersForIPFamily(t *testing.T) {
202202
},
203203
expectedServerConfig: map[string]int{
204204
"listen 8443;": 1,
205+
"listen unix:/var/run/nginx/cafe.example.com-8443.sock;": 1,
205206
},
206207
},
207208
{
208-
msg: "http, ssl servers, and tls servers with IPv6 IP family",
209+
msg: "tls servers with IPv6 IP family",
209210
config: dataplane.Configuration{
210211
BaseHTTPConfig: dataplane.BaseHTTPConfig{
211212
IPFamily: dataplane.IPv6,
@@ -215,10 +216,11 @@ func TestExecuteStreamServersForIPFamily(t *testing.T) {
215216
},
216217
expectedServerConfig: map[string]int{
217218
"listen [::]:8443;": 1,
219+
"listen unix:/var/run/nginx/cafe.example.com-8443.sock;": 1,
218220
},
219221
},
220222
{
221-
msg: "http and ssl servers with Dual IP family",
223+
msg: "tls servers with dual IP family",
222224
config: dataplane.Configuration{
223225
BaseHTTPConfig: dataplane.BaseHTTPConfig{
224226
IPFamily: dataplane.Dual,
@@ -229,6 +231,7 @@ func TestExecuteStreamServersForIPFamily(t *testing.T) {
229231
expectedServerConfig: map[string]int{
230232
"listen 8443;": 1,
231233
"listen [::]:8443;": 1,
234+
"listen unix:/var/run/nginx/cafe.example.com-8443.sock;": 1,
232235
},
233236
},
234237
}
@@ -240,6 +243,7 @@ func TestExecuteStreamServersForIPFamily(t *testing.T) {
240243
g.Expect(results).To(HaveLen(1))
241244
serverConf := string(results[0].data)
242245

246+
print(serverConf)
243247
for expSubStr, expCount := range test.expectedServerConfig {
244248
g.Expect(strings.Count(serverConf, expSubStr)).To(Equal(expCount))
245249
}

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,7 @@ func TestBuildStreamUpstreams(t *testing.T) {
35093509
secureApp2Key := getL4RouteKey("secure-app2")
35103510
secureApp3Key := getL4RouteKey("secure-app3")
35113511
secureApp4Key := getL4RouteKey("secure-app4")
3512+
secureApp5Key := getL4RouteKey("secure-app5")
35123513
testGraph := graph.Graph{
35133514
Gateway: &graph.Gateway{
35143515
Listeners: []*graph.Listener{
@@ -3567,14 +3568,41 @@ func TestBuildStreamUpstreams(t *testing.T) {
35673568
},
35683569
},
35693570
},
3571+
secureApp5Key: {
3572+
Valid: true,
3573+
Spec: graph.L4RouteSpec{
3574+
Hostnames: []v1.Hostname{"app2.example.com"},
3575+
BackendRef: graph.BackendRef{
3576+
Valid: true,
3577+
SvcNsName: secureApp5Key.NamespacedName,
3578+
ServicePort: apiv1.ServicePort{
3579+
Name: "https",
3580+
Protocol: "TCP",
3581+
Port: 8443,
3582+
TargetPort: intstr.IntOrString{
3583+
Type: intstr.Int,
3584+
IntVal: 8443,
3585+
},
3586+
},
3587+
},
3588+
},
3589+
},
35703590
},
35713591
},
35723592
},
35733593
},
35743594
}
35753595

35763596
fakeResolver := resolverfakes.FakeServiceResolver{}
3577-
fakeResolver.ResolveReturns(nil, errors.New("error"))
3597+
fakeResolver.ResolveReturnsOnCall(0, nil, errors.New("error"))
3598+
fakeEndpoints := []resolver.Endpoint{
3599+
{Address: "1.1.1.1", Port: 80},
3600+
}
3601+
fakeResolver.ResolveReturnsOnCall(
3602+
1,
3603+
fakeEndpoints,
3604+
nil,
3605+
)
35783606

35793607
streamUpstreams := buildStreamUpstreams(context.Background(), testGraph.Gateway.Listeners, &fakeResolver, Dual)
35803608

@@ -3583,8 +3611,12 @@ func TestBuildStreamUpstreams(t *testing.T) {
35833611
Name: "default_secure-app_8443",
35843612
ErrorMsg: "error",
35853613
},
3614+
{
3615+
Name: "default_secure-app5_8443",
3616+
Endpoints: fakeEndpoints,
3617+
},
35863618
}
35873619
g := NewWithT(t)
35883620

3589-
g.Expect(streamUpstreams).To(Equal(expectedStreamUpstreams))
3621+
g.Expect(streamUpstreams).To(ConsistOf(expectedStreamUpstreams))
35903622
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ func getAndValidateListenerSupportedKinds(listener v1.Listener) (
285285
supportedKinds = make([]v1.RouteGroupKind, 0, len(listener.AllowedRoutes.Kinds))
286286
for _, kind := range listener.AllowedRoutes.Kinds {
287287
if !validProtocolRouteKind(kind) {
288-
msg := fmt.Sprintf("Unsupported route kind for protocol %s \"%s/%s\"", listener.Protocol, *kind.Group, kind.Kind)
288+
group := v1.GroupName
289+
if kind.Group != nil {
290+
group = string(*kind.Group)
291+
}
292+
msg := fmt.Sprintf("Unsupported route kind for protocol %s \"%s/%s\"", listener.Protocol, group, kind.Kind)
289293
conds = append(conds, staticConds.NewListenerInvalidRouteKinds(msg)...)
290294
continue
291295
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ func TestListenerNamesHaveOverlap(t *testing.T) {
535535
)).To(BeTrue())
536536

537537
g.Expect(haveOverlap(
538-
(*v1.Hostname)(helpers.GetPointer("cafe.example.com")),
539538
nil,
539+
(*v1.Hostname)(helpers.GetPointer("cafe.example.com")),
540540
)).To(BeTrue())
541541

542542
g.Expect(haveOverlap(

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

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,22 @@ func TestBuildGateway(t *testing.T) {
413413
Source: getLastCreatedGetaway(),
414414
Listeners: []*Listener{
415415
{
416-
Name: "foo-443-https-1",
417-
Source: foo443HTTPSListener1,
418-
Valid: true,
419-
Attachable: true,
420-
Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{},
416+
Name: "foo-443-https-1",
417+
Source: foo443HTTPSListener1,
418+
Valid: true,
419+
Attachable: true,
420+
Routes: map[RouteKey]*L7Route{},
421+
L4Routes: map[L4RouteKey]*L4Route{},
421422
ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)),
422423
SupportedKinds: supportedKindsForListeners,
423424
},
424425
{
425-
Name: "foo-8443-https",
426-
Source: foo8443HTTPSListener,
427-
Valid: true,
428-
Attachable: true,
429-
Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{},
426+
Name: "foo-8443-https",
427+
Source: foo8443HTTPSListener,
428+
Valid: true,
429+
Attachable: true,
430+
Routes: map[RouteKey]*L7Route{},
431+
L4Routes: map[L4RouteKey]*L4Route{},
430432
ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)),
431433
SupportedKinds: supportedKindsForListeners,
432434
},
@@ -984,6 +986,40 @@ func TestBuildGateway(t *testing.T) {
984986
},
985987
name: "https listener and tls listener with overlapping hostnames",
986988
},
989+
{
990+
gateway: createGateway(
991+
gatewayCfg{listeners: []v1.Listener{foo443TLSListener, bar443HTTPSListener}},
992+
),
993+
gatewayClass: validGC,
994+
expected: &Gateway{
995+
Source: getLastCreatedGetaway(),
996+
Valid: true,
997+
Listeners: []*Listener{
998+
{
999+
Name: "foo-443-tls",
1000+
Source: foo443TLSListener,
1001+
Valid: true,
1002+
Attachable: true,
1003+
Routes: map[RouteKey]*L7Route{},
1004+
L4Routes: map[L4RouteKey]*L4Route{},
1005+
SupportedKinds: []v1.RouteGroupKind{
1006+
{Kind: kinds.TLSRoute, Group: helpers.GetPointer[v1.Group](v1.GroupName)},
1007+
},
1008+
},
1009+
{
1010+
Name: "bar-443-https",
1011+
Source: bar443HTTPSListener,
1012+
Valid: true,
1013+
Attachable: true,
1014+
ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)),
1015+
Routes: map[RouteKey]*L7Route{},
1016+
L4Routes: map[L4RouteKey]*L4Route{},
1017+
SupportedKinds: supportedKindsForListeners,
1018+
},
1019+
},
1020+
},
1021+
name: "https listener and tls listener with non overlapping hostnames",
1022+
},
9871023
}
9881024

9891025
secretResolver := newSecretResolver(

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

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,6 @@ func TestBindL4RouteToListeners(t *testing.T) {
19481948
tests := []struct {
19491949
route *L4Route
19501950
gateway *Gateway
1951-
portHostnamesMap map[string]struct{}
19521951
expectedGatewayListeners []*Listener
19531952
name string
19541953
expectedSectionNameRefs []ParentRef
@@ -2402,15 +2401,11 @@ func TestBindL4RouteToListeners(t *testing.T) {
24022401
t.Run(test.name, func(t *testing.T) {
24032402
g := NewWithT(t)
24042403

2405-
if test.portHostnamesMap == nil {
2406-
test.portHostnamesMap = map[string]struct{}{}
2407-
}
2408-
24092404
bindL4RouteToListeners(
24102405
test.route,
24112406
test.gateway,
24122407
namespaces,
2413-
test.portHostnamesMap,
2408+
map[string]struct{}{},
24142409
)
24152410

24162411
g.Expect(test.route.ParentRefs).To(Equal(test.expectedSectionNameRefs))
@@ -2423,50 +2418,60 @@ func TestBindL4RouteToListeners(t *testing.T) {
24232418
func TestBuildL4RoutesForGateways(t *testing.T) {
24242419
g := NewWithT(t)
24252420

2426-
g.Expect(buildL4RoutesForGateways(
2427-
map[types.NamespacedName]*v1alpha2.TLSRoute{
2428-
{Namespace: testNs, Name: "hi"}: {
2429-
Spec: v1alpha2.TLSRouteSpec{
2430-
Hostnames: []v1alpha2.Hostname{"app.example.com"},
2431-
},
2421+
nsName := types.NamespacedName{Namespace: testNs, Name: "hi"}
2422+
2423+
tlsRoutes := map[types.NamespacedName]*v1alpha2.TLSRoute{
2424+
nsName: {
2425+
Spec: v1alpha2.TLSRouteSpec{
2426+
Hostnames: []v1alpha2.Hostname{"app.example.com"},
24322427
},
24332428
},
2434-
nil,
2435-
map[types.NamespacedName]*v1.Service{
2436-
{Namespace: testNs, Name: "hi"}: {
2437-
Spec: v1.ServiceSpec{
2438-
Ports: []v1.ServicePort{},
2439-
},
2429+
}
2430+
2431+
services := map[types.NamespacedName]*v1.Service{
2432+
nsName: {
2433+
Spec: v1.ServiceSpec{
2434+
Ports: []v1.ServicePort{},
24402435
},
24412436
},
2437+
}
2438+
2439+
g.Expect(buildL4RoutesForGateways(
2440+
tlsRoutes,
2441+
nil,
2442+
services,
24422443
nil,
24432444
)).To(BeNil())
24442445
}
24452446

24462447
func TestTryToAttachL4RouteToListeners(t *testing.T) {
24472448
g := NewWithT(t)
24482449

2449-
cond, attachable := tryToAttachL4RouteToListeners(
2450-
nil,
2451-
nil,
2452-
&L4Route{
2453-
Spec: L4RouteSpec{
2454-
Hostnames: []v1alpha2.Hostname{"app.example.com"},
2455-
},
2456-
Valid: true,
2457-
Attachable: true,
2450+
route := &L4Route{
2451+
Spec: L4RouteSpec{
2452+
Hostnames: []v1alpha2.Hostname{"app.example.com"},
24582453
},
2459-
&Gateway{
2460-
Valid: true,
2461-
Listeners: []*Listener{
2462-
{
2463-
Name: "listener1",
2464-
},
2465-
{
2466-
Name: "listener2",
2467-
},
2454+
Valid: true,
2455+
Attachable: true,
2456+
}
2457+
2458+
gw := &Gateway{
2459+
Valid: true,
2460+
Listeners: []*Listener{
2461+
{
2462+
Name: "listener1",
2463+
},
2464+
{
2465+
Name: "listener2",
24682466
},
24692467
},
2468+
}
2469+
2470+
cond, attachable := tryToAttachL4RouteToListeners(
2471+
nil,
2472+
nil,
2473+
route,
2474+
gw,
24702475
nil,
24712476
map[string]struct{}{},
24722477
)

0 commit comments

Comments
 (0)