Skip to content

refactor(rest-api): Use our generic cdb.GetPtr instead of per-type GetXPtr helpers#2171

Merged
chet merged 1 commit into
NVIDIA:mainfrom
chet:rest-use-get-ptr
Jun 3, 2026
Merged

refactor(rest-api): Use our generic cdb.GetPtr instead of per-type GetXPtr helpers#2171
chet merged 1 commit into
NVIDIA:mainfrom
chet:rest-use-get-ptr

Conversation

@chet

@chet chet commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Description

@bcavnvidia pointed out that after cdb.Ptr got introduced as a generic helper in NVIDIA/infra-controller-rest#569 (which I probably should have just named cdb.GetPtr), we could actually get rid of all of our type-specific helpers and just lean on this across the board.

To summarize:

  • cutil.GetPtr (in common/pkg/util) is now the one helper for any value type (renamed from cdb.Ptr and moved out of db/pkg/db -- thanks to @thossain-nv for that suggestion).
  • The per-type helpers (GetStrPtr, GetIntPtr, GetBoolPtr, GetUUIDPtr, GetTimePtr) go away.

But, cdb.GetTypedStrPtr stays, because it converts a typed-string value (e.g. MachineCapabilityType) to *string, which GetPtr can't do generically (i.e. it'd return *MachineCapabilityType).

Per-type tests collapsed into a single TestGetPtr with type subtests, alongside its converter tests.

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

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.)

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 June 3, 2026 21:27
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. 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: 04800eea-6585-4d48-b6f9-7be7e41e0f38

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:

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

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

@github-actions

github-actions Bot commented Jun 3, 2026

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-06-03 21:29:30 UTC | Commit: 5958b51

@chet

chet commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Hey @coderabbitai! There's a .coderabbit.yaml in rest-api/ for you to use (or maybe it's in the repo root now)? Care to take a peek? You helped provide guidance for some of the original work around cbd.GetPtr (what was cbd.Ptr) based on the original PR I did to introduce it, so I think you should be pleased with this iterative effort around it. Thank you!

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for .coderabbit.yaml in rest-api/ and repo root
echo "=== rest-api/.coderabbit.yaml ==="
cat rest-api/.coderabbit.yaml 2>/dev/null || echo "(not found)"

echo ""
echo "=== .coderabbit.yaml (root) ==="
cat .coderabbit.yaml 2>/dev/null || echo "(not found)"

echo ""
echo "=== rest-api/AGENTS.md ==="
cat rest-api/AGENTS.md 2>/dev/null || echo "(not found)"

Length of output: 30783


🏁 Script executed:

#!/bin/bash
# Fetch the PR diff for `#2171`
gh pr view 2171 --json title,body,files 2>/dev/null | jq '.'
gh pr diff 2171 2>/dev/null | head -500

Length of output: 56820



@chet — good to hear from you, and thank you for the kind words. I have reviewed the .coderabbit.yaml (it is at the repo root rather than rest-api/; I will update my notes accordingly), rest-api/AGENTS.md, and the PR diff.

Configuration

The root .coderabbit.yaml is well-structured:

  • auto_review: enabled: false means I will only engage when explicitly invoked — the model that suits a repo of this scale.
  • Path instructions are correctly scoped: Go, Proto, OpenAPI, shell, Markdown, and the auto-generated sdk/standard carve-out are all accounted for.
  • The knowledge_base.code_guidelines file patterns now pick up AGENTS.md and rest-api/AGENTS.md, which is the right move; the conventions documented there are substantial and I will use them in future reviews.

PR assessment

This is a clean, production-grade refactor. Specific observations:

  1. Uniform generic surface. cdb.GetPtr[T] is a strict improvement: one entry point, zero per-type maintenance, and the Go type system enforces correctness at every call site. The diff is large in file count but trivially mechanical — no logic changes are introduced.

  2. Correct retention of cdb.GetTypedStrPtr. This is the right call. GetPtr on a MachineCapabilityType would yield *MachineCapabilityType, not *string. Per the AGENTS.md named-types convention, the typed-string enum owns its conversion behavior; GetTypedStrPtr is the narrow bridge from that domain type to a wire *string. Collapsing it into the generic would violate that boundary.

  3. Test consolidation. Collapsing per-type TestGetXPtr functions into a single TestGetPtr with typed subtests is idiomatic Go test structure. It reduces boilerplate while keeping coverage parity.

  4. db.GetPtr(0) at expectedTotal. This uses a different package alias (db) than the rest of the file (cdb). Assuming both resolve to the same function post-rename, this is a non-issue — but worth confirming that the db alias is intentional and not a stale import alias from before the rename.

No blocking concerns. The API is simpler, the intent is clearer, and the AGENTS.md conventions are respected throughout. Well done to you and @bcavnvidia for the follow-through.

🐇 ✨


✏️ Learnings added
Learnt from: chet
URL: https://github.com/NVIDIA/infra-controller/pull/2171

Timestamp: 2026-06-03T21:30:56.488Z
Learning: In the NVIDIA/infra-controller repository, the `.coderabbit.yaml` configuration file is located at the **repo root** (not at `rest-api/.coderabbit.yaml`). The `rest-api/AGENTS.md` file contains detailed coding conventions for the Go codebase and should be consulted for reviews involving `rest-api/` code. `auto_review` is disabled (`enabled: false`), so CodeRabbit reviews are triggered only on explicit invocation.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: chet
Repo: NVIDIA/infra-controller PR: 0
File: :0-0
Timestamp: 2026-06-02T19:13:04.224Z
Learning: For the NVIDIA/infra-controller repository, review guidance for rest-api changes is available in `rest-api/.coderabbit.yaml` and `rest-api/AGENTS.md`; future reviews involving `rest-api` code should consult those files.

Learnt from: chet
Repo: NVIDIA/infra-controller PR: 0
File: :0-0
Timestamp: 2026-06-02T19:06:09.917Z
Learning: In `infra-controller-rest` (Go), named types own their proto behavior — `map`, `slice`, or other primitive composites representing domain concepts get named types with methods, not free functions. Examples: `db/pkg/db/model.Labels` (`type Labels map[string]string` with `ToProto`/`FromProto`), `MachineCapabilityType`/`MachineCapabilityDeviceType` (`type X string` with typed proto enum round-trip). Free functions like `LabelsToProto(m map[string]string)` are an anti-pattern.

@thossain-nv

Copy link
Copy Markdown
Contributor

Hi @chet, we could take this opportunity to move the GetPtr function to https://github.com/NVIDIA/infra-controller/blob/main/rest-api/common/pkg/util/converter.go!

@chet

chet commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @chet, we could take this opportunity to move the GetPtr function to https://github.com/NVIDIA/infra-controller/blob/main/rest-api/common/pkg/util/converter.go!

@thossain-nv Genius!! Moving!

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
nico-flow 66 4 34 18 2 8
nico-nsm 82 2 28 43 9 0
nico-psm 67 4 35 18 2 8
nico-rest-api 100 6 53 30 3 8
nico-rest-cert-manager 65 4 34 18 1 8
nico-rest-db 66 4 34 18 2 8
nico-rest-site-agent 65 4 34 18 1 8
nico-rest-site-manager 65 4 34 18 1 8
nico-rest-workflow 67 4 35 18 2 8
TOTAL 643 36 321 199 23 64

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

@chet chet force-pushed the rest-use-get-ptr branch from 5958b51 to 0fa594b Compare June 3, 2026 21:47
…tXPtr helpers

@bcavnvidia pointed out that after `cdb.Ptr` got introduced as a generic helper in NVIDIA/infra-controller-rest#569 (which I probably should have just named `cdb.GetPtr`), we could actually get rid of all of our type-specific helpers and just lean on this across the board.

To summarize:
- `cutil.GetPtr` (in `common/pkg/util`) is now the one helper for any value type (renamed from `cdb.Ptr` and moved out of `db/pkg/db` -- thanks to @thossain-nv for that suggestion).
- The per-type helpers (`GetStrPtr`, `GetIntPtr`, `GetBoolPtr`, `GetUUIDPtr`, `GetTimePtr`) go away.

But, `cdb.GetTypedStrPtr` stays, because it converts a typed-string value (e.g. `MachineCapabilityType`) to `*string`, which `GetPtr` can't do generically (i.e. it'd return `*MachineCapabilityType`).

Per-type tests collapsed into a single `TestGetPtr` with type subtests, alongside its sibling converter tests.

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet chet force-pushed the rest-use-get-ptr branch from 0fa594b to dcca67e Compare June 3, 2026 21:47
@chet

chet commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @chet, we could take this opportunity to move the GetPtr function to https://github.com/NVIDIA/infra-controller/blob/main/rest-api/common/pkg/util/converter.go!

@thossain-nv Genius!! Moving!

@thossain-nv Done!

@thossain-nv thossain-nv 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.

Thank you for moving it to common!

@chet chet merged commit 8b4188b into NVIDIA:main Jun 3, 2026
89 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