fix: address a name collision risk in the MCS handling logic - #397
Conversation
Signed-off-by: michaelawyu <chenyu1@microsoft.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #397 +/- ##
==========================================
- Coverage 67.11% 67.11% -0.01%
==========================================
Files 33 34 +1
Lines 3783 3859 +76
==========================================
+ Hits 2539 2590 +51
- Misses 1070 1089 +19
- Partials 174 180 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds collision-resistant derived Service naming while preserving compatibility with existing MCS resources.
Changes:
- Adds hash-suffixed derived Service names.
- Verifies ownership before updating or deleting Services.
- Adds unit and integration coverage for collision handling and migration.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pkg/controllers/multiclusterservice/uniquename.go |
Generates hash-suffixed Service names. |
pkg/controllers/multiclusterservice/uniquename_test.go |
Tests naming and truncation. |
pkg/controllers/multiclusterservice/controller.go |
Adds ownership checks and migration handling. |
pkg/controllers/multiclusterservice/controller_test.go |
Updates controller unit tests for new names. |
pkg/controllers/multiclusterservice/controller_integration_test.go |
Tests new, legacy, and colliding MCS scenarios. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: michaelawyu <chenyu1@microsoft.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
pkg/controllers/multiclusterservice/uniquename_test.go:112
- These assertions accept any 12-character hex suffix, so they do not test that the suffix is actually keyed by MCS identity—the behavior that prevents this PR's collision. A constant suffix would pass every case. Add paired assertions that
team-a/serviceandteam/a-servicediffer, that distinct UIDs for the same namespace/name differ, and that identical inputs remain deterministic.
wantPattern := "^" + regexp.QuoteMeta(tc.wantPrefix) + "-[0-9a-f]{12}$"
matched, err := regexp.MatchString(wantPattern, got.Name)
if err != nil {
t.Fatalf("failed to match pattern %q: %v", wantPattern, err)
}
if !matched {
t.Fatalf("uniqueDerivedServiceName() = %q, want match %q", got.Name, wantPattern)
pkg/controllers/multiclusterservice/controller.go:446
- Treating a Service with no owner-namespace label as orphaned authorizes the subsequent
CreateOrUpdateto adopt and rewrite it. A mutable MCS derived-service label can therefore target an unrelated unlabeled fleet-system Service and change its ports, type, and labels. Missing either owner label means ownership is unproven; handle it as an unmanaged/colliding Service and assign the MCS a different derived name instead of overwriting it.
case !foundOwnerNS:
// The owner information is missing, this normally wouldn't happen, as the derived service is created in one go
// with the owner information set as labels. Still, the controller handles this by letting the following createOrUpdate
// step to overwrite the derived service with the correct owner information.
return derivedSvcOwnerVeriResOrphaned, nil
What type of PR is this?
/bug
What this PR does / why we need it:
This PR fixes a name collision situation that might lead to two MCS constantly overwriting the same derived service.
Which issue(s) this PR fixes:
N/A
Requirements:
make reviewablefor basic local testHow has this code been tested
Special notes for your reviewer
N/A