Skip to content

fix: restrict hub reconciliation to member reserved namespaces - #466

Open
Chen Yu (michaelawyu) wants to merge 1 commit into
Azure:mainfrom
michaelawyu:fix/restrict-internal-api-object-reconciliation
Open

Chen Yu (michaelawyu) wants to merge 1 commit into
Azure:mainfrom
michaelawyu:fix/restrict-internal-api-object-reconciliation

Conversation

@michaelawyu

@michaelawyu Chen Yu (michaelawyu) commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

/kind bug

What this PR does / why we need it:

Member agents only write EndpointSliceExports, InternalServiceExports and InternalServiceImports to their reserved hub namespaces (fleet-member-*). Hub controllers previously reconciled these objects in any namespace. An object created elsewhere could:

  • claim a ServiceImport for an arbitrary namespace, causing EndpointSliceImports to be written there and blocking the real import;
  • add its cluster ID to ServiceImport status, set the resolved ports, or mark real exports as conflicted. The ServiceImport controller only checks for a finalizer, which a creator can set;
  • replace a member's Traffic Manager endpoint target, because the TrafficManagerBackend controller looks up exports by cluster ID through the field index.

This PR:

  • adds objectmeta.IsMemberReservedNamespace and objectmeta.MemberReservedNamespacePredicate, based on a new hubconfig.HubNamespacePrefix. HubNamespaceNameFormat is now built from that prefix;
  • adds the predicate to the For watch of the hub EndpointSliceExport, InternalServiceExport and InternalServiceImport controllers. The ServiceImport map functions apply the same filter;
  • excludes InternalServiceExports outside reserved namespaces from the field index shared by the ServiceImport and TrafficManagerBackend controllers;
  • moves the Gateway API E2E synthetic exports into test-owned reserved namespaces. They can't go in a real member's namespace, because the member agent deletes exports there that have no matching ServiceExport;
  • updates integration fixtures to use fleet-member-* namespaces.

Which issue(s) this PR fixes:

Fixes # N/A (no tracking issue)

Requirements:

How has this code been tested

  • go build ./...: passed

  • go vet ./pkg/common/... ./pkg/controllers/hub/...: passed

  • go vet -tags e2e ./test/e2e/...: passed

  • KUBEBUILDER_ASSETS="$(hack/tools/bin/setup-envtest-release-0.22 use 1.35.0 -p path)" CGO_ENABLED=1 go test -race -count=1 ./pkg/common/objectmeta ./pkg/common/hubconfig ./pkg/controllers/hub/endpointsliceexport ./pkg/controllers/hub/internalserviceexport ./pkg/controllers/hub/internalserviceimport ./pkg/controllers/hub/serviceimport ./pkg/controllers/hub/trafficmanagerbackend ./pkg/controllers/hub/gatewayresolver: passed

  • GOTOOLCHAIN=go1.26.10 make lint: passed. The toolchain is pinned so golangci-lint is built with the same Go version as CI.

  • New regression tests:

    • one integration spec each for EndpointSliceExport, InternalServiceExport and InternalServiceImport objects outside reserved namespaces;
    • a ServiceImport spec with an export outside reserved namespaces that has its finalizer set at creation;
    • a TrafficManagerBackend index unit test.

    With IsMemberReservedNamespace temporarily forced to return true, all of these failed.

  • Not run: make reviewable (lint, vet and goimports were run individually) and Azure E2E, including the updated Gateway API E2E test.

Special notes for your reviewer

  • The predicates are on For rather than WithEventFilter. WithEventFilter would also drop ServiceImport events, which come from application namespaces.
  • The check matches the fleet-member- prefix only. It doesn't require the namespace to equal fleet-member-<ClusterID>.
  • Objects that already exist outside reserved namespaces and carry a hub finalizer won't be cleaned up after upgrade. Member-created objects aren't affected.
  • Not covered here: an export outside reserved namespaces can still make the gateway resolver report ConflictingExports, and the TrafficManagerBackend export watch still queues reconciles for such exports. Neither can change the resolved backends or the Traffic Manager endpoints.

Member agents only write EndpointSliceExports, InternalServiceExports and
InternalServiceImports to their reserved hub namespaces (fleet-member-*).
Hub controllers previously reconciled these objects in any namespace, so an
object created elsewhere could claim a ServiceImport, distribute endpoints to
arbitrary namespaces, add clusters to ServiceImport status, or replace a
member's Traffic Manager endpoint target.

- Add objectmeta.IsMemberReservedNamespace and
  objectmeta.MemberReservedNamespacePredicate, based on the new
  hubconfig.HubNamespacePrefix.
- Filter the primary watches and ServiceImport map functions of the hub
  EndpointSliceExport, InternalServiceExport and InternalServiceImport
  controllers.
- Exclude InternalServiceExports outside reserved namespaces from the field
  index shared by the ServiceImport and TrafficManagerBackend controllers.
- Move the Gateway API E2E synthetic exports into test-owned reserved
  namespaces.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: michaelawyu <chenyu1@microsoft.com>
@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.52%. Comparing base (fcf98eb) to head (7e9ff62).

Files with missing lines Patch % Lines
pkg/common/objectmeta/objectmeta.go 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #466      +/-   ##
==========================================
+ Coverage   76.32%   76.52%   +0.20%     
==========================================
  Files          77       77              
  Lines        7669     7681      +12     
==========================================
+ Hits         5853     5878      +25     
+ Misses       1402     1392      -10     
+ Partials      414      411       -3     

☔ 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.

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.

1 participant