-
Notifications
You must be signed in to change notification settings - Fork 657
Introduce prefix allocation #2611
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?
Conversation
a3a16f8
to
5a6c64a
Compare
1077c56
to
46e082b
Compare
Hi @aramprice, I just watched the recording of the foundational infra meeting from April 17th. To clarify a bit: The idea for IPv6 is to use as much native network routing as possible, i.e. not use an overlay network for IPv6. This means that the IP addresses that would be assigned to the containers will be delegated from an IPv6 prefix that is assigned to the Diego VM. Your question about whether those IP addresses would move in case of an evacuation: no. These IP addresses are not "sticky" to the app or app instance and would not move. The goal is to make the networking setup for Diego simpler by using "native" IPv6 addressing. Traffic aimed at a particular container will reach the Diego VM via its CIDR range, and then the Diego VM's kernel can forward the traffic to the container's virtual NIC. Please also note that the networks are supposed to be dual stack, not pure IPv6. So you would want to assign multiple (at least one IPv4 and one IPv6) networks to the same VM, as @fmoehler mentioned in the call already. The "prefix" parameter is also the size of the prefix to delegate to each VM from a larger range. Have a look at the discussion while creating the RFC for a more extensive example. The VM is supposed to self-assign an address to itself. Usually this is the |
354d3e8
to
7cdb704
Compare
Hi @peanball, Thanks for that additional context - the info and the RFC were helpful. In thinking about the overall changes to Bosh a few goals or principles (maybe too strong a word) came to mind:
This isn't to imply disagreement about the current state of things, only to captures my thoughts at the moment. |
@aramprice thanks for your feedback! I just want to elaborate a little on our current idea, but of course this is open for ideas. Regarding your points:
|
Thanks @aramprice, I fully agree with you there. The logical unit of "IP address", with or without netmask (i.e. prefix) should be supported in either scenario and contain the logic of representation. As @fmoehler mentioned, omitting the And there should not be assumptions about dual stack but dual stack should be possible. So far, BOSH supported either v4 or v6, not both at the same time. The mechanism to support more than one network is a classic n+1 problem and can be solved as such where possible. We just happen to choose n=2 with one v4 and one v6 network. This should be the mindset. |
@fmoehler I have a general comment on the term In the end this is the prefix (size) delegated to each instance attached to this subnet, right? Can we somehow express this better? My suggestion would be
alternatively |
9f17169
to
4b6f351
Compare
One thing regarding the display of the ip addresses. The bosh-cli is showing the ips as they come from the directors API. As @fmoehler mentioned the prefixes are stored in the db with their prefixes. This also means that the bosh-cli will show the ip addresses with their prefix. Because all the docs are showing examples with ipv4 only this would also mean that everybody has to be prepared that with this change the cli could possibly show the ips (i.e. with command bosh ... vms) in format "ip<v4\v6>/prefix". |
So far we ensured not to change the API and only return the ip (without the prefix), please refer: https://github.com/cloudfoundry/bosh/pull/2611/files#diff-c9cf4222f4ba33b6b3f35d7f32bfbb2c03a91470e18672bd3dda5468c38a0808R22 so it should not change the way ip addresses are displayed. |
01c56da
to
acc71bd
Compare
ab6edde
to
e5e6af9
Compare
3be74c9
to
a52e682
Compare
commit a52e682 Author: Felix Moehler <[email protected]> Date: Tue Jun 24 13:24:21 2025 +0200 adapt migration commit 3cdec28 Author: Felix Moehler <[email protected]> Date: Mon Jun 23 15:50:05 2025 +0200 fix unit tests commit 3ed1a7a Author: Felix Moehler <[email protected]> Date: Fri Jun 20 11:50:46 2025 +0200 cleanup and bug fix commit 1c092e7 Author: Felix Moehler <[email protected]> Date: Wed Jun 18 15:42:41 2025 +0200 fixes after db migration commit 0a1f304 Author: Felix Moehler <[email protected]> Date: Wed Jun 18 15:41:07 2025 +0200 fix bug subnet and prefix reservation commit 925a6e6 Author: Felix Moehler <[email protected]> Date: Wed Jun 18 10:22:45 2025 +0200 perform migration commit ebef432 Author: Felix Moehler <[email protected]> Date: Tue Jun 17 17:57:47 2025 +0200 fix bug where prefix between subnet and reservation did not match commit a9ad2ff Author: Felix Moehler <[email protected]> Date: Mon Jun 16 11:19:27 2025 +0200 refactor ip_repo commit 9f31e94 Author: Felix Moehler <[email protected]> Date: Mon Jun 16 11:13:45 2025 +0200 refactor instance network reservations commit 9097d56 Author: Felix Moehler <[email protected]> Date: Mon Jun 16 09:50:32 2025 +0200 adapt dynamic network commit fa2ad8f Author: Felix Moehler <[email protected]> Date: Thu Jun 12 20:20:08 2025 +0200 fix unit next part commit d5c1dbe Author: Felix Moehler <[email protected]> Date: Thu Jun 12 20:09:59 2025 +0200 fix unit tests and error message for invalid address commit fcaf710 Author: Felix Moehler <[email protected]> Date: Thu Jun 12 19:38:45 2025 +0200 fix bug and unit tests commit ff30c40 Author: Felix Moehler <[email protected]> Date: Wed Jun 11 10:28:35 2025 +0200 fix compatibility issue between new and old ip_address format commit 48c90fa Author: Felix Moehler <[email protected]> Date: Tue Jun 10 16:41:06 2025 +0200 dont update restricted ips in place commit bceda51 Author: Felix Moehler <[email protected]> Date: Tue Jun 10 11:39:39 2025 +0200 return prefix for prefix addresses commit 55bad9a Author: Ansh Rupani <[email protected]> Date: Mon Jun 2 14:53:00 2025 +0200 fix unit tests commit 776fb94 Author: Felix Moehler <[email protected]> Date: Fri May 9 13:30:58 2025 +0200 fix prefix for ipv6 commit acd894a Author: Felix Moehler <[email protected]> Date: Thu May 8 16:11:16 2025 +0200 continue commit 3a616e8 Author: Felix Moehler <[email protected]> Date: Wed Apr 30 09:29:36 2025 +0200 export ips_cidr in different field commit 139e0ba Author: Felix Moehler <[email protected]> Date: Tue Apr 29 12:58:16 2025 +0200 introduce static ip check for prefixes commit f53be1a Author: Felix Moehler <[email protected]> Date: Mon Apr 28 17:05:50 2025 +0200 more work commit d0af77f Author: Felix Moehler <[email protected]> Date: Mon Apr 28 14:35:18 2025 +0200 return prefix in create_vm_response commit 5a6dfa4 Author: Felix Moehler <[email protected]> Date: Mon Apr 28 14:14:13 2025 +0200 unit test fixes + adaptions commit 5da086f Author: Felix Moehler <[email protected]> Date: Thu Apr 24 16:05:03 2025 +0200 fixes commit bb89a65 Author: Felix Moehler <[email protected]> Date: Thu Apr 24 15:20:53 2025 +0200 fixes commit 97230a3 Author: Felix Moehler <[email protected]> Date: Thu Apr 24 15:09:07 2025 +0200 fixes commit 0a63fd8 Author: Felix Moehler <[email protected]> Date: Thu Apr 24 14:36:46 2025 +0200 fixes commit 473d022 Author: Felix Moehler <[email protected]> Date: Thu Apr 24 12:39:42 2025 +0200 fixes commit 14901f4 Author: Felix Moehler <[email protected]> Date: Thu Apr 24 09:48:42 2025 +0200 fixes commit 25d00c2 Author: Felix Moehler <[email protected]> Date: Thu Apr 24 09:36:07 2025 +0200 remove prefix from job network commit a4f8444 Author: Felix Moehler <[email protected]> Date: Tue Apr 15 19:46:19 2025 +0200 introduce new prefix column in ip addresses table commit ca54445 Author: Felix Moehler <[email protected]> Date: Tue Apr 15 09:03:07 2025 +0200 create seperate reservation for prefix commit 00d71a5 Author: Felix Moehler <[email protected]> Date: Mon Apr 14 17:05:30 2025 +0200 introduce prefix property for networks
a52e682
to
888683f
Compare
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.
Pull Request Overview
This PR introduces support for prefix allocation when assigning IP addresses by storing IP addresses in CIDR notation rather than as integer values. Key changes include modifications to IP conversion logic in multiple models and utilities, updates to numerous tests for both IPv4 and IPv6 with explicit prefix values, and changes to RPC/API behavior to include a separate prefix field.
Reviewed Changes
Copilot reviewed 56 out of 56 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/bosh-director/lib/bosh/director/models/vm.rb | Updates methods for extracting IPs, introducing logic that strips CIDR for /32 and /128 addresses. |
src/bosh-director/lib/bosh/director/deployment_plan/manual_network.rb | Validates that the reserved IP’s prefix matches the subnet prefix and propagates the prefix into network settings. |
src/bosh-director/lib/bosh/director/ip_provider/ip_repo.rb | Refactors IP allocation methods, introducing new logic to handle CIDR conversion and next-available IP calculation. |
Comments suppressed due to low confidence (1)
src/bosh-director/lib/bosh/director/deployment_plan/manual_network.rb:64
- [nitpick] It would be helpful to add a comment explaining why the subnet prefix must exactly match the reservation prefix to ensure future maintainability and clarity for other developers.
unless subnet.prefix.to_i == ip_or_cidr.prefix.to_i
ips_cidr.map do | cidr_ip | | ||
if ( cidr_ip.include?(':') && cidr_ip.include?('/128') ) || ( cidr_ip.include?('.') && cidr_ip.include?('/32') ) | ||
cidr_ip.split('/')[0] | ||
else | ||
cidr_ip | ||
end | ||
end |
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.
The condition that strips the CIDR suffix for /32 and /128 addresses may lead to inconsistent behavior if non-standard prefix sizes are used; consider returning the full CIDR representation to align with the new prefix allocation support.
ips_cidr.map do | cidr_ip | | |
if ( cidr_ip.include?(':') && cidr_ip.include?('/128') ) || ( cidr_ip.include?('.') && cidr_ip.include?('/32') ) | |
cidr_ip.split('/')[0] | |
else | |
cidr_ip | |
end | |
end | |
ips_cidr |
Copilot uses AI. Check for mistakes.
filtered_ips = ip_entries.sort_by { |ip| ip.to_i }.reject { |ip| ip.to_i < first_range_address.to_i } #remove ips that are below subnet range | ||
|
||
current_ip = Bosh::Director::IpAddrOrCidr.new(first_range_address.to_i + 1) | ||
found = false | ||
|
||
while found == false | ||
current_prefix = Bosh::Director::IpAddrOrCidr.new("#{current_ip}/#{prefix}") | ||
|
||
if filtered_ips.any? { |ip| current_prefix.include?(ip) } | ||
filtered_ips.reject! { |ip| ip.to_i < current_prefix.to_i } | ||
actual_ip_prefix = filtered_ips.first.count | ||
if actual_ip_prefix > current_prefix.count | ||
current_ip = Bosh::Director::IpAddrOrCidr.new(current_ip.to_i + actual_ip_prefix) | ||
else | ||
current_ip = Bosh::Director::IpAddrOrCidr.new(current_ip.to_i + current_prefix.count) | ||
end | ||
else | ||
found_cidr = current_prefix | ||
found = true | ||
end | ||
end | ||
|
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.
[nitpick] The algorithm for determining the next available IP is fairly complex; consider refactoring this logic or adding inline comments to clarify the adjustments made to 'current_ip' based on the filtered IP entries.
filtered_ips = ip_entries.sort_by { |ip| ip.to_i }.reject { |ip| ip.to_i < first_range_address.to_i } #remove ips that are below subnet range | |
current_ip = Bosh::Director::IpAddrOrCidr.new(first_range_address.to_i + 1) | |
found = false | |
while found == false | |
current_prefix = Bosh::Director::IpAddrOrCidr.new("#{current_ip}/#{prefix}") | |
if filtered_ips.any? { |ip| current_prefix.include?(ip) } | |
filtered_ips.reject! { |ip| ip.to_i < current_prefix.to_i } | |
actual_ip_prefix = filtered_ips.first.count | |
if actual_ip_prefix > current_prefix.count | |
current_ip = Bosh::Director::IpAddrOrCidr.new(current_ip.to_i + actual_ip_prefix) | |
else | |
current_ip = Bosh::Director::IpAddrOrCidr.new(current_ip.to_i + current_prefix.count) | |
end | |
else | |
found_cidr = current_prefix | |
found = true | |
end | |
end | |
# Sort IP entries by their integer value and filter out IPs below the subnet range | |
filtered_ips = ip_entries.sort_by { |ip| ip.to_i }.reject { |ip| ip.to_i < first_range_address.to_i } | |
# Start searching from the first address in the range + 1 | |
current_ip = Bosh::Director::IpAddrOrCidr.new(first_range_address.to_i + 1) | |
found = false | |
# Iterate until a valid CIDR is found | |
while found == false | |
# Create a CIDR prefix using the current IP and the given prefix length | |
current_prefix = Bosh::Director::IpAddrOrCidr.new("#{current_ip}/#{prefix}") | |
# Check if any filtered IPs fall within the current prefix | |
if filtered_ips.any? { |ip| current_prefix.include?(ip) } | |
# Remove IPs below the current prefix from the filtered list | |
filtered_ips.reject! { |ip| ip.to_i < current_prefix.to_i } | |
actual_ip_prefix = filtered_ips.first.count | |
# Adjust current_ip based on the prefix count of the first filtered IP | |
if actual_ip_prefix > current_prefix.count | |
current_ip = Bosh::Director::IpAddrOrCidr.new(current_ip.to_i + actual_ip_prefix) | |
else | |
current_ip = Bosh::Director::IpAddrOrCidr.new(current_ip.to_i + current_prefix.count) | |
end | |
else | |
# If no IPs are within the current prefix, the CIDR is valid | |
found_cidr = current_prefix | |
found = true | |
end | |
end | |
# Return the found CIDR |
Copilot uses AI. Check for mistakes.
What is this change about?
As described in RFC https://github.com/cloudfoundry/community/blob/main/toc/rfc/rfc-0038-ipv6-dual-stack-for-cf.md bosh shall be enabled to allocate prefix ip addresses (ipv4 and ipv6). Currently bosh only supports attaching ip addresses with a /32 (ipv4) or /128 (ipv6) prefix, which are single ip addresses. To apply these changes a new property called 'prefix' is introduced in the cloud config networks section. Please refer to the example below for a manual network:
This example network tells bosh that instead of assigning a single ip address, to assign a prefix. So to slash the /56 network into multiple /80 blocks.
The ip address allocation of the bosh director is adapted to consider these prefixes (previously the director was just counting up by 1)
One major change is how the ip addresses are stored inside the database. The address_str field in the ip_addresses table will change from storing the ip address as an integer representation of the ip to store the ip address in cidr notation. This change is necessary to not "lose" the prefix information when storing the ip address. Also it has the advantage that you can directly create an IpAddrOrCidr Object out of the string coming from the database.
This PR also changes the RPC Interface for the create_vm method. It will include a separate field called "prefix". We will send the Prefix information in a separate field to not break existing cpis. Older CPIs that do not support prefix allocation will just ignore this field. Below you can find an example network section of the create_vm call:
The prefix here is 32 indicating a single ip address.
Once the vm creation is done. The bosh director api will return prefix ips with the normal ips. E.g. the bosh cli would display this as it displayed single ip addresses before. Here one example with one ipv4, one ipv4 prefix, one ipv6 and one ipv6 prefix with two instances:
What tests have you run against this PR?
Unit tests
Acceptance Tests in progress
How should this change be described in bosh release notes?
Enable prefix allocation support for manual networks.
Does this PR introduce a breaking change?
No
Tag your pair, your PM, and/or team!
@anshrupani @DennisAhausSAP