Skip to content

Add weighted address strategy for multi-key listeners (#2394)#2405

Open
gabordozsa wants to merge 3 commits intoskupperproject:mainfrom
gabordozsa:gabor_weighted_address_2394
Open

Add weighted address strategy for multi-key listeners (#2394)#2405
gabordozsa wants to merge 3 commits intoskupperproject:mainfrom
gabordozsa:gabor_weighted_address_2394

Conversation

@gabordozsa
Copy link
Collaborator

Add weighted address strategy for multi-key listeners

Fixes #2394

@gabordozsa gabordozsa added this to the 2.2.0 milestone Mar 13, 2026
@gabordozsa gabordozsa force-pushed the gabor_weighted_address_2394 branch 3 times, most recently from 1f3766e to e0d2c99 Compare March 16, 2026 14:59
@gabordozsa gabordozsa force-pushed the gabor_weighted_address_2394 branch from e0d2c99 to 4a3197f Compare March 18, 2026 12:02
@gabordozsa gabordozsa marked this pull request as ready for review March 18, 2026 12:03
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider following rewrite:

The listener distributes traffic among reachable routing keys according to their weights. Routing keys with higher weights receive a larger portion of the traffic. If all keys are assigned the same weight, traffic is split equally between them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the comment as suggested.

type: object
weighted:
description: |-
WeightedStrategySpec specifies a map of routing keys to route traffic to.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WeightedStrategySpec specifies a map of routing keys to route traffic to.
WeightedStrategySpec defines a mapping of routing keys to weights.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as suggested.

weighted:
description: |-
WeightedStrategySpec specifies a map of routing keys to route traffic to.
Each routingKey has a weight value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary if prev comment accepted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

additionalProperties:
type: integer
description: |-
routingKeysReachable is a map of routingKeys with at least one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
routingKeysReachable is a map of routingKeys with at least one
routingKeysReachable is a mapping of routingKeys to weights with at least one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as suggested.

RoutingKeys []string `json:"routingKeys"`
}

// WeightedStrategySpec specifies a map of routing keys to route traffic to.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on comments above, might need to change these comments

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All previous comments are generated from this file. I made the changes in this file and generated the yaml again.

@gabordozsa gabordozsa requested a review from pwright March 18, 2026 18:30
Copy link
Member

@fgiorgetti fgiorgetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is working great on both kubernetes with system sites. Nice job @gabordozsa.

One thing that we need to consider, is whether the strategy field should be immutable or not. If we allow it to change, we should cleanup the status.strategy field and update it with the new strategy.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be positive (remove the not).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return true

if m.Spec.Strategy.Priority != nil {
if m.Status.Strategy.Priority == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it force Status.Strategy.Weighted = nil (and the opposite when using Weighted) to clean up old status in case the strategy has changed?

@gabordozsa
Copy link
Collaborator Author

One thing that we need to consider, is whether the strategy field should be immutable or not. If we allow it to change, we should cleanup the status.strategy field and update it with the new strategy.

@fgiorgetti I think the strategy field should be immutable for now. The router does not allow updating the strategy so, the control plane should delete and re-create the multi-key listener if strategy changes. That would terminate existing TCP connections. If strategy update is required, we may add it in a follow up change including the router support for it.

@fgiorgetti
Copy link
Member

fgiorgetti commented Mar 20, 2026

One thing that we need to consider, is whether the strategy field should be immutable or not. If we allow it to change, we should cleanup the status.strategy field and update it with the new strategy.

@fgiorgetti I think the strategy field should be immutable for now. The router does not allow updating the strategy so, the control plane should delete and re-create the multi-key listener if strategy changes. That would terminate existing TCP connections. If strategy update is required, we may add it in a follow up change including the router support for it.

Agreed. The CRD validation could be enhanced to guarantee that the field is immutable.

@pwright
Copy link
Member

pwright commented Mar 20, 2026

Help me understand immutable in this context.
If i create a CR named 'A' with strategy 'priority', I can not change the strategy without first deleting 'A' resource. Can i then recreate 'A' with strategy weighted?

@fgiorgetti
Copy link
Member

Help me understand immutable in this context. If i create a CR named 'A' with strategy 'priority', I can not change the strategy without first deleting 'A' resource. Can i then recreate 'A' with strategy weighted?

Correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add wrr strategy to MultiKeyListener

3 participants