fix(nvca): apply primary-PV selector in model cache cleanup - #441
Conversation
📝 WalkthroughWalkthroughThe primary PV selector now retains its label requirement, and a unit test verifies that it rejects unlabeled objects and matches PVs with the primary label. ChangesPrimary PV selector
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
bec4165 to
2647a51
Compare
labels.Selector.Add returns a new selector and does not mutate the receiver, so the discarded return left primaryPVSel empty. An empty selector matches every object, so the idle model cache cleanup listed every PV in the cluster instead of only model-cache primary PVs. This skewed the model cache backend count metric and made the cleanup loop scan all PVs each tick. Reassign the Add result so the primary-PV requirement is applied, and add a regression test on the selector. Closes NVIDIA#440 Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
2647a51 to
569d778
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/compute-plane-services/nvca/pkg/storage/modelcache_cleanup_test.go (1)
38-46: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a table-driven test for the selector cases.
This test covers multiple scenarios inline. Convert them to table-driven cases so additional selector behaviors can be added consistently.
As per coding guidelines, tests covering multiple scenarios should use table-driven tests.
Proposed refactor
func TestPrimaryPVSelector(t *testing.T) { - assert.False(t, primaryPVSel.Matches(labels.Set{}), - "empty label set must not match; selector should require the primary-PV label") - assert.True(t, primaryPVSel.Matches(labels.Set{primaryPVLabelKey: "true"}), - "a PV carrying the primary-PV label must match") + tests := []struct { + name string + labelSet labels.Set + want bool + }{ + { + name: "empty labels do not match", + labelSet: labels.Set{}, + want: false, + }, + { + name: "primary PV label matches", + labelSet: labels.Set{primaryPVLabelKey: "true"}, + want: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.want, primaryPVSel.Matches(tt.labelSet)) + }) + } }🤖 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 `@src/compute-plane-services/nvca/pkg/storage/modelcache_cleanup_test.go` around lines 38 - 46, Convert TestPrimaryPVSelector into a table-driven test with named cases for the empty label set and a set containing primaryPVLabelKey. Iterate over the cases with subtests, asserting each expected Matches result while preserving the existing failure messages or equivalent scenario-specific diagnostics.Source: Coding guidelines
🤖 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 `@src/compute-plane-services/nvca/pkg/storage/modelcache_cleanup_test.go`:
- Around line 38-46: Convert TestPrimaryPVSelector into a table-driven test with
named cases for the empty label set and a set containing primaryPVLabelKey.
Iterate over the cases with subtests, asserting each expected Matches result
while preserving the existing failure messages or equivalent scenario-specific
diagnostics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: acd7b72b-cd5e-49c7-9244-0ad32ef9b4d7
📒 Files selected for processing (2)
src/compute-plane-services/nvca/pkg/storage/modelcache_cleanup.gosrc/compute-plane-services/nvca/pkg/storage/modelcache_cleanup_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- src/compute-plane-services/nvca/pkg/storage/modelcache_cleanup.go
TL;DR
The model cache cleanup selector was left empty because the result of
labels.Selector.Addwas discarded. An empty selector matches every object, soidle cleanup listed every PV in the cluster instead of only model-cache primary
PVs. This skewed the model cache backend count metric and made the cleanup loop
scan all PVs each tick. Reassign the
Addresult so the requirement applies, plusa regression test.
Issues
Closes #440
Testing
go test ./pkg/storage/...with envtest passes. AddedTestPrimaryPVSelector,which fails before the fix (empty selector matches an empty label set) and passes
after. No QA needed.
Checklist
Summary by CodeRabbit
Bug Fixes
Tests