Skip to content

feat(api): Added support for automatic prefix selection by VPC ID#3456

Draft
bcavnvidia wants to merge 1 commit into
NVIDIA:mainfrom
bcavnvidia:auto-prefix-selection
Draft

feat(api): Added support for automatic prefix selection by VPC ID#3456
bcavnvidia wants to merge 1 commit into
NVIDIA:mainfrom
bcavnvidia:auto-prefix-selection

Conversation

@bcavnvidia

Copy link
Copy Markdown
Contributor

This PR adds support for callers to auto-select VPC prefixes per interface by specifying only a VPC ID, which gets resolved to a VPC prefix with capacity. Some effort is made to avoid sparse allocation, but we're favoring simplicity and deadlock+serialization avoidance over strong avoidance of sparse-allocation for the moment. Not too hard to change later.

  • Adds typed VPC selection with IPv4-only, IPv6-only, and dual-stack modes, plus family-keyed resolved-prefix status in crates/rpc/proto/forge.proto.
  • Preserves caller intent while retaining legacy-readable prefix resolution for rolling compatibility.
  • Implements deterministic static first-fit allocation, canonical lock ordering, savepoint-based retries, and correct exhaustion/contention classification.
  • Supports all family modes internally through prefix, segment, and address persistence. Inbound IPv6 automatic modes remain temporarily gated at the RPC boundary.
  • Makes repeated VPC-selection updates idempotent and reuses resources when transitioning from an explicit prefix to its owning VPC.
  • Applies tenant ownership checks to explicit and automatic selections and updates cleanup, status, CLI output, documentation, and lifecycle tests.

Related issues

#3110

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Additional Notes

Partially addresses #3110
REST API work still needed.

@copy-pr-bot

copy-pr-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8eeef089-4365-4be1-a950-aa18af796954

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
crates/api-core/src/tests/instance.rs (1)

110-115: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consolidate the triplicated fixture_tenant_config() into a shared fixture. The identical helper now lives in three test modules; any future change to the fixture tenant contract must be applied in lockstep or the modules silently diverge. Extract a single definition into the existing crates/api-core/src/tests/common/api_fixtures module (alongside create_fixture_tenant) and import it in each site.

  • crates/api-core/src/tests/instance.rs#L110-L115: remove the local definition and import the shared helper.
  • crates/api-core/src/tests/instance_config_update.rs#L46-L51: remove the local definition and import the shared helper.
  • crates/api-core/src/tests/vpc_prefix.rs#L41-L46: remove the local definition and import the shared helper.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/api-core/src/tests/instance.rs` around lines 110 - 115, Consolidate
the duplicated fixture_tenant_config helper by adding one shared definition to
the existing api_fixtures module alongside create_fixture_tenant, then remove
the local definitions and import the shared helper in
crates/api-core/src/tests/instance.rs#L110-L115,
crates/api-core/src/tests/instance_config_update.rs#L46-L51, and
crates/api-core/src/tests/vpc_prefix.rs#L41-L46.
crates/machine-controller/src/handler.rs (1)

6437-6443: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider centralising the generated-segment projection. The identical expression interfaces.iter().filter_map(InstanceInterfaceConfig::generated_network_segment_id).collect_vec() now appears verbatim at three readiness/cleanup sites. Extracting a single helper (e.g. InstanceNetworkConfig::generated_network_segment_ids() or a free function over &[InstanceInterfaceConfig]) would keep the "which segments are generated VPC-prefix segments" contract in one place and guard against future divergence between readiness gating and cleanup.

  • crates/machine-controller/src/handler.rs#L6437-L6443: replace the inline filter_map(...).collect_vec() in InstanceState::WaitingForNetworkSegmentToBeReady with the shared helper.
  • crates/machine-controller/src/handler.rs#L7567-L7572: replace the identical expression in NetworkConfigUpdateState::WaitingForNetworkSegmentToBeReady with the same helper.
  • crates/machine-controller/src/handler.rs#L7929-L7932: replace the identical expression in release_network_segments_with_vpc_prefix with the same helper.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/machine-controller/src/handler.rs` around lines 6437 - 6443,
Centralize the generated network-segment projection in a shared helper, such as
InstanceNetworkConfig::generated_network_segment_ids(), preserving the existing
filter_map and collection behavior. Use that helper in
crates/machine-controller/src/handler.rs:6437-6443 within
InstanceState::WaitingForNetworkSegmentToBeReady, :7567-7572 within
NetworkConfigUpdateState::WaitingForNetworkSegmentToBeReady, and :7929-7932
within release_network_segments_with_vpc_prefix, replacing each inline
expression.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/api-core/src/tests/instance.rs`:
- Around line 110-115: Consolidate the duplicated fixture_tenant_config helper
by adding one shared definition to the existing api_fixtures module alongside
create_fixture_tenant, then remove the local definitions and import the shared
helper in crates/api-core/src/tests/instance.rs#L110-L115,
crates/api-core/src/tests/instance_config_update.rs#L46-L51, and
crates/api-core/src/tests/vpc_prefix.rs#L41-L46.

In `@crates/machine-controller/src/handler.rs`:
- Around line 6437-6443: Centralize the generated network-segment projection in
a shared helper, such as InstanceNetworkConfig::generated_network_segment_ids(),
preserving the existing filter_map and collection behavior. Use that helper in
crates/machine-controller/src/handler.rs:6437-6443 within
InstanceState::WaitingForNetworkSegmentToBeReady, :7567-7572 within
NetworkConfigUpdateState::WaitingForNetworkSegmentToBeReady, and :7929-7932
within release_network_segments_with_vpc_prefix, replacing each inline
expression.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: cf68be2c-2460-4ede-bded-b2d185b58fe8

📥 Commits

Reviewing files that changed from the base of the PR and between f70eada and 1792f9d.

📒 Files selected for processing (18)
  • crates/admin-cli/src/instance/show/cmd.rs
  • crates/agent/src/tests/full.rs
  • crates/api-core/src/handlers/instance.rs
  • crates/api-core/src/instance/mod.rs
  • crates/api-core/src/network_segment/allocate.rs
  • crates/api-core/src/tests/instance.rs
  • crates/api-core/src/tests/instance_config_update.rs
  • crates/api-core/src/tests/vpc_prefix.rs
  • crates/api-db/src/instance_address.rs
  • crates/api-db/src/instance_network_config.rs
  • crates/api-db/src/vpc_prefix.rs
  • crates/api-model/src/instance/config/network.rs
  • crates/api-model/src/instance/status/network.rs
  • crates/machine-controller/src/handler.rs
  • crates/rpc/build.rs
  • crates/rpc/proto/forge.proto
  • crates/rpc/src/model/instance/config/network.rs
  • crates/rpc/src/model/instance/status/network.rs

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