Skip to content

fix: address a name collision risk in the MCS handling logic - #397

Merged
Chen Yu (michaelawyu) merged 2 commits into
Azure:mainfrom
michaelawyu:fix/name-collision
Aug 26, 2026
Merged

fix: address a name collision risk in the MCS handling logic#397
Chen Yu (michaelawyu) merged 2 commits into
Azure:mainfrom
michaelawyu:fix/name-collision

Conversation

@michaelawyu

Copy link
Copy Markdown
Collaborator

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:

How has this code been tested

  • UTs
  • ITs

Special notes for your reviewer

N/A

Signed-off-by: michaelawyu <chenyu1@microsoft.com>
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.78652% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.11%. Comparing base (556170b) to head (d2f3fe6).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pkg/controllers/multiclusterservice/controller.go 64.51% 17 Missing and 5 partials ⚠️
pkg/controllers/multiclusterservice/uniquename.go 85.18% 2 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/controllers/multiclusterservice/uniquename.go
Signed-off-by: michaelawyu <chenyu1@microsoft.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/service and team/a-service differ, 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 CreateOrUpdate to 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

Comment thread pkg/controllers/multiclusterservice/controller.go
@michaelawyu
Chen Yu (michaelawyu) merged commit dcc84ec into Azure:main Aug 26, 2026
10 checks passed
@michaelawyu
Chen Yu (michaelawyu) deleted the fix/name-collision branch August 26, 2026 23:57
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.

3 participants