-
Notifications
You must be signed in to change notification settings - Fork 88
Add weighted address strategy for multi-key listeners (#2394) #2405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -105,12 +105,36 @@ spec: | |||||
| required: | ||||||
| - routingKeys | ||||||
| type: object | ||||||
| weighted: | ||||||
| description: |- | ||||||
| WeightedStrategySpec specifies a map of routing keys to route traffic to. | ||||||
| Each routingKey has a weight value. | ||||||
|
||||||
|
|
||||||
| With this strategy traffic is distributed randomly among the reachable | ||||||
|
||||||
| routing keys. The larger the weight of a routing key - relative to the | ||||||
| weights of the other routing keys - the higher the likelihood of | ||||||
| receiving more traffic. E.g. if all routing keys have equal weights then the | ||||||
| traffic is distributed in a random uniform fashion among the reachable | ||||||
| routing keys. | ||||||
| properties: | ||||||
| routingKeys: | ||||||
| additionalProperties: | ||||||
| type: integer | ||||||
| description: routingKeys to route traffic to according to | ||||||
| their weight values | ||||||
| maxProperties: 256 | ||||||
| minProperties: 1 | ||||||
| type: object | ||||||
| x-kubernetes-map-type: granular | ||||||
| required: | ||||||
| - routingKeys | ||||||
| type: object | ||||||
| type: object | ||||||
| x-kubernetes-validations: | ||||||
| - message: exactly one of the fields in [priority] must be | ||||||
| - message: exactly one of the fields in [priority weighted] must be | ||||||
| set | ||||||
| rule: '[has(self.priority)].filter(x,x==true).size() == | ||||||
| 1' | ||||||
| rule: '[has(self.priority),has(self.weighted)].filter(x,x==true).size() | ||||||
| == 1' | ||||||
| tlsCredentials: | ||||||
| description: tlsCredentials for client-to-listener | ||||||
| type: string | ||||||
|
|
@@ -214,12 +238,27 @@ spec: | |||||
| required: | ||||||
| - routingKeysReachable | ||||||
| type: object | ||||||
| weighted: | ||||||
| description: weighted status | ||||||
| properties: | ||||||
| routingKeysReachable: | ||||||
| additionalProperties: | ||||||
| type: integer | ||||||
| description: |- | ||||||
| routingKeysReachable is a map of routingKeys with at least one | ||||||
|
||||||
| routingKeysReachable is a map of routingKeys with at least one | |
| routingKeysReachable is a mapping of routingKeys to weights with at least one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed as suggested.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,26 @@ | ||
| apiVersion: skupper.io/v2alpha1 | ||
| kind: MultiKeyListener | ||
| metadata: | ||
| name: backend | ||
| name: backend-priority | ||
| spec: | ||
| host: backend | ||
| host: backend-priority | ||
| port: 8080 | ||
| strategy: | ||
| priority: | ||
| routingKeys: | ||
| - backend-primary | ||
| - backend-secondary | ||
|
|
||
| --- | ||
| apiVersion: skupper.io/v2alpha1 | ||
| kind: MultiKeyListener | ||
| metadata: | ||
| name: backend-weighted | ||
| spec: | ||
| host: backend-weighted | ||
| port: 8081 | ||
| strategy: | ||
| weighted: | ||
| routingKeys: | ||
| backend-single: 1 | ||
| backend-double: 2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,15 +198,30 @@ func (s *SiteStateValidator) validateMultiKeyListeners(multiKeyListeners map[str | |
| return fmt.Errorf("port %d is already mapped for host %q (multikeylistener: %q)", mkl.Spec.Port, mkl.Spec.Host, name) | ||
| } | ||
| hostPorts[mkl.Spec.Host] = append(hostPorts[mkl.Spec.Host], mkl.Spec.Port) | ||
| if mkl.Spec.Strategy.Priority == nil { | ||
| return fmt.Errorf("invalid multikeylistener: %s - strategy.priority is required", mkl.Name) | ||
| if mkl.Spec.Strategy.Priority == nil && mkl.Spec.Strategy.Weighted == nil { | ||
| return fmt.Errorf("invalid multikeylistener: %s - strategy.priority or strategy.weighted is required", mkl.Name) | ||
| } | ||
| if len(mkl.Spec.Strategy.Priority.RoutingKeys) == 0 { | ||
| return fmt.Errorf("invalid multikeylistener: %s - routingKeys must not be empty", mkl.Name) | ||
| if mkl.Spec.Strategy.Priority != nil { | ||
fgiorgetti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if len(mkl.Spec.Strategy.Priority.RoutingKeys) == 0 { | ||
| return fmt.Errorf("invalid multikeylistener: %s - routingKeys must not be empty", mkl.Name) | ||
| } | ||
| for _, key := range mkl.Spec.Strategy.Priority.RoutingKeys { | ||
| if key == "" { | ||
| return fmt.Errorf("invalid multikeylistener: %s - routingKey must not be empty", mkl.Name) | ||
| } | ||
| } | ||
| } | ||
| for _, key := range mkl.Spec.Strategy.Priority.RoutingKeys { | ||
| if key == "" { | ||
| return fmt.Errorf("invalid multikeylistener: %s - routingKey must not be empty", mkl.Name) | ||
| if mkl.Spec.Strategy.Weighted != nil { | ||
| if len(mkl.Spec.Strategy.Weighted.RoutingKeys) == 0 { | ||
| return fmt.Errorf("invalid multikeylistener: %s - routingKeys must not be empty", mkl.Name) | ||
| } | ||
| for key, weight := range mkl.Spec.Strategy.Weighted.RoutingKeys { | ||
| if key == "" { | ||
| return fmt.Errorf("invalid multikeylistener: %s - routingKey must not be empty", mkl.Name) | ||
| } | ||
| if weight <= 0 { | ||
| return fmt.Errorf("invalid multikeylistener: %s - weight value must not be positive", mkl.Name) | ||
|
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed as suggested.