Skip to content

Commit 50f3b50

Browse files
committed
feat: Add configurable load balancing policy for Knative revisions
This commit implements configurable load balancing policy. - Add LoadBalancingPolicy field to RevisionSpec in v1 API - Support policies: random-choice-2, round-robin, least-connections, first-available - Add validation for LoadBalancingPolicy in revision validation - Update CRD definitions for Configuration, Revision, and Service resources - Add validateLoadBalancingPolicy() to validate policy strings - Add pickLBPolicy() to select appropriate LB policy based on configuration - Convert lbPolicy and containerConcurrency to atomic types for thread-safe updates - Implement dynamic policy updates via revisionUpdated() method - Default policy selection based on container concurrency: - CC=0: random-choice-2 - CC=1-3: first-available - CC>3: round-robin - Fix leastConnectionsPolicy to use weight field instead of removed InFlight() - Add nil-safety checks to randomLBPolicy - Maintain existing policy implementations with minor safety improvements - Add LoadBalancingPolicy to defaults configuration - Update generated deepcopy methods for new field - Add TestLoadBalancingPolicySelection for policy selection logic - Add TestThrottlerUsesRevisionLoadBalancingPolicy for revision-level policies - Add TestDynamicLoadBalancingPolicyUpdate for runtime policy changes - Fix type mismatches (int32 vs uint32) in weight comparisons - Remove unused imports and variables - Maintain backward compatibility with existing pod tracking tests - Update serving-api.md with LoadBalancingPolicy field documentation This change enables users to configure load balancing behavior per revision.
1 parent 86af837 commit 50f3b50

File tree

17 files changed

+700
-218
lines changed

17 files changed

+700
-218
lines changed

config/core/300-resources/configuration.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ spec:
438438
type: object
439439
properties:
440440
host:
441-
description: 'Optional: Host name to connect to, defaults to the pod IP.'
441+
description: "Optional: Host name to connect to, defaults to the pod IP."
442442
type: string
443443
port:
444444
description: |-
@@ -606,7 +606,7 @@ spec:
606606
type: object
607607
properties:
608608
host:
609-
description: 'Optional: Host name to connect to, defaults to the pod IP.'
609+
description: "Optional: Host name to connect to, defaults to the pod IP."
610610
type: string
611611
port:
612612
description: |-
@@ -871,7 +871,7 @@ spec:
871871
type: object
872872
properties:
873873
host:
874-
description: 'Optional: Host name to connect to, defaults to the pod IP.'
874+
description: "Optional: Host name to connect to, defaults to the pod IP."
875875
type: string
876876
port:
877877
description: |-
@@ -1027,6 +1027,12 @@ spec:
10271027
description: This is accessible behind a feature flag - kubernetes.podspec-init-containers
10281028
type: object
10291029
x-kubernetes-preserve-unknown-fields: true
1030+
loadBalancingPolicy:
1031+
description: |-
1032+
LoadBalancingPolicy is the load balancing algorithm used by the
1033+
activator to route requests to application pods. If unspecified,
1034+
a suggested default is applied depending on ContainerConcurrency
1035+
type: string
10301036
nodeSelector:
10311037
description: |-
10321038
This is accessible behind a feature flag - kubernetes.podspec-nodeselector
@@ -1291,7 +1297,7 @@ spec:
12911297
- path
12921298
properties:
12931299
fieldRef:
1294-
description: 'Required: Selects a field of the pod: only annotations, labels, name, namespace and uid are supported.'
1300+
description: "Required: Selects a field of the pod: only annotations, labels, name, namespace and uid are supported."
12951301
type: object
12961302
required:
12971303
- fieldPath
@@ -1314,7 +1320,7 @@ spec:
13141320
type: integer
13151321
format: int32
13161322
path:
1317-
description: 'Required: Path is the relative path name of the file to be created. Must not be absolute or contain the ''..'' path. Must be utf-8 encoded. The first item of the relative path must not start with ''..'''
1323+
description: "Required: Path is the relative path name of the file to be created. Must not be absolute or contain the '..' path. Must be utf-8 encoded. The first item of the relative path must not start with '..'"
13181324
type: string
13191325
resourceFieldRef:
13201326
description: |-
@@ -1325,7 +1331,7 @@ spec:
13251331
- resource
13261332
properties:
13271333
containerName:
1328-
description: 'Container name: required for volumes, optional for env vars'
1334+
description: "Container name: required for volumes, optional for env vars"
13291335
type: string
13301336
divisor:
13311337
description: Specifies the output format of the exposed resources, defaults to "1"
@@ -1335,7 +1341,7 @@ spec:
13351341
- type: string
13361342
x-kubernetes-int-or-string: true
13371343
resource:
1338-
description: 'Required: resource to select'
1344+
description: "Required: resource to select"
13391345
type: string
13401346
x-kubernetes-map-type: atomic
13411347
x-kubernetes-list-type: atomic

config/core/300-resources/revision.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ spec:
414414
type: object
415415
properties:
416416
host:
417-
description: 'Optional: Host name to connect to, defaults to the pod IP.'
417+
description: "Optional: Host name to connect to, defaults to the pod IP."
418418
type: string
419419
port:
420420
description: |-
@@ -582,7 +582,7 @@ spec:
582582
type: object
583583
properties:
584584
host:
585-
description: 'Optional: Host name to connect to, defaults to the pod IP.'
585+
description: "Optional: Host name to connect to, defaults to the pod IP."
586586
type: string
587587
port:
588588
description: |-
@@ -847,7 +847,7 @@ spec:
847847
type: object
848848
properties:
849849
host:
850-
description: 'Optional: Host name to connect to, defaults to the pod IP.'
850+
description: "Optional: Host name to connect to, defaults to the pod IP."
851851
type: string
852852
port:
853853
description: |-
@@ -1003,6 +1003,12 @@ spec:
10031003
description: This is accessible behind a feature flag - kubernetes.podspec-init-containers
10041004
type: object
10051005
x-kubernetes-preserve-unknown-fields: true
1006+
loadBalancingPolicy:
1007+
description: |-
1008+
LoadBalancingPolicy is the load balancing algorithm used by the
1009+
activator to route requests to application pods. If unspecified,
1010+
a suggested default is applied depending on ContainerConcurrency
1011+
type: string
10061012
nodeSelector:
10071013
description: |-
10081014
This is accessible behind a feature flag - kubernetes.podspec-nodeselector
@@ -1267,7 +1273,7 @@ spec:
12671273
- path
12681274
properties:
12691275
fieldRef:
1270-
description: 'Required: Selects a field of the pod: only annotations, labels, name, namespace and uid are supported.'
1276+
description: "Required: Selects a field of the pod: only annotations, labels, name, namespace and uid are supported."
12711277
type: object
12721278
required:
12731279
- fieldPath
@@ -1290,7 +1296,7 @@ spec:
12901296
type: integer
12911297
format: int32
12921298
path:
1293-
description: 'Required: Path is the relative path name of the file to be created. Must not be absolute or contain the ''..'' path. Must be utf-8 encoded. The first item of the relative path must not start with ''..'''
1299+
description: "Required: Path is the relative path name of the file to be created. Must not be absolute or contain the '..' path. Must be utf-8 encoded. The first item of the relative path must not start with '..'"
12941300
type: string
12951301
resourceFieldRef:
12961302
description: |-
@@ -1301,7 +1307,7 @@ spec:
13011307
- resource
13021308
properties:
13031309
containerName:
1304-
description: 'Container name: required for volumes, optional for env vars'
1310+
description: "Container name: required for volumes, optional for env vars"
13051311
type: string
13061312
divisor:
13071313
description: Specifies the output format of the exposed resources, defaults to "1"
@@ -1311,7 +1317,7 @@ spec:
13111317
- type: string
13121318
x-kubernetes-int-or-string: true
13131319
resource:
1314-
description: 'Required: resource to select'
1320+
description: "Required: resource to select"
13151321
type: string
13161322
x-kubernetes-map-type: atomic
13171323
x-kubernetes-list-type: atomic

config/core/300-resources/service.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ spec:
456456
type: object
457457
properties:
458458
host:
459-
description: 'Optional: Host name to connect to, defaults to the pod IP.'
459+
description: "Optional: Host name to connect to, defaults to the pod IP."
460460
type: string
461461
port:
462462
description: |-
@@ -624,7 +624,7 @@ spec:
624624
type: object
625625
properties:
626626
host:
627-
description: 'Optional: Host name to connect to, defaults to the pod IP.'
627+
description: "Optional: Host name to connect to, defaults to the pod IP."
628628
type: string
629629
port:
630630
description: |-
@@ -889,7 +889,7 @@ spec:
889889
type: object
890890
properties:
891891
host:
892-
description: 'Optional: Host name to connect to, defaults to the pod IP.'
892+
description: "Optional: Host name to connect to, defaults to the pod IP."
893893
type: string
894894
port:
895895
description: |-
@@ -1045,6 +1045,12 @@ spec:
10451045
description: This is accessible behind a feature flag - kubernetes.podspec-init-containers
10461046
type: object
10471047
x-kubernetes-preserve-unknown-fields: true
1048+
loadBalancingPolicy:
1049+
description: |-
1050+
LoadBalancingPolicy is the load balancing algorithm used by the
1051+
activator to route requests to application pods. If unspecified,
1052+
a suggested default is applied depending on ContainerConcurrency
1053+
type: string
10481054
nodeSelector:
10491055
description: |-
10501056
This is accessible behind a feature flag - kubernetes.podspec-nodeselector
@@ -1309,7 +1315,7 @@ spec:
13091315
- path
13101316
properties:
13111317
fieldRef:
1312-
description: 'Required: Selects a field of the pod: only annotations, labels, name, namespace and uid are supported.'
1318+
description: "Required: Selects a field of the pod: only annotations, labels, name, namespace and uid are supported."
13131319
type: object
13141320
required:
13151321
- fieldPath
@@ -1332,7 +1338,7 @@ spec:
13321338
type: integer
13331339
format: int32
13341340
path:
1335-
description: 'Required: Path is the relative path name of the file to be created. Must not be absolute or contain the ''..'' path. Must be utf-8 encoded. The first item of the relative path must not start with ''..'''
1341+
description: "Required: Path is the relative path name of the file to be created. Must not be absolute or contain the '..' path. Must be utf-8 encoded. The first item of the relative path must not start with '..'"
13361342
type: string
13371343
resourceFieldRef:
13381344
description: |-
@@ -1343,7 +1349,7 @@ spec:
13431349
- resource
13441350
properties:
13451351
containerName:
1346-
description: 'Container name: required for volumes, optional for env vars'
1352+
description: "Container name: required for volumes, optional for env vars"
13471353
type: string
13481354
divisor:
13491355
description: Specifies the output format of the exposed resources, defaults to "1"
@@ -1353,7 +1359,7 @@ spec:
13531359
- type: string
13541360
x-kubernetes-int-or-string: true
13551361
resource:
1356-
description: 'Required: resource to select'
1362+
description: "Required: resource to select"
13571363
type: string
13581364
x-kubernetes-map-type: atomic
13591365
x-kubernetes-list-type: atomic

docs/serving-api.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,20 @@ to stay open while not receiving any bytes from the user’s application. If
948948
unspecified, a system default will be provided.</p>
949949
</td>
950950
</tr>
951+
<tr>
952+
<td>
953+
<code>loadBalancingPolicy</code><br/>
954+
<em>
955+
string
956+
</em>
957+
</td>
958+
<td>
959+
<em>(Optional)</em>
960+
<p>LoadBalancingPolicy is the load balancing algorithm used by the
961+
activator to route requests to application pods. If unspecified,
962+
a suggested default is applied depending on ContainerConcurrency</p>
963+
</td>
964+
</tr>
951965
</table>
952966
</td>
953967
</tr>
@@ -1438,6 +1452,20 @@ to stay open while not receiving any bytes from the user&rsquo;s application. If
14381452
unspecified, a system default will be provided.</p>
14391453
</td>
14401454
</tr>
1455+
<tr>
1456+
<td>
1457+
<code>loadBalancingPolicy</code><br/>
1458+
<em>
1459+
string
1460+
</em>
1461+
</td>
1462+
<td>
1463+
<em>(Optional)</em>
1464+
<p>LoadBalancingPolicy is the load balancing algorithm used by the
1465+
activator to route requests to application pods. If unspecified,
1466+
a suggested default is applied depending on ContainerConcurrency</p>
1467+
</td>
1468+
</tr>
14411469
</tbody>
14421470
</table>
14431471
<h3 id="serving.knative.dev/v1.RevisionStatus">RevisionStatus
@@ -1666,6 +1694,20 @@ to stay open while not receiving any bytes from the user&rsquo;s application. If
16661694
unspecified, a system default will be provided.</p>
16671695
</td>
16681696
</tr>
1697+
<tr>
1698+
<td>
1699+
<code>loadBalancingPolicy</code><br/>
1700+
<em>
1701+
string
1702+
</em>
1703+
</td>
1704+
<td>
1705+
<em>(Optional)</em>
1706+
<p>LoadBalancingPolicy is the load balancing algorithm used by the
1707+
activator to route requests to application pods. If unspecified,
1708+
a suggested default is applied depending on ContainerConcurrency</p>
1709+
</td>
1710+
</tr>
16691711
</table>
16701712
</td>
16711713
</tr>

0 commit comments

Comments
 (0)