Skip to content

refactor: Migrate IP Block API handlers to use WithTx transaction helper#474

Merged
chet merged 2 commits into
NVIDIA:mainfrom
chet:with-tx-ipblock
May 6, 2026
Merged

refactor: Migrate IP Block API handlers to use WithTx transaction helper#474
chet merged 2 commits into
NVIDIA:mainfrom
chet:with-tx-ipblock

Conversation

@chet
Copy link
Copy Markdown
Contributor

@chet chet commented May 4, 2026

Description

Apply WithTx (from #462) to the Create/Update/Delete ipblock handlers, where:

  • Create uses WithTx with closure-captured ipb/ssd vars (since the returned tuple includes a StatusDetail alongside the IPBlock).
  • Update uses WithTxResult returning the IPBlock with closure-captured status details.
  • Delete uses WithTx for the IPBlock row delete plus IPAM entry cleanup.

Keeping these PRs smaller and tightly scoped so they're:

  • In theory a little easier to read.
  • More tightly scoped/less "blast radius" per PR.
  • A little nicer on/for @coderabbitai. 😆

Signed-off-by: Chet Nichols III chetn@nvidia.com

Type of Change

  • Feature - New feature or functionality (feat:)
  • Fix - Bug fixes (fix:)
  • Chore - Modification or removal of existing functionality (chore:)
  • Refactor - Refactoring of existing functionality (refactor:)
  • Docs - Changes in documentation or OpenAPI schema (docs:)
  • CI - Changes in GitHub workflows. Requires additional scrutiny (ci:)
  • Version - Issuing a new release version (version:)

Services Affected

  • API - API models or endpoints updated
  • Workflow - Workflow service updated
  • DB - DB DAOs or migrations updated
  • Site Manager - Site Manager updated
  • Cert Manager - Cert Manager updated
  • Site Agent - Site Agent updated
  • RLA - RLA service updated
  • Powershelf Manager - Powershelf Manager updated
  • NVSwitch Manager - NVSwitch Manager updated

Related Issues (Optional)

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

@chet chet requested a review from a team as a code owner May 4, 2026 04:14
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2a5b88e0-c4db-4a1f-8caa-3bec18dadf0f

📥 Commits

Reviewing files that changed from the base of the PR and between af3bef3 and e831dab.

📒 Files selected for processing (1)
  • api/pkg/api/handler/ipblock.go

Summary by CodeRabbit

  • Refactor
    • Improved internal transaction handling mechanisms for IP block operations to enhance code maintainability and error handling consistency.

Walkthrough

Refactors IPBlock handlers to use higher-level transaction helpers (cdb.WithTx, cdb.WithTxResult) instead of manual BeginTx/Commit/rollback. Consolidates IPAM and DB operations into transactional closures for Create, Update, and Delete. Removes unused database/sql import.

Changes

Transaction Management Abstraction

Layer / File(s) Summary
Import Cleanup
api/pkg/api/handler/ipblock.go
Removed database/sql import after eliminating direct use of sql.TxOptions.
Create Handler Transaction Refactoring
api/pkg/api/handler/ipblock.go (lines 196–247)
CreateIPBlockHandler.Handle moved from manual BeginTx/Commit/rollback to cdb.WithTx; IPAM prefix creation, IPBlock DB insert, and status-detail insert are executed inside the transaction; errors returned as transaction-scoped API errors and handled via common.HandleTxError.
Update Handler Transaction Refactoring
api/pkg/api/handler/ipblock.go (lines 1008–1035)
UpdateIPBlockHandler.Handle now uses cdb.WithTxResult to perform ipbDAO.Update and to query status-details within the same transaction, returning the updated IPBlock or a transaction error handled by common.HandleTxError.
Delete Handler Transaction Refactoring
api/pkg/api/handler/ipblock.go (lines 1156–1173)
DeleteIPBlockHandler.Handle uses cdb.WithTx to delete the IPBlock DB record and the corresponding IPAM entry inside one transaction; transactional errors are converted to API errors and propagated via common.HandleTxError.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: migrating IP Block API handlers from manual transaction management to the WithTx helper pattern.
Description check ✅ Passed The description is directly related to the changeset, providing specific context about applying WithTx to Create/Update/Delete handlers and referencing the supporting PR #462.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@chet chet changed the title refactor: migrate ipblock handler to WithTx refactor: Migrate ipblock handler to WithTx May 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

🔐 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-05-04 04:15:57 UTC | Commit: af3bef3

@chet chet changed the title refactor: Migrate ipblock handler to WithTx refactor: Migrate ipblock handlers to WithTx May 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
nico-nsm 64 2 20 33 9 0
nico-psm 56 4 29 13 2 8
nico-rest-api 57 4 30 13 2 8
nico-rest-cert-manager 54 4 28 13 1 8
nico-rest-db 55 4 28 13 2 8
nico-rest-site-agent 54 4 28 13 1 8
nico-rest-site-manager 54 4 28 13 1 8
nico-rest-workflow 56 4 29 13 2 8
nico-rla 55 4 28 13 2 8
TOTAL 505 34 248 137 22 64

Per-CVE detail lives in the per-service grype-* artifacts (JSON + SARIF). Severity counts only — no CVE IDs published here.

@thossain-nv thossain-nv changed the title refactor: Migrate ipblock handlers to WithTx refactor: Migrate IP Block API handlers to use WithTx transaction helper May 6, 2026
Copy link
Copy Markdown
Contributor

@thossain-nv thossain-nv left a comment

Choose a reason for hiding this comment

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

Looks good, thank you @chet

Apply `WithTx` (from NVIDIA#462) to the Create/Update/Delete `ipblock` handlers, where:
- Create uses `WithTx` with closure-captured `ipb`/`ssd` vars (since the returned tuple includes a `StatusDetail` alongside the `IPBlock`).
- Update uses `WithTxResult` returning the `IPBlock` with closure-captured status details.
- Delete uses `WithTx` for the `IPBlock` row delete plus IPAM entry cleanup.

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet chet force-pushed the with-tx-ipblock branch from af3bef3 to e831dab Compare May 6, 2026 17:35
@chet chet merged commit 7da45c1 into NVIDIA:main May 6, 2026
53 checks passed
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