Skip to content

Commit c32436e

Browse files
author
Rajat Chopra
committed
ab testing
1 parent 93af6aa commit c32436e

File tree

26 files changed

+499
-257
lines changed

26 files changed

+499
-257
lines changed

api/swagger-spec/oapi-v1.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22799,9 +22799,15 @@
2279922799
"description": "Path that the router watches for, to route traffic for to the service. Optional"
2280022800
},
2280122801
"to": {
22802-
"$ref": "v1.ObjectReference",
22802+
"$ref": "v1.RouteTargetReference",
2280322803
"description": "To is an object the route points to. Only the Service kind is allowed, and it will be defaulted to Service."
2280422804
},
22805+
"additionalTos": {
22806+
"type": "array",
22807+
"items": {
22808+
"$ref": "v1.RouteTargetReference"
22809+
}
22810+
},
2280522811
"port": {
2280622812
"$ref": "v1.RoutePort",
2280722813
"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."
@@ -22812,6 +22818,26 @@
2281222818
}
2281322819
}
2281422820
},
22821+
"v1.RouteTargetReference": {
22822+
"id": "v1.RouteTargetReference",
22823+
"required": [
22824+
"kind",
22825+
"name",
22826+
"weight"
22827+
],
22828+
"properties": {
22829+
"kind": {
22830+
"type": "string"
22831+
},
22832+
"name": {
22833+
"type": "string"
22834+
},
22835+
"weight": {
22836+
"type": "integer",
22837+
"format": "int32"
22838+
}
22839+
}
22840+
},
2281522841
"v1.RoutePort": {
2281622842
"id": "v1.RoutePort",
2281722843
"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
@@ -206,18 +206,25 @@ backend openshift_default
206206
where to send the traffic but should run the be in tcp mode
207207
3. if the config is terminated at the
208208
*/}}
209-
{{ range $id, $serviceUnit := .State }}
210-
{{ range $cfgIdx, $cfg := $serviceUnit.ServiceAliasConfigs }}
211-
{{ if or (eq $cfg.TLSTermination "") (eq $cfg.TLSTermination "edge") }}
212-
{{ if (eq $cfg.TLSTermination "") }}
209+
{{ range $cfgIdx, $cfg := .State }}
210+
{{ if or (eq $cfg.TLSTermination "") (eq $cfg.TLSTermination "edge") }}
211+
{{ if (eq $cfg.TLSTermination "") }}
212+
# Plain http backend
213213
backend be_http_{{$cfgIdx}}
214-
{{ else }}
214+
{{ else }}
215+
# Plain http backend but request is TLS, terminated at edge
215216
backend be_edge_http_{{$cfgIdx}}
216-
{{ end }}
217+
{{ end }}
217218
mode http
218219
option redispatch
219220
option forwardfor
221+
{{ with $balanceAlgo := index $cfg.Annotations "router.openshift.io/haproxy.balance" }}
222+
{{ with $matchValue := (matchValues $balanceAlgo "roundrobin" "leastconn" ) }}
223+
balance {{ $balanceAlgo }}
224+
{{ end }}
225+
{{ else }}
220226
balance leastconn
227+
{{ end }}
221228
timeout check 5000ms
222229
http-request set-header X-Forwarded-Host %[req.hdr(host)]
223230
http-request set-header X-Forwarded-Port %[dst_port]
@@ -226,41 +233,53 @@ backend be_edge_http_{{$cfgIdx}}
226233
{{ if (eq $cfg.TLSTermination "") }}
227234
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly
228235
{{ else }}
229-
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
236+
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
230237
{{ end }}
231238
http-request set-header Forwarded for=%[src];host=%[req.hdr(host)];proto=%[req.hdr(X-Forwarded-Proto)]
232-
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
233-
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.IdHash}}
234-
{{ end }}
235-
{{ end }}
236-
237-
{{ if eq $cfg.TLSTermination "passthrough" }}
239+
{{ range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}
240+
{{ with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
241+
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
242+
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.IdHash}} weight {{ $weight }}
243+
{{ end }}
244+
{{ end }}
245+
{{ end }}{{/* end iterate over services */}}
246+
{{ end }}{{/* end if tls==edge/none */}}
247+
248+
# Secure backend, pass through
249+
{{ if eq $cfg.TLSTermination "passthrough" }}
238250
backend be_tcp_{{$cfgIdx}}
239251
{{ if ne (env "ROUTER_SYSLOG_ADDRESS" "") ""}}
240252
option tcplog
241253
{{ end }}
242254
balance {{ env "ROUTER_TCP_BALANCE_SCHEME" "source" }}
243255
hash-type consistent
244256
timeout check 5000ms
245-
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
257+
{{ range $svcUnitIdx, $serviceUnitName := $cfg.ServiceUnitNames }}
258+
{{ with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
259+
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
246260
server {{$endpoint.ID}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms
247-
{{ end }}
248-
{{ end }}
261+
{{ end }}
262+
{{ end }}
263+
{{ end }}{{/* end iterate over services*/}}
264+
{{ end }}{{/*end tls==passthrough*/}}
249265

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

266285
{{/*--------------------------------- END OF HAPROXY CONFIG, BELOW ARE MAPPING FILES ------------------------*/}}
@@ -269,27 +288,23 @@ backend be_secure_{{$cfgIdx}}
269288
by attaching a prefix (be_http_) by use_backend statements if acls are matched.
270289
*/}}
271290
{{ define "/var/lib/haproxy/conf/os_http_be.map" }}
272-
{{ range $id, $serviceUnit := .State }}
273-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
291+
{{ range $idx, $cfg := .State }}
274292
{{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "")}}
275293
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
276294
{{ end }}
277295
{{ end }}
278-
{{ end }}
279296
{{ end }}{{/* end http host map template */}}
280297

281298
{{/*
282299
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
283300
a tls only route on the unsecure port
284301
*/}}
285302
{{ define "/var/lib/haproxy/conf/os_edge_http_be.map" }}
286-
{{ range $id, $serviceUnit := .State }}
287-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
303+
{{ range $idx, $cfg := .State }}
288304
{{ if and (ne $cfg.Host "") (eq $cfg.TLSTermination "edge")}}
289305
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
290306
{{ end }}
291307
{{ end }}
292-
{{ end }}
293308
{{ end }}{{/* end edge http host map template */}}
294309

295310
{{/*
@@ -298,13 +313,11 @@ backend be_secure_{{$cfgIdx}}
298313
(http) if acls match for routes with insecure option set to expose.
299314
*/}}
300315
{{ define "/var/lib/haproxy/conf/os_edge_http_expose.map" }}
301-
{{ range $id, $serviceUnit := .State }}
302-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
316+
{{ range $idx, $cfg := .State }}
303317
{{ if and (ne $cfg.Host "") (and (eq $cfg.TLSTermination "edge") (eq $cfg.InsecureEdgeTerminationPolicy "Allow"))}}
304318
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
305319
{{ end }}
306320
{{ end }}
307-
{{ end }}
308321
{{ end }}{{/* end edge insecure expose http host map template */}}
309322

310323
{{/*
@@ -313,13 +326,11 @@ backend be_secure_{{$cfgIdx}}
313326
if acls match for routes that have the insecure option set to redirect.
314327
*/}}
315328
{{ define "/var/lib/haproxy/conf/os_edge_http_redirect.map" }}
316-
{{ range $id, $serviceUnit := .State }}
317-
{{ range $idx, $cfg := $serviceUnit.ServiceAliasConfigs }}
329+
{{ range $idx, $cfg := .State }}
318330
{{ if and (ne $cfg.Host "") (and (eq $cfg.TLSTermination "edge") (eq $cfg.InsecureEdgeTerminationPolicy "Redirect"))}}
319331
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
320332
{{ end }}
321333
{{ end }}
322-
{{ end }}
323334
{{ end }}{{/* end edge insecure redirect http host map template */}}
324335

325336

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

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

354361

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

pkg/cmd/cli/cmd/create_route.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func unsecuredRoute(kc *kclient.Client, namespace, routeName, serviceName, portS
373373
Name: routeName,
374374
},
375375
Spec: api.RouteSpec{
376-
To: kapi.ObjectReference{
376+
To: api.RouteTargetReference{
377377
Name: serviceName,
378378
},
379379
Port: resolveRoutePort(portString),
@@ -392,7 +392,7 @@ func unsecuredRoute(kc *kclient.Client, namespace, routeName, serviceName, portS
392392
Labels: svc.Labels,
393393
},
394394
Spec: api.RouteSpec{
395-
To: kapi.ObjectReference{
395+
To: api.RouteTargetReference{
396396
Name: serviceName,
397397
},
398398
},

pkg/generate/app/pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func AddRoutes(objects Objects) Objects {
382382
Labels: t.Labels,
383383
},
384384
Spec: route.RouteSpec{
385-
To: kapi.ObjectReference{
385+
To: route.RouteTargetReference{
386386
Name: t.Name,
387387
},
388388
},

pkg/route/allocation/simple/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewSimpleAllocationPlugin(suffix string) (*SimpleAllocationPlugin, error) {
3838
// the "global" router shard.
3939
// TODO: replace with per router allocation
4040
func (p *SimpleAllocationPlugin) Allocate(route *routeapi.Route) (*routeapi.RouterShard, error) {
41-
glog.V(4).Infof("Allocating global shard *.%s to Route: %s", p.DNSSuffix, route.Spec.To.Name)
41+
glog.V(4).Infof("Allocating global shard *.%s to Route: %s", p.DNSSuffix, route.Name)
4242

4343
return &routeapi.RouterShard{ShardName: "global", DNSSuffix: p.DNSSuffix}, nil
4444
}

pkg/route/api/deep_copy_generated.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func init() {
2020
DeepCopy_api_RoutePort,
2121
DeepCopy_api_RouteSpec,
2222
DeepCopy_api_RouteStatus,
23+
DeepCopy_api_RouteTargetReference,
2324
DeepCopy_api_RouterShard,
2425
DeepCopy_api_TLSConfig,
2526
); err != nil {
@@ -109,9 +110,20 @@ func DeepCopy_api_RoutePort(in RoutePort, out *RoutePort, c *conversion.Cloner)
109110
func DeepCopy_api_RouteSpec(in RouteSpec, out *RouteSpec, c *conversion.Cloner) error {
110111
out.Host = in.Host
111112
out.Path = in.Path
112-
if err := api.DeepCopy_api_ObjectReference(in.To, &out.To, c); err != nil {
113+
if err := DeepCopy_api_RouteTargetReference(in.To, &out.To, c); err != nil {
113114
return err
114115
}
116+
if in.AdditionalTos != nil {
117+
in, out := in.AdditionalTos, &out.AdditionalTos
118+
*out = make([]RouteTargetReference, len(in))
119+
for i := range in {
120+
if err := DeepCopy_api_RouteTargetReference(in[i], &(*out)[i], c); err != nil {
121+
return err
122+
}
123+
}
124+
} else {
125+
out.AdditionalTos = nil
126+
}
115127
if in.Port != nil {
116128
in, out := in.Port, &out.Port
117129
*out = new(RoutePort)
@@ -148,6 +160,19 @@ func DeepCopy_api_RouteStatus(in RouteStatus, out *RouteStatus, c *conversion.Cl
148160
return nil
149161
}
150162

163+
func DeepCopy_api_RouteTargetReference(in RouteTargetReference, out *RouteTargetReference, c *conversion.Cloner) error {
164+
out.Kind = in.Kind
165+
out.Name = in.Name
166+
if in.Weight != nil {
167+
in, out := in.Weight, &out.Weight
168+
*out = new(int32)
169+
**out = *in
170+
} else {
171+
out.Weight = nil
172+
}
173+
return nil
174+
}
175+
151176
func DeepCopy_api_RouterShard(in RouterShard, out *RouterShard, c *conversion.Cloner) error {
152177
out.ShardName = in.ShardName
153178
out.DNSSuffix = in.DNSSuffix

pkg/route/api/types.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ type RouteSpec struct {
2525
// Path that the router watches for, to route traffic for to the service. Optional
2626
Path string
2727

28-
// An object the route points to. Only the Service kind is allowed, and it will
28+
// Objects that the route points to. Only the Service kind is allowed, and it will
2929
// be defaulted to Service.
30-
To kapi.ObjectReference
30+
To RouteTargetReference
31+
32+
// Additional objects that the route may want to point to. Use the 'weight' field to
33+
// determine which ones of the several get more emphasis
34+
AdditionalTos []RouteTargetReference
3135

3236
// If specified, the port to be used by the router. Most routers will use all
3337
// endpoints exposed by the service by default - set this value to instruct routers
@@ -38,6 +42,14 @@ type RouteSpec struct {
3842
TLS *TLSConfig
3943
}
4044

45+
// RouteTargetReference specifies the target that resolve into endpoints. Only the 'Service'
46+
// kind is allowed. Use 'weight' field to emphasize one over others.
47+
type RouteTargetReference struct {
48+
Kind string
49+
Name string
50+
Weight *int32
51+
}
52+
4153
// RoutePort defines a port mapping from a router to an endpoint in the service endpoints.
4254
type RoutePort struct {
4355
// The target port on pods selected by the service this route points to.

pkg/route/api/v1/conversion.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ import (
1010
func addConversionFuncs(scheme *runtime.Scheme) {
1111
err := scheme.AddDefaultingFuncs(
1212
func(obj *RouteSpec) {
13-
if len(obj.To.Kind) == 0 {
14-
obj.To.Kind = "Service"
13+
if obj.AdditionalTos == nil {
14+
obj.AdditionalTos = make([]RouteTargetReference, 0)
15+
}
16+
},
17+
func(obj *RouteTargetReference) {
18+
if len(obj.Kind) == 0 {
19+
obj.Kind = "Service"
20+
}
21+
if obj.Weight == nil {
22+
*obj.Weight = 100
1523
}
1624
},
1725
func(obj *TLSConfig) {

0 commit comments

Comments
 (0)