Skip to content

Commit 89bc90b

Browse files
author
Rajat Chopra
committed
ab testing
1 parent 58544a5 commit 89bc90b

40 files changed

+897
-3643
lines changed

api/swagger-spec/oapi-v1.json

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24052,9 +24052,16 @@
2405224052
"description": "Path that the router watches for, to route traffic for to the service. Optional"
2405324053
},
2405424054
"to": {
24055-
"$ref": "v1.ObjectReference",
24055+
"$ref": "v1.RouteTargetReference",
2405624056
"description": "To is an object the route points to. Only the Service kind is allowed, and it will be defaulted to Service."
2405724057
},
24058+
"alternateBackends": {
24059+
"type": "array",
24060+
"items": {
24061+
"$ref": "v1.RouteTargetReference"
24062+
},
24063+
"description": "AlternateBackends is an extension of the 'to' field. If more than one service needs to be pointed to, then use this field. Use the weight field in RouteTargetReference object to specify relative preference"
24064+
},
2405824065
"port": {
2405924066
"$ref": "v1.RoutePort",
2406024067
"description": "If specified, the port to be used by the router. Most routers will use all endpoints exposed by the service by default - set this value to instruct routers which port to use."
@@ -24065,6 +24072,30 @@
2406524072
}
2406624073
}
2406724074
},
24075+
"v1.RouteTargetReference": {
24076+
"id": "v1.RouteTargetReference",
24077+
"description": "RouteTargetReference specifies the target that resolve into endpoints. Only the 'Service' kind is allowed. Use 'weight' field to emphasize one over others.",
24078+
"required": [
24079+
"kind",
24080+
"name",
24081+
"weight"
24082+
],
24083+
"properties": {
24084+
"kind": {
24085+
"type": "string",
24086+
"description": "The kind of target that the route is referring to. Currently, only 'Service' is allowed"
24087+
},
24088+
"name": {
24089+
"type": "string",
24090+
"description": "Name of the service/target that is being referred to. e.g. name of the service"
24091+
},
24092+
"weight": {
24093+
"type": "integer",
24094+
"format": "int32",
24095+
"description": "Weight as an integer between 1 and 256 that specifies the target's relative weight against other target reference objects"
24096+
}
24097+
}
24098+
},
2406824099
"v1.RoutePort": {
2406924100
"id": "v1.RoutePort",
2407024101
"description": "RoutePort defines a port mapping from a router to an endpoint in the service endpoints.",

images/router/haproxy/conf/haproxy-config.template

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,25 @@ backend openshift_default
207207
where to send the traffic but should run the be in tcp mode
208208
3. if the config is terminated at the
209209
*/}}
210-
{{ range $id, $serviceUnit := .State }}
211-
{{ range $cfgIdx, $cfg := $serviceUnit.ServiceAliasConfigs }}
212-
{{ if or (eq $cfg.TLSTermination "") (eq $cfg.TLSTermination "edge") }}
213-
{{ if (eq $cfg.TLSTermination "") }}
210+
{{ range $cfgIdx, $cfg := .State }}
211+
{{ if or (eq $cfg.TLSTermination "") (eq $cfg.TLSTermination "edge") }}
212+
{{ if (eq $cfg.TLSTermination "") }}
213+
# Plain http backend
214214
backend be_http_{{$cfgIdx}}
215-
{{ else }}
215+
{{ else }}
216+
# Plain http backend but request is TLS, terminated at edge
216217
backend be_edge_http_{{$cfgIdx}}
217-
{{ end }}
218+
{{ end }}
218219
mode http
219220
option redispatch
220221
option forwardfor
222+
{{ with $balanceAlgo := index $cfg.Annotations "router.openshift.io/haproxy.balance" }}
223+
{{ with $matchValue := (matchValues $balanceAlgo "roundrobin" "leastconn" ) }}
224+
balance {{ $balanceAlgo }}
225+
{{ end }}
226+
{{ else }}
221227
balance leastconn
228+
{{ end }}
222229
timeout check 5000ms
223230
http-request set-header X-Forwarded-Host %[req.hdr(host)]
224231
http-request set-header X-Forwarded-Port %[dst_port]
@@ -227,41 +234,53 @@ backend be_edge_http_{{$cfgIdx}}
227234
{{ if (eq $cfg.TLSTermination "") }}
228235
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly
229236
{{ else }}
230-
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
237+
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
231238
{{ end }}
232239
http-request set-header Forwarded for=%[src];host=%[req.hdr(host)];proto=%[req.hdr(X-Forwarded-Proto)]
233-
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
234-
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.IdHash}}
235-
{{ end }}
236-
{{ end }}
237-
238-
{{ if eq $cfg.TLSTermination "passthrough" }}
240+
{{ range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}
241+
{{ with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
242+
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
243+
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.IdHash}} weight {{ $weight }}
244+
{{ end }}
245+
{{ end }}
246+
{{ end }}{{/* end iterate over services */}}
247+
{{ end }}{{/* end if tls==edge/none */}}
248+
249+
# Secure backend, pass through
250+
{{ if eq $cfg.TLSTermination "passthrough" }}
239251
backend be_tcp_{{$cfgIdx}}
240252
{{ if ne (env "ROUTER_SYSLOG_ADDRESS" "") ""}}
241253
option tcplog
242254
{{ end }}
243255
balance {{ env "ROUTER_TCP_BALANCE_SCHEME" "source" }}
244256
hash-type consistent
245257
timeout check 5000ms
246-
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
258+
{{ range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}
259+
{{ with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
260+
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
247261
server {{$endpoint.ID}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms
248-
{{ end }}
249-
{{ end }}
262+
{{ end }}
263+
{{ end }}
264+
{{ end }}{{/* end iterate over services*/}}
265+
{{ end }}{{/*end tls==passthrough*/}}
250266

251-
{{ if eq $cfg.TLSTermination "reencrypt" }}
267+
# Secure backend which requires re-encryption
268+
{{ if eq $cfg.TLSTermination "reencrypt" }}
252269
backend be_secure_{{$cfgIdx}}
253270
mode http
254271
option redispatch
255272
balance leastconn
256273
timeout check 5000ms
257274
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
258-
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
275+
{{ range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}
276+
{{ with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
277+
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
259278
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} ssl check inter 5000ms verify required ca-file {{ $workingDir }}/cacerts/{{$cfgIdx}}.pem cookie {{$endpoint.IdHash}}
260-
{{ end }}
261-
{{ end }}
262-
{{ end }}{{/* $serviceUnit.ServiceAliasConfigs*/}}
263-
{{ end }}{{/* $serviceUnit */}}
264-
279+
{{ end }}
280+
{{ end }}
281+
{{ end }}
282+
{{ end }}{{/* end tls==reencrypt */}}
283+
{{ end }}{{/* end loop over routes */}}
265284
{{ end }}{{/* end haproxy config template */}}
266285

267286
{{/*--------------------------------- END OF HAPROXY CONFIG, BELOW ARE MAPPING FILES ------------------------*/}}
@@ -270,27 +289,23 @@ backend be_secure_{{$cfgIdx}}
270289
by attaching a prefix (be_http_) by use_backend statements if acls are matched.
271290
*/}}
272291
{{ define "/var/lib/haproxy/conf/os_http_be.map" }}
273-
{{ range $id, $serviceUnit := .State }}
274-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
292+
{{ range $idx, $cfg := .State }}
275293
{{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "")}}
276294
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
277295
{{ end }}
278296
{{ end }}
279-
{{ end }}
280297
{{ end }}{{/* end http host map template */}}
281298

282299
{{/*
283300
os_edge_http_be.map: same as os_http_be.map but allows us to separate tls from non-tls routes to ensure we don't expose
284301
a tls only route on the unsecure port
285302
*/}}
286303
{{ define "/var/lib/haproxy/conf/os_edge_http_be.map" }}
287-
{{ range $id, $serviceUnit := .State }}
288-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
304+
{{ range $idx, $cfg := .State }}
289305
{{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "edge")}}
290306
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
291307
{{ end }}
292308
{{ end }}
293-
{{ end }}
294309
{{ end }}{{/* end edge http host map template */}}
295310

296311
{{/*
@@ -299,13 +314,11 @@ backend be_secure_{{$cfgIdx}}
299314
(http) if acls match for routes with insecure option set to expose.
300315
*/}}
301316
{{ define "/var/lib/haproxy/conf/os_edge_http_expose.map" }}
302-
{{ range $id, $serviceUnit := .State }}
303-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
317+
{{ range $idx, $cfg := .State }}
304318
{{ if and (ne $cfg.Host "") (and (eq $cfg.TLSTermination "edge") (eq $cfg.InsecureEdgeTerminationPolicy "Allow"))}}
305319
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
306320
{{ end }}
307321
{{ end }}
308-
{{ end }}
309322
{{ end }}{{/* end edge insecure expose http host map template */}}
310323

311324
{{/*
@@ -314,13 +327,11 @@ backend be_secure_{{$cfgIdx}}
314327
if acls match for routes that have the insecure option set to redirect.
315328
*/}}
316329
{{ define "/var/lib/haproxy/conf/os_edge_http_redirect.map" }}
317-
{{ range $id, $serviceUnit := .State }}
318-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
330+
{{ range $idx, $cfg := .State }}
319331
{{ if and (ne $cfg.Host "") (and (eq $cfg.TLSTermination "edge") (eq $cfg.InsecureEdgeTerminationPolicy "Redirect"))}}
320332
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
321333
{{ end }}
322334
{{ end }}
323-
{{ end }}
324335
{{ end }}{{/* end edge insecure redirect http host map template */}}
325336

326337

@@ -329,27 +340,23 @@ backend be_secure_{{$cfgIdx}}
329340
by attaching a prefix (be_tcp_ or be_secure_) by use_backend statements if acls are matched.
330341
*/}}
331342
{{ define "/var/lib/haproxy/conf/os_tcp_be.map" }}
332-
{{ range $id, $serviceUnit := .State }}
333-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
343+
{{ range $idx, $cfg := .State }}
334344
{{ if and (eq $cfg.Path "") (and (ne $cfg.Host "") (or (eq $cfg.TLSTermination "passthrough") (eq $cfg.TLSTermination "reencrypt"))) }}
335345
{{$cfg.Host}} {{$idx}}
336346
{{ end }}
337347
{{ end }}
338-
{{ end }}
339348
{{ end }}{{/* end tcp host map template */}}
340349

341350
{{/*
342351
os_sni_passthrough.map: contains a mapping of routes that expect to have an sni header and should be passed
343352
through to the host_be. Driven by the termination type of the ServiceAliasConfigs
344353
*/}}
345354
{{ define "/var/lib/haproxy/conf/os_sni_passthrough.map" }}
346-
{{ range $id, $serviceUnit := .State }}
347-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
355+
{{ range $idx, $cfg := .State }}
348356
{{ if and (eq $cfg.Path "") (eq $cfg.TLSTermination "passthrough") }}
349357
{{$cfg.Host}} 1
350358
{{ end }}
351359
{{ end }}
352-
{{ end }}
353360
{{ end }}{{/* end sni passthrough map template */}}
354361

355362

@@ -358,11 +365,9 @@ backend be_secure_{{$cfgIdx}}
358365
that does specific checks that avoid mitm attacks: http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#5.2-ssl
359366
*/}}
360367
{{ define "/var/lib/haproxy/conf/os_reencrypt.map" }}
361-
{{ range $id, $serviceUnit := .State }}
362-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
368+
{{ range $idx, $cfg := .State }}
363369
{{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "reencrypt") }}
364370
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
365371
{{ end }}
366372
{{ end }}
367-
{{ end }}
368373
{{ end }}{{/* end reencrypt passthrough map template */}}

pkg/api/serialization_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,11 @@ func fuzzInternalObject(t *testing.T, forVersion unversioned.GroupVersion, item
243243
j.To.Name = strings.Replace(j.To.Name, ":", "-", -1)
244244
}
245245
},
246-
func(j *route.RouteSpec, c fuzz.Continue) {
246+
func(j *route.RouteTargetReference, c fuzz.Continue) {
247247
c.FuzzNoCustom(j)
248-
j.To = kapi.ObjectReference{
249-
Kind: "Service",
250-
Name: j.To.Name,
251-
}
248+
j.Kind = "Service"
249+
j.Weight = new(int32)
250+
*j.Weight = 100
252251
},
253252
func(j *route.TLSConfig, c fuzz.Continue) {
254253
c.FuzzNoCustom(j)

0 commit comments

Comments
 (0)