Skip to content

Add pick_addresses option for explicit IP candidate selection#674

Open
DeamonMV wants to merge 1 commit intok8snetworkplumbingwg:masterfrom
DeamonMV:dml-changes
Open

Add pick_addresses option for explicit IP candidate selection#674
DeamonMV wants to merge 1 commit intok8snetworkplumbingwg:masterfrom
DeamonMV:dml-changes

Conversation

@DeamonMV
Copy link
Copy Markdown

What this PR does / why we need it:

In some environments, only a specific subset of IPs within a subnet are available for allocation — due to external infrastructure constraints, policy grouping, or operational lifecycle (e.g., IPs rotating in and out of service). The existing range_start/range_end mechanism requires contiguous ranges, which cannot express arbitrary sets of eligible addresses.

The new pick_addresses field in RangeConfiguration allows users to specify an explicit list of candidate IPs. When provided, allocation selects from this list (in order) instead of iterating the full range, while still honoring CIDR bounds, exclude ranges, and existing reservations.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

Also fixes IPManagementKubernetesUpdate to preserve OmitRanges and PickAddresses when reconstructing range configuration for node slicing, where these fields were previously silently dropped.

Special notes for your reviewer (optional):

In some environments, only a specific subset of IPs within a subnet are
available for allocation — due to external infrastructure constraints,
policy grouping, or operational lifecycle (e.g., IPs rotating in and out
of service). The existing range_start/range_end mechanism requires
contiguous ranges, which cannot express arbitrary sets of eligible
addresses.

The new `pick_addresses` field in RangeConfiguration allows users to
specify an explicit list of candidate IPs. When provided, allocation
selects from this list (in order) instead of iterating the full range,
while still honoring CIDR bounds, exclude ranges, and existing
reservations.

Also fixes IPManagementKubernetesUpdate to preserve OmitRanges and
PickAddresses when reconstructing range configuration for node slicing,
where these fields were previously silently dropped.
@DeamonMV DeamonMV requested a review from dougbtv as a code owner February 27, 2026 13:43
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to IP address allocation by allowing explicit selection of IP candidates. This new functionality provides greater flexibility for environments with specific IP management requirements that cannot be met by simple contiguous ranges. Additionally, it includes a crucial fix to ensure that all range configuration parameters, including the new pick addresses and existing omit ranges, are correctly maintained during node slicing operations.

Highlights

  • New pick_addresses option: Introduced a new pick_addresses field in RangeConfiguration allowing users to specify an explicit list of candidate IPs for allocation. This addresses scenarios where contiguous IP ranges are insufficient due to external infrastructure constraints or policy grouping.
  • Enhanced IP Allocation Logic: The IterateForAssignment function now prioritizes IP allocation from the pick_addresses list, if provided, while still enforcing CIDR bounds, existing reservations, and exclude ranges.
  • Bug Fix: Preserve Range Configuration: Fixed an issue in IPManagementKubernetesUpdate where OmitRanges and the newly added PickAddresses were not being preserved when reconstructing range configurations for node slicing.
  • Comprehensive Test Coverage: Added extensive unit tests for the pick_addresses functionality, covering various scenarios including valid selection, skipping invalid/reserved IPs, honoring exclude ranges, and handling cases where all candidates are invalid.
Changelog
  • pkg/allocate/allocate.go
    • Modified AssignIP to pass the new PickAddresses field to IterateForAssignment.
    • Updated the signature of IterateForAssignment to accept a pickAddr []net.IP parameter.
    • Implemented logic within IterateForAssignment to iterate through pickAddr for allocation if provided, validating each candidate against network bounds, reservations, and exclusion rules.
    • Adjusted logging in IterateForAssignment to include the length of the pickAddr list.
  • pkg/allocate/allocate_test.go
    • Updated existing calls to IterateForAssignment to include a nil value for the new pickAddr parameter.
    • Added a new test context for pickAddr selection, including tests for selecting the first valid IP, skipping IPs outside the CIDR, skipping reserved IPs, honoring exclude ranges, handling invalid candidates, and allocating IPs outside rangeStart/rangeEnd if within the CIDR.
  • pkg/storage/kubernetes/ipam.go
    • Modified IPManagementKubernetesUpdate to explicitly preserve OmitRanges and PickAddresses when reconstructing RangeConfiguration during node slicing.
  • pkg/types/types.go
    • Added a new PickAddresses []net.IP field to the RangeConfiguration struct, with json:"pick_addresses,omitempty" tag.
Activity
  • The pull request introduces a new feature to allow explicit IP candidate selection.
  • It also includes a bug fix to ensure proper preservation of range configurations during node slicing.
  • Comprehensive test cases have been added to validate the new functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the pick_addresses option to the IP address allocation process, allowing users to specify an explicit list of candidate IPs for allocation. This addresses the limitation of the existing range-based allocation mechanism, which requires contiguous ranges. The changes include modifications to the IterateForAssignment function to incorporate the pickAddr parameter and corresponding logic to select IPs from the provided list. Additionally, the IPManagementKubernetesUpdate function is updated to preserve OmitRanges and PickAddresses during range configuration reconstruction. The pull request also includes new unit tests to validate the functionality of the pick_addresses option.

Comment on lines +148 to +149
// No valid IPs in pick list; return regular assignment error
return net.IP{}, reserveList, AssignmentError{firstIP, lastIP, ipnet, excludeRanges}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The error message returned when no valid IPs are found in the pickAddr list could be more informative. Consider including details about why the IPs were invalid (e.g., out of range, reserved, excluded) to aid in debugging.

Also, consider returning a wrapped error that includes the original AssignmentError for better context.

Suggested change
// No valid IPs in pick list; return regular assignment error
return net.IP{}, reserveList, AssignmentError{firstIP, lastIP, ipnet, excludeRanges}
return net.IP{}, reserveList, fmt.Errorf("no valid IP addresses found in pick list: %w", AssignmentError{firstIP, lastIP, ipnet, excludeRanges})

Comment on lines +87 to +88
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Could not allocate IP in range"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The error message assertion ContainSubstring("Could not allocate IP in range") is too generic. It would be better to assert against a more specific error message that includes details about the pickAddr list and why the allocation failed. This will make the test more robust and easier to debug.

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.

1 participant