Skip to content

fix(mat-k8s-ctrl): cache mat api clients and propagate delete errors - #4646

Merged
akorobkov-nvda merged 1 commit into
NVIDIA:mainfrom
akorobkov-nvda:fix/mat-k8s-controller-reconcile
Aug 6, 2026
Merged

fix(mat-k8s-ctrl): cache mat api clients and propagate delete errors#4646
akorobkov-nvda merged 1 commit into
NVIDIA:mainfrom
akorobkov-nvda:fix/mat-k8s-controller-reconcile

Conversation

@akorobkov-nvda

Copy link
Copy Markdown
Contributor

Addresses three issues from PR #3955 review:

  1. Client caching - Reconciler caches MAT API clients by URL, creating new clients only on cache miss. Stale entries are evicted and closed when URLs disappear from discovery, including when all instances disappear.
  2. Delete error propagation - Delete failures are now appended toReconcileResult.Errors instead of only being logged.
  3. Deployment documentation - Added comments to Helm values.yaml explaining production deployments must override the default image repository/tag.

Related issues

Fixes #4410

Type of Change

  • Fix - Bug fixes

Testing

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

Test Results

ok  .../pkg/controller   0.702s  (22 tests)
ok  .../pkg/matclient    0.904s  (5 tests)

@akorobkov-nvda akorobkov-nvda self-assigned this Aug 6, 2026
@akorobkov-nvda
akorobkov-nvda requested review from a team as code owners August 6, 2026 03:33
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Improved controller performance by reusing status connections across reconciliations.
    • Automatically closes connections that are no longer needed.
    • Reports errors encountered while processing resource deletions.
    • Added support for safely closing API clients.
  • Documentation

    • Expanded deployment configuration guidance, including container image overrides and Helm installation examples.

Walkthrough

The controller now caches status fetchers by discovered URL, closes stale clients, and reports concurrent deletion errors. Tests cover reuse, eviction, cleanup, and error propagation. Helm values now document production image overrides.

Changes

Controller reconciliation

Layer / File(s) Summary
Status-fetcher cache lifecycle
dev/k8s/machine-a-tron-controller/pkg/controller/controller.go, dev/k8s/machine-a-tron-controller/pkg/controller/controller_test.go, dev/k8s/machine-a-tron-controller/pkg/matclient/client.go, dev/k8s/machine-a-tron-controller/pkg/matclient/client_test.go
Reconciler caches fetchers by URL and reuses them across reconciliations. It evicts undiscovered URLs and closes fetchers that implement Closeable. Tests cover reuse, eviction, empty discovery, and idempotent client closure.
Concurrent deletion error reporting
dev/k8s/machine-a-tron-controller/pkg/controller/controller.go, dev/k8s/machine-a-tron-controller/pkg/controller/controller_test.go
Concurrent deletion processing appends wrapped deletion errors to ReconcileResult.Errors under a mutex. Tests verify failed deletions are not counted as successful.
Production image override documentation
helm/charts/nico-machine-a-tron/charts/mat-k8s-controller/values.yaml
The values file documents repository and tag overrides for production installations, with Helm command and values-file examples.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Discovery
  participant Reconciler
  participant StatusFetcher
  participant ReconcileResult

  Discovery->>Reconciler: Return discovered instance URLs
  Reconciler->>Reconciler: Get or create fetcher by URL
  Reconciler->>StatusFetcher: Fetch machine status
  Reconciler->>Reconciler: Evict absent URLs
  Reconciler->>StatusFetcher: Close stale fetcher
  Reconciler->>ReconcileResult: Append concurrent deletion errors
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the two primary code changes: MAT API client caching and delete error propagation.
Description check ✅ Passed The description directly explains the caching, error propagation, documentation, linked issue, and test coverage changes.
Linked Issues check ✅ Passed The changes address all objectives in issue #4410: client caching, stale-client cleanup, delete error propagation, and deployment documentation.
Out of Scope Changes check ✅ Passed All changes are limited to the requested controller fixes, related tests, client cleanup support, and Helm deployment documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
dev/k8s/machine-a-tron-controller/pkg/controller/controller_test.go (1)

1006-1025: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise concurrent deletion failures.

This test uses one worker and one failing delete. It does not verify concurrent access to result.Errors. Use at least two failing names with concurrency: 2. Assert that Deleted remains zero and that result.Errors contains both errors without assuming an order.

🤖 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 `@dev/k8s/machine-a-tron-controller/pkg/controller/controller_test.go` around
lines 1006 - 1025, The test TestProcessDeletesConcurrently_PropagatesErrors
should exercise concurrent failures by configuring concurrency to 2 and
providing at least two service names that both fail deletion. Assert Deleted
remains zero, then verify result.Errors contains both service-specific errors
without relying on their ordering.
🤖 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 `@helm/charts/nico-machine-a-tron/charts/mat-k8s-controller/values.yaml`:
- Around line 11-12: Update the comments above the default image repository in
the values configuration to remove the claim that a missing registry prefix will
prevent resolution, and describe the repository as a placeholder that production
deployments must override instead. Preserve the existing production override
requirement while avoiding environment-specific assumptions.

---

Nitpick comments:
In `@dev/k8s/machine-a-tron-controller/pkg/controller/controller_test.go`:
- Around line 1006-1025: The test
TestProcessDeletesConcurrently_PropagatesErrors should exercise concurrent
failures by configuring concurrency to 2 and providing at least two service
names that both fail deletion. Assert Deleted remains zero, then verify
result.Errors contains both service-specific errors without relying on their
ordering.
🪄 Autofix

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: 11b09893-a71a-433d-9aa9-6fb683c6bb34

📥 Commits

Reviewing files that changed from the base of the PR and between 4f0e11f and 0caa128.

📒 Files selected for processing (5)
  • dev/k8s/machine-a-tron-controller/pkg/controller/controller.go
  • dev/k8s/machine-a-tron-controller/pkg/controller/controller_test.go
  • dev/k8s/machine-a-tron-controller/pkg/matclient/client.go
  • dev/k8s/machine-a-tron-controller/pkg/matclient/client_test.go
  • helm/charts/nico-machine-a-tron/charts/mat-k8s-controller/values.yaml

@shayan1995 shayan1995 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.

Two small nits, otherwise this is clean — the caching strategy, eviction ordering, and delete error propagation are all correct. Happy to merge once these are addressed.

Nit 1: Replace the custom Closeable interface with io.Closer from the standard library — they have the identical signature (Close() error) and io.Closer is the established Go convention for this contract.

Nit 2: The Close() error on eviction is silently discarded with _ = c.Close(). Since the interface allows failure, a logger.Warn() here would make production debugging easier if a transport ever does return an error on close.

@akorobkov-nvda
akorobkov-nvda merged commit b486e2a into NVIDIA:main Aug 6, 2026
64 checks passed
@akorobkov-nvda
akorobkov-nvda deleted the fix/mat-k8s-controller-reconcile branch August 6, 2026 19:52
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.

bug: mat-k8s-controller reconciliation behavior and deployment docs

3 participants