fix(mat-k8s-ctrl): cache mat api clients and propagate delete errors - #4646
Conversation
Summary by CodeRabbit
WalkthroughThe 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. ChangesController reconciliation
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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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 winExercise 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 withconcurrency: 2. Assert thatDeletedremains zero and thatresult.Errorscontains 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
📒 Files selected for processing (5)
dev/k8s/machine-a-tron-controller/pkg/controller/controller.godev/k8s/machine-a-tron-controller/pkg/controller/controller_test.godev/k8s/machine-a-tron-controller/pkg/matclient/client.godev/k8s/machine-a-tron-controller/pkg/matclient/client_test.gohelm/charts/nico-machine-a-tron/charts/mat-k8s-controller/values.yaml
shayan1995
left a comment
There was a problem hiding this comment.
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.
Addresses three issues from PR #3955 review:
ReconcileResult.Errorsinstead of only being logged.Related issues
Fixes #4410
Type of Change
Testing
Test Results