Skip to content

fix(rest-api): Auto vpc-prefix support#3850

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

fix(rest-api): Auto vpc-prefix support#3850
bcavnvidia wants to merge 1 commit into
NVIDIA:mainfrom
bcavnvidia:auto-vpc-prefix-rest

Conversation

@bcavnvidia

Copy link
Copy Markdown
Contributor

#3456 added support for auto-selecting VPC prefixes via VPC ID on interfaces. This PR does the work of exposing that in the rest-api layer.

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

Closes #3110

@copy-pr-bot

copy-pr-bot Bot commented Jul 22, 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 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features
    • Added support for selecting instance interfaces by VPC ID with IPv4 or IPv6 family preferences.
    • Preserved VPC selection intent across instance creation, updates, batch creation, and controller workflows.
    • Added VPC selection details to interface responses and filtering.
  • Bug Fixes
    • Improved synchronization of resolved VPC prefixes and interface status.
    • Added HTTP 429 responses for resource-exhaustion errors.
  • Documentation
    • Updated API schemas, validation rules, examples, and error responses for VPC-based interface selection.

Walkthrough

Instance create, update, and batch flows now accept controller-managed VPC interface selection through vpcId and ipFamilies. The selection is validated, persisted, sent to Core, reconciled with inventory, exposed in API responses, included in VPC filtering, and mapped to HTTP 429 errors when enabled.

Changes

VPC selection support

Layer / File(s) Summary
API contracts and validation
rest-api/api/pkg/api/model/*, rest-api/openapi/spec.yaml
Interface requests and responses support vpcId and ipFamilies, with selector exclusivity, family normalization, secondary-VPC validation, and updated OpenAPI schemas.
Persistence and filtering
rest-api/db/pkg/db/model/*, rest-api/db/pkg/migrations/*
Interfaces persist VPC IDs and IP-family modes, migrations add the corresponding columns and foreign key, and instance VPC filtering includes directly selected interfaces.
Instance and batch handler flows
rest-api/api/pkg/api/handler/instance.go, rest-api/api/pkg/api/handler/instancebatch.go
Create, update, and batch handlers validate VPC selections, persist interface intent, emit Core VPC configuration, adjust physical-interface checks, and propagate selected VPCs.
Workflow inventory reconciliation
rest-api/workflow/pkg/activity/instance/*
Workflow matching resolves controller VPC selectors to persisted interfaces and synchronizes resolved VPC prefixes from inventory status.
Validation and integration coverage
rest-api/api/pkg/api/handler/*_test.go, rest-api/api/pkg/api/model/*_test.go, rest-api/db/pkg/db/model/*_test.go, rest-api/workflow/pkg/activity/instance/*_test.go
Tests cover request validation, create/update/batch preservation, persistence, filtering, Core request construction, and inventory reconciliation.
Resource exhaustion mapping
rest-api/site-workflow/pkg/error/error.go, rest-api/api/pkg/api/handler/util/common/*, rest-api/openapi/spec.yaml
Resource exhaustion errors receive a dedicated Temporal type and optional HTTP 429 mapping with corresponding API responses and tests.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant InstanceHandler
  participant InterfaceDAO
  participant SiteWorkflow
  participant InventoryActivity
  Client->>InstanceHandler: submit vpcId and ipFamilies
  InstanceHandler->>InterfaceDAO: persist VPC interface intent
  InstanceHandler->>SiteWorkflow: send VPC network configuration
  SiteWorkflow-->>InventoryActivity: report interface inventory
  InventoryActivity->>InterfaceDAO: reconcile VPC prefix and status
  InterfaceDAO-->>Client: return updated interface state
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.63% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: automatic VPC prefix support.
Description check ✅ Passed The description matches the feature and references the linked issue; it is clearly related to the changes.
Linked Issues check ✅ Passed The changes add VPC-ID-based interface selection and ResourceExhausted handling, covering auto-prefix selection and exhaustion behavior.
Out of Scope Changes check ✅ Passed The API, model, DB, workflow, and test changes all support the VPC-selection feature and error handling.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
rest-api/openapi/spec.yaml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'

🔧 ast-grep (0.44.1)
rest-api/docs/index.html

ast-grep timed out on this file


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.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rest-api/openapi/spec.yaml (1)

18514-18531: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

vpcId should be nullable to match its sibling selectors.

subnetId and vpcPrefixId are both typed [string, 'null'] since they are optional, mutually-exclusive selectors on the same Interface. The new vpcId field (Line 18521) is typed as a plain string, breaking that convention. If the server ever emits an explicit vpcId: null for a Subnet- or explicit-prefix-backed interface (as it evidently does for subnetId/vpcPrefixId today), strict JSON Schema validation of this OpenAPI 3.1 document will reject the response.

🛡️ Proposed fix for schema consistency
         vpcId:
-          type: string
+          type:
+            - string
+            - 'null'
           description: ID of the VPC from which the Controller selects a prefix
           format: uuid
🤖 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 `@rest-api/openapi/spec.yaml` around lines 18514 - 18531, Update the vpcId
property in the relevant interface schema to allow both string and null,
matching the nullable typing of subnetId and vpcPrefixId while preserving its
UUID format and description.
🤖 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.

Inline comments:
In `@rest-api/api/pkg/api/model/interface.go`:
- Around line 328-350: Update NewAPIInterface in
rest-api/api/pkg/api/model/interface.go (lines 328-350) to assign VpcPrefix only
when VpcPrefixID is present and VpcID is nil, matching the existing VpcPrefixID
condition. Extend the vpcInterface fixture and expectations in
rest-api/api/pkg/api/model/interface_test.go (lines 34-52) to include a loaded
VpcPrefix and verify it is omitted from the response.

In `@rest-api/db/pkg/db/model/interface.go`:
- Around line 435-450: Update the interface update path around VpcID and
VpcIPFamilyMode so transitioning from VPC-ID selection to subnet- or
prefix-based selection clears the stale VpcID and related VPC selector state
instead of retaining it. Ensure the clear/update handling can persist null
values and that API projection no longer prioritizes the old VPC selection after
the transition; preserve existing behavior when VPC selector values are
provided.

In `@rest-api/openapi/spec.yaml`:
- Around line 18654-18658: Update the dependentSchemas.subnetId constraint for
the inlineRoutingProfile property so Subnet-backed interfaces only allow
inlineRoutingProfile to be null, matching the existing ipAddress restriction and
the field description. Preserve the current behavior for interfaces without
subnetId.
- Around line 18590-18596: Update InterfaceCreateRequest.ipFamilies to reference
the shared IPFamily schema used by Interface.ipFamilies instead of defining a
hard-coded IPv4 enum, ensuring both properties stay aligned when IPv6 support
changes.

In `@rest-api/site-workflow/pkg/error/error.go`:
- Around line 94-95: Add a table-driven test case for WrapErr covering
codes.ResourceExhausted, asserting it returns a non-retryable application error
whose type is ErrTypeNICoResourceExhausted. Exercise the WrapErr branch directly
rather than constructing ErrTypeNICoResourceExhausted independently, and
preserve the existing expectations for other codes.

---

Outside diff comments:
In `@rest-api/openapi/spec.yaml`:
- Around line 18514-18531: Update the vpcId property in the relevant interface
schema to allow both string and null, matching the nullable typing of subnetId
and vpcPrefixId while preserving its UUID format and description.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 34edbe99-4078-4571-80d4-6d5eaef40ce8

📥 Commits

Reviewing files that changed from the base of the PR and between 85e7389 and 4179c59.

⛔ Files ignored due to path filters (8)
  • rest-api/sdk/standard/api_instance.go is excluded by !rest-api/sdk/standard/api_*.go
  • rest-api/sdk/standard/client.go is excluded by !rest-api/sdk/standard/client.go
  • rest-api/sdk/standard/model_batch_instance_create_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_instance_create_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_instance_update_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_interface.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_interface_create_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_ip_family.go is excluded by !rest-api/sdk/standard/model_*.go
📒 Files selected for processing (20)
  • rest-api/api/pkg/api/handler/instance.go
  • rest-api/api/pkg/api/handler/instance_test.go
  • rest-api/api/pkg/api/handler/instancebatch.go
  • rest-api/api/pkg/api/handler/instancebatch_test.go
  • rest-api/api/pkg/api/handler/util/common/common.go
  • rest-api/api/pkg/api/handler/util/common/common_test.go
  • rest-api/api/pkg/api/model/instance.go
  • rest-api/api/pkg/api/model/instance_test.go
  • rest-api/api/pkg/api/model/interface.go
  • rest-api/api/pkg/api/model/interface_test.go
  • rest-api/db/pkg/db/model/instance.go
  • rest-api/db/pkg/db/model/instance_test.go
  • rest-api/db/pkg/db/model/interface.go
  • rest-api/db/pkg/db/model/interface_test.go
  • rest-api/db/pkg/migrations/20260720120000_interface_vpc_selection.go
  • rest-api/docs/index.html
  • rest-api/openapi/spec.yaml
  • rest-api/site-workflow/pkg/error/error.go
  • rest-api/workflow/pkg/activity/instance/instance.go
  • rest-api/workflow/pkg/activity/instance/instance_test.go

Comment thread rest-api/api/pkg/api/model/interface.go
Comment thread rest-api/db/pkg/db/model/interface.go
Comment thread rest-api/openapi/spec.yaml
Comment thread rest-api/openapi/spec.yaml
Comment thread rest-api/site-workflow/pkg/error/error.go
@bcavnvidia
bcavnvidia force-pushed the auto-vpc-prefix-rest branch from 4179c59 to f209e98 Compare July 22, 2026 20:55
@bcavnvidia
bcavnvidia marked this pull request as ready for review July 22, 2026 21:34
@bcavnvidia
bcavnvidia requested a review from a team as a code owner July 22, 2026 21:34
@bcavnvidia
bcavnvidia marked this pull request as draft July 22, 2026 21:34
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

🔐 TruffleHog Secret Scan

No secrets or credentials found!

Your code has been scanned for 700+ types of secrets and credentials. All clear! 🎉

🔗 View scan details

🕐 Last updated: 2026-07-22 21:38:55 UTC | Commit: f209e98

@bcavnvidia
bcavnvidia force-pushed the auto-vpc-prefix-rest branch from f209e98 to 2c93971 Compare July 22, 2026 22:04
@bcavnvidia
bcavnvidia marked this pull request as ready for review July 22, 2026 22:04
@bcavnvidia
bcavnvidia marked this pull request as draft July 22, 2026 22:04

@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 (1)
rest-api/workflow/pkg/activity/instance/instance_test.go (1)

231-235: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: consolidate the repeated "mark instance stale" mutation.

The UPDATE instance SET updated = ... staleness setup is duplicated here and at Lines 369-373 and 390-394 (with an inline variant inside buildInstance). Extracting a small helper would remove the copy/paste and centralize the magic *2 interval, improving readability without altering behavior.

♻️ Proposed helper extraction
markInstanceStale := func(instanceID uuid.UUID) {
	_, staleErr := dbSession.DB.Exec(
		"UPDATE instance SET updated = ? WHERE id = ?",
		time.Now().Add(-time.Duration(cutil.InventoryReceiptInterval)*2),
		instanceID,
	)
	require.NoError(t, staleErr)
}

Then replace the three standalone blocks (and the inline exec in buildInstance) with markInstanceStale(<id>).

🤖 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 `@rest-api/workflow/pkg/activity/instance/instance_test.go` around lines 231 -
235, Consolidate the repeated stale-instance UPDATE setup in the test by adding
a local markInstanceStale helper that accepts an instance ID, performs the
existing timestamp mutation, and asserts no error. Replace the duplicate
mutations near the current setup and the corresponding blocks in buildInstance,
preserving the existing behavior and interval calculation.
🤖 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 `@rest-api/workflow/pkg/activity/instance/instance_test.go`:
- Around line 231-235: Consolidate the repeated stale-instance UPDATE setup in
the test by adding a local markInstanceStale helper that accepts an instance ID,
performs the existing timestamp mutation, and asserts no error. Replace the
duplicate mutations near the current setup and the corresponding blocks in
buildInstance, preserving the existing behavior and interval calculation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 696321a1-5200-46e2-81a0-8f8882894f7d

📥 Commits

Reviewing files that changed from the base of the PR and between f209e98 and 2c93971.

⛔ Files ignored due to path filters (8)
  • rest-api/sdk/standard/api_instance.go is excluded by !rest-api/sdk/standard/api_*.go
  • rest-api/sdk/standard/client.go is excluded by !rest-api/sdk/standard/client.go
  • rest-api/sdk/standard/model_batch_instance_create_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_instance_create_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_instance_update_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_interface.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_interface_create_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_ip_family.go is excluded by !rest-api/sdk/standard/model_*.go
📒 Files selected for processing (21)
  • rest-api/api/pkg/api/handler/instance.go
  • rest-api/api/pkg/api/handler/instance_test.go
  • rest-api/api/pkg/api/handler/instancebatch.go
  • rest-api/api/pkg/api/handler/instancebatch_test.go
  • rest-api/api/pkg/api/handler/util/common/common.go
  • rest-api/api/pkg/api/handler/util/common/common_test.go
  • rest-api/api/pkg/api/model/instance.go
  • rest-api/api/pkg/api/model/instance_test.go
  • rest-api/api/pkg/api/model/interface.go
  • rest-api/api/pkg/api/model/interface_test.go
  • rest-api/db/pkg/db/model/instance.go
  • rest-api/db/pkg/db/model/instance_test.go
  • rest-api/db/pkg/db/model/interface.go
  • rest-api/db/pkg/db/model/interface_test.go
  • rest-api/db/pkg/migrations/20260720120000_interface_vpc_selection.go
  • rest-api/docs/index.html
  • rest-api/openapi/oasdiff-breaking-changes-ignore.txt
  • rest-api/openapi/spec.yaml
  • rest-api/site-workflow/pkg/error/error.go
  • rest-api/workflow/pkg/activity/instance/instance.go
  • rest-api/workflow/pkg/activity/instance/instance_test.go
🚧 Files skipped from review as they are similar to previous changes (17)
  • rest-api/db/pkg/migrations/20260720120000_interface_vpc_selection.go
  • rest-api/site-workflow/pkg/error/error.go
  • rest-api/api/pkg/api/handler/util/common/common_test.go
  • rest-api/api/pkg/api/handler/util/common/common.go
  • rest-api/db/pkg/db/model/instance_test.go
  • rest-api/api/pkg/api/model/instance_test.go
  • rest-api/workflow/pkg/activity/instance/instance.go
  • rest-api/db/pkg/db/model/interface.go
  • rest-api/api/pkg/api/handler/instancebatch_test.go
  • rest-api/api/pkg/api/model/interface.go
  • rest-api/api/pkg/api/model/instance.go
  • rest-api/db/pkg/db/model/interface_test.go
  • rest-api/openapi/spec.yaml
  • rest-api/api/pkg/api/model/interface_test.go
  • rest-api/api/pkg/api/handler/instance_test.go
  • rest-api/api/pkg/api/handler/instance.go
  • rest-api/api/pkg/api/handler/instancebatch.go

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.

feat: auto-select VPC Prefix during instance/interface creation for FNN VPCs

1 participant