Skip to content

Conversation

@hoffmaen
Copy link
Contributor

@hoffmaen hoffmaen commented Jan 9, 2026

This Pull-Request replaces #4696.

This Pull-Request adds support for hash-based routing to Cloud Controller.

Summary:
The routes model is enhanced as follows:

  • hash is added as a valid loadbalancing option
  • hash_header is added as a per-route option. The option is mandatory when loadbalancing=hash
  • hash_balance is added as a per-route option. The option is optional when loadbalancing=hash

Validation of these options is added when creating and updating both via API and via manifest. All validations that do not need the context of a potentially existing route during an update, are executed in the message:

  • Hash Balance must be numeric
  • Hash Header and Hash Balance must not be specified together with round-robin or least-connection
  • Values for Hash Header and Hash Balance must not be arbitrarily long

Further validations and cleanups are performed on the route model, as they need the context of existing routes:

  • The route options from the update message are merged with existing routes, when existing
  • When the loadbalancing algorithm is hash, then Hash Header must be specified
  • When the loadbalancing algorithm is switched from hash to something else (or when it is removed), also Hash Header and Hash Balance options are removed
  • Hash Balance is always stored as a string, and is always trimmed to a numeric value with one decimal place

The route options are still stored as a raw JSON string in the routes table.

Links:

Thanks for contributing to cloud_controller_ng. To speed up the process of reviewing your pull request please provide us with:

  • A short explanation of the proposed change:

  • An explanation of the use cases your change solves

  • Links to any other associated PRs

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

@hoffmaen hoffmaen mentioned this pull request Jan 9, 2026
5 tasks
Copy link
Member

@philippthun philippthun left a comment

Choose a reason for hiding this comment

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

Most comments are minor things...

There is a file test-manifest-roundrobin.yml which seems to be some leftover.

I don't think we should modify spec/unit/messages/validators_spec.rb. I see that this was already done for the other route options, but from my point of view this file is more for generic validators and not for specific ones. The tests should be moved into a file route_options_message_spec.rb.

@philippthun philippthun marked this pull request as ready for review January 16, 2026 08:54
@philippthun philippthun merged commit 11f090a into cloudfoundry:main Jan 16, 2026
17 of 18 checks passed
ari-wg-gitbot added a commit to cloudfoundry/capi-release that referenced this pull request Jan 16, 2026
Changes in cloud_controller_ng:

- Support Hash-Based Routing
    PR: cloudfoundry/cloud_controller_ng#4746
    Author: Clemens Hoffmann <clemens.hoffmann@sap.com>
@hoffmaen hoffmaen deleted the hash-based-new branch January 16, 2026 14:38
hoffmaen added a commit to sap-contributions/cloud_controller_ng that referenced this pull request Jan 16, 2026
* Add loadbalancing option hash, and hash_header/hash_balance. Add validations

* Add basic options validation to manifest_routes_update_message

* Add basic tests for manifest route updates

* Simplify validations, improve error messages, adjust tests

* Add validation for hash balance being a float

* Have consistent validations in manifest_routes_updates_message and route_options_message

* Minor refactoring

* Add check for hash_balance value being 0 or >=1.1

* Transform hash_balance to string in the route model before saving

* Validate the route merged with the route update from the message.

* Attempt to forward errors in route_update validation to the client

* Add route options changes to app event

* Add new hash options to mnifest route

* Add new hash options to route properties presenter

* Move additional validation to route model

* Move final options cleanup to route model

* Proper error validation and forwarding

* Forward proper error message on route updates

* Add some logging to find the manifest issue

* Add more logging

* Logging in app_manifest_message

* Test a few things

* Test a few things pt 2

* Test a few things pt 3

* Test a few things pt 4

* Test a few things pt 5

* Test a few things pt 6

* Cleanup logging

* Use symbolized_keys in route_update

* WIP

* Add more validations and tests

* Add more tests for route_update

* Add more tests

* Some test fixes and cleanup

* Use blank? instead of nil? for loadbalancing check

* Fix rubocop issues

* Fix rubocop spec issues

* Refactor to resolve rubocop complexity findings

* Remove test file

* Move all route option message tests from validator spec to new spec file

* Introduce stub config in validator spec to fix execution of standalone spec test

* Fix typos and validation logic

* Fix validation function name inconsistencies

* Fix remaining issues found in review

* revert change to validators spec
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.

2 participants