Skip to content

Commit bca2e0e

Browse files
committed
Refactor and dedupe routes
1 parent 6b6c667 commit bca2e0e

35 files changed

+1473
-2382
lines changed

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBj
3232
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
3333
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
3434
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
35+
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
3536
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
3637
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
3738
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=

internal/mode/static/handler.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -245,23 +245,18 @@ func (h *eventHandlerImpl) updateStatuses(ctx context.Context, logger logr.Logge
245245
if h.cfg.updateGatewayClassStatus {
246246
gcReqs = status.PrepareGatewayClassRequests(graph.GatewayClass, graph.IgnoredGatewayClasses, transitionTime)
247247
}
248-
hrReqs := status.PrepareHTTPRouteRequests(
249-
graph.HTTPRoutes,
248+
routeReqs := status.PrepareRouteRequests(
249+
graph.Routes,
250250
transitionTime,
251251
h.latestReloadResult,
252252
h.cfg.gatewayCtlrName,
253253
)
254-
grReqs := status.PrepareGRPCRouteRequests(
255-
graph.GRPCRoutes, transitionTime,
256-
h.latestReloadResult,
257-
h.cfg.gatewayCtlrName,
258-
)
254+
259255
polReqs := status.PrepareBackendTLSPolicyRequests(graph.BackendTLSPolicies, transitionTime, h.cfg.gatewayCtlrName)
260256

261-
reqs := make([]frameworkStatus.UpdateRequest, 0, len(gcReqs)+len(hrReqs)+len(grReqs)+len(polReqs))
257+
reqs := make([]frameworkStatus.UpdateRequest, 0, len(gcReqs)+len(routeReqs)+len(polReqs))
262258
reqs = append(reqs, gcReqs...)
263-
reqs = append(reqs, hrReqs...)
264-
reqs = append(reqs, grReqs...)
259+
reqs = append(reqs, routeReqs...)
265260
reqs = append(reqs, polReqs...)
266261

267262
h.cfg.statusUpdater.UpdateGroup(ctx, groupAllExceptGateways, reqs...)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Location struct {
2020
HTTPMatchVar string
2121
Rewrites []string
2222
ProxySetHeaders []Header
23-
IsGRPC bool
23+
GRPC bool
2424
}
2525

2626
// Header defines an HTTP header to be passed to the proxied server.

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func createSSLServer(virtualServer dataplane.VirtualServer) http.Server {
6666
}
6767
}
6868

69-
locs, http2 := createLocations(virtualServer.PathRules, virtualServer.Port)
69+
locs, grpc := createLocations(virtualServer.PathRules, virtualServer.Port)
7070

7171
return http.Server{
7272
ServerName: virtualServer.Hostname,
@@ -76,7 +76,7 @@ func createSSLServer(virtualServer dataplane.VirtualServer) http.Server {
7676
},
7777
Locations: locs,
7878
Port: virtualServer.Port,
79-
GRPC: http2,
79+
GRPC: grpc,
8080
}
8181
}
8282

@@ -88,13 +88,13 @@ func createServer(virtualServer dataplane.VirtualServer) http.Server {
8888
}
8989
}
9090

91-
locs, http2 := createLocations(virtualServer.PathRules, virtualServer.Port)
91+
locs, grpc := createLocations(virtualServer.PathRules, virtualServer.Port)
9292

9393
return http.Server{
9494
ServerName: virtualServer.Hostname,
9595
Locations: locs,
9696
Port: virtualServer.Port,
97-
GRPC: http2,
97+
GRPC: grpc,
9898
}
9999
}
100100

@@ -109,7 +109,7 @@ func createLocations(pathRules []dataplane.PathRule, listenerPort int32) ([]http
109109
maxLocs, pathsAndTypes := getMaxLocationCountAndPathMap(pathRules)
110110
locs := make([]http.Location, 0, maxLocs)
111111
var rootPathExists bool
112-
var http2 bool
112+
var grpc bool
113113

114114
for pathRuleIdx, rule := range pathRules {
115115
matches := make([]httpMatch, 0, len(rule.MatchRules))
@@ -119,7 +119,7 @@ func createLocations(pathRules []dataplane.PathRule, listenerPort int32) ([]http
119119
}
120120

121121
if rule.GRPC {
122-
http2 = true
122+
grpc = true
123123
}
124124

125125
extLocations := initializeExternalLocations(rule, pathsAndTypes)
@@ -149,7 +149,7 @@ func createLocations(pathRules []dataplane.PathRule, listenerPort int32) ([]http
149149
locs = append(locs, createDefaultRootLocation())
150150
}
151151

152-
return locs, http2
152+
return locs, grpc
153153
}
154154

155155
// pathAndTypeMap contains a map of paths and any path types defined for that path
@@ -274,7 +274,7 @@ func updateLocationsForFilters(
274274
GRPC,
275275
)
276276
buildLocations[i].ProxyPass = proxyPass
277-
buildLocations[i].IsGRPC = GRPC
277+
buildLocations[i].GRPC = GRPC
278278
}
279279

280280
return buildLocations

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ server {
4646
js_content httpmatches.redirect;
4747
{{- end }}
4848
49-
{{ $proxyOrGRPC := "proxy" }}{{ if $l.IsGRPC }}{{ $proxyOrGRPC = "grpc" }}{{ end }}
49+
{{ $proxyOrGRPC := "proxy" }}{{ if $l.GRPC }}{{ $proxyOrGRPC = "grpc" }}{{ end }}
5050
51-
{{- if $l.IsGRPC }}
51+
{{- if $l.GRPC }}
5252
include /etc/nginx/grpc-error-pages.conf;
5353
{{- end }}
5454

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ func TestCreateServers(t *testing.T) {
820820
{
821821
Path: "= /grpc/method",
822822
ProxyPass: "grpc://test_foo_80",
823-
IsGRPC: true,
823+
GRPC: true,
824824
ProxySetHeaders: []http.Header{},
825825
},
826826
{
@@ -830,7 +830,7 @@ func TestCreateServers(t *testing.T) {
830830
Name: "test-btp.example.com",
831831
TrustedCertificate: "/etc/nginx/secrets/test-btp.crt",
832832
},
833-
IsGRPC: true,
833+
GRPC: true,
834834
ProxySetHeaders: []http.Header{},
835835
},
836836
}

0 commit comments

Comments
 (0)