Skip to content

Add shared library for writing resources across clusters#618

Open
scotwells wants to merge 1 commit into
mainfrom
feat/downstream-client-package
Open

Add shared library for writing resources across clusters#618
scotwells wants to merge 1 commit into
mainfrom
feat/downstream-client-package

Conversation

@scotwells
Copy link
Copy Markdown
Contributor

@scotwells scotwells commented May 18, 2026

What's changing

Adds a new pkg/downstreamclient package that centralises the cross-cluster resource management pattern currently duplicated across services.

Why it matters

Two services already implement this pattern independently:

  • network-services-operator — uses MappedNamespaceResourceStrategy in internal/downstreamclient/ to write network resources into downstream clusters, mapping upstream project namespaces to ns-<uid> namespaces on the target
  • compute — needs the same strategy to federate WorkloadDeployment objects to the Karmada control plane and project Instance objects back to management cluster namespaces

Without a shared library each new service that does cross-cluster writes copies the same code, with the risk of the namespace-mapping convention, anchor ConfigMap pattern, and upstream-owner labels drifting out of sync.

What's included

The pkg/downstreamclient package (moved and exported from NSO's internal package) handles:

  • Namespace mapping — resolves upstream namespace → ns-<uid> on the downstream cluster
  • Anchor ConfigMaps — tracks cross-cluster ownership so downstream resources are garbage-collected when the upstream owner is deleted
  • Upstream-owner labels — consistent meta.datumapis.com/* labels so resources can always be traced back to their origin cluster, namespace, group, and kind
  • TypedEnqueueRequestsForUpstreamOwner — generic controller-runtime handler that re-enqueues the upstream owner when a downstream resource changes

What's not changing

No existing behaviour changes. NSO's internal copy is unaffected until it chooses to migrate to this package. This PR is purely additive.

Consumers

Once tagged, the following services will import this package:

  • go.datum.net/network-services-operator — migrate away from internal/downstreamclient/
  • go.datum.net/compute — use MappedNamespaceResourceStrategy in the Karmada federation path

Promotes the MappedNamespaceResourceStrategy pattern from
network-services-operator into a shared platform library so any
service can write resources to a downstream cluster without
duplicating the namespace-mapping and ownership-tracking logic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@scotwells scotwells marked this pull request as ready for review May 18, 2026 19:04
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.

2 participants