Skip to content

Add namespaced isolation mode for cluster-scoped objects#394

Merged
xrstf merged 7 commits into
kbind-dev:mainfrom
xrstf:cluster-isolation
Nov 26, 2025
Merged

Add namespaced isolation mode for cluster-scoped objects#394
xrstf merged 7 commits into
kbind-dev:mainfrom
xrstf:cluster-isolation

Conversation

@xrstf

@xrstf xrstf commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR implements two new scoping methods for cluster-scoped objects:

  • none doesn't change anything about the name of a consumer-side object when it's synced to the provider. This comes with all the obvious pitfalls.
  • namespaced transforms a cluster-scoped object into a namespaced one, putting it into the cluster namespace (kube-bind-abc123).

However to accomplish this, I had to refactor the entire approach to how object scoping is handled in the spec/status controllers.

Originally, kube-bind was written for only namespaced objects and everything was easy. Then we added basic support for cluster-scoped objects by prepending them with a prefix. This change however was yanked into the controllers with a crowbar. For example, the function to create the copy of an object on the provider cluster (createProviderObject) suddenly was transforming the given object into something else, then applies it, then un-transforms it again before returning it. From what I can see in the codebase, there is never even a reason to undo any transformations being done. Once createProviderObject is called, we're done processing the object. Why have all the code for reverting changes? Likewise, injecting and changing namespaces was also done in the small functional wrappers (like createProviderObject, updateProviderObject) which were never meant to contain business logic, but exist (as far as I can tell) to ease unit testing and to make the reconcilers "more functional" (i.e. instead of giving them loads of small details, just give them the few pieces of behaviour they rely on). createProviderObject should IMHO not have anything to do with how the objects are changed during transit.

Now that new isolation modes have been added, the old approach would not have scaled anyway and so I introduced the concept of "isolation strategies". At first I had three (prefixed (the old), namespaced, none), but then when I looked through the spec/status controllers event handlers, a lot of them also contained magic to undo/unmap cluster-scoped objects. So that logic was also moved into the isolation strategies.

However this was ugly with code basically being

if namespaced {
   lots of code
   yadda yadda
   APIServiceNamespace handling
   requeueing...
} else {
   isolationStrategy.DoStuff(obj)
}

Since the entire APIServiceNamespace handling is exclusive to how namespaced objects are handled, I was trying to avoid having it remain in the controllers and so I decided that a fourth isolation strategy makes the most sense:

  • ServiceNamespaced is the strategy for natively namespaced (on both sides) objects.
  • Prefixed is the old cluster-scoped behaviour.
  • Namespaced is one of the new cluster-scoped behaviours.
  • None is one of the new cluster-scoped behaviours.

In the CRD however we only expose the latter three, since we always use the ServiceNamespaced strategy for namespaced objects [at the moment...].

The only thing that remained as part of the controller logic was applying the ClusterNamespaceAnnotation, since it applies to every object no matter what strategy and can easily be done transparently to the isolation strategies. And since this annotation is always present, I awarded it its own dedicated types package in the konnector to make it independent of the controllers/ packages.

Warning: Due to the nature of this feature, the namespaced isolation requires a namespaced CRD on the provider side. (and a cluster-scoped CRD on the consumer side). Since the backend currently only has 1 global CLI flag to control isolation and can otherwise just look at the existing CRDs on the provider cluster, the backend cannot distinguish between namespaced CRDs that are meant to stay namespaced, and those that are meant to be translated into cluster-scoped CRDs.

This means that if you run your backend with --cluster-scoped-isolation=namespaced, ALL NAMESPACED CRDs ON THE PROVIDER CLUSTER WILL BECOME CLUSTER-SCOPED CRDs. Currently you would need to run two separate backends if you want to offer Services that make use of this translation, and those where you want to have natively namespaced CRDs on both sides (consumer and provider).

This limitation only affects this new isolation mode, since it's the only one that has differnt scoping on different clusters.

What Type of PR Is This?

/kind feature

Related Issue(s)

Fixes #307

Release Notes

Implement support for `Namespaced` and `None` cluster isolation strategies when dealing with cluster-scoped objects.

@xrstf

xrstf commented Nov 20, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai

@coderabbitai

coderabbitai Bot commented Nov 20, 2025

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@xrstf: Hello! How can I assist you with this pull request?


🧠 Learnings used
Learnt from: mjudeikis
Repo: kube-bind/kube-bind PR: 351
File: contrib/kcp/test/e2e/binding.go:49-56
Timestamp: 2025-11-04T11:51:36.024Z
Learning: In kube-bind e2e tests (contrib/kcp/test/e2e/), workspace-level isolation prevents conflicts between test runs, making it safe to use hardcoded resource names like "test-binding" without risk of concurrent test collisions.

@xrstf

xrstf commented Nov 20, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review this please

@coderabbitai

coderabbitai Bot commented Nov 20, 2025

Copy link
Copy Markdown

@xrstf: I will review the changes in this pull request.


🧠 Learnings used
Learnt from: mjudeikis
Repo: kube-bind/kube-bind PR: 351
File: contrib/kcp/test/e2e/binding.go:49-56
Timestamp: 2025-11-04T11:51:36.024Z
Learning: In kube-bind e2e tests (contrib/kcp/test/e2e/), workspace-level isolation prevents conflicts between test runs, making it safe to use hardcoded resource names like "test-binding" without risk of concurrent test collisions.
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 20, 2025
@xrstf xrstf marked this pull request as ready for review November 20, 2025 18:58
@xrstf xrstf requested a review from a team as a code owner November 20, 2025 18:58
@xrstf xrstf changed the title Add namespaced isolation mode for cluster-scoped objects WIP: Add namespaced isolation mode for cluster-scoped objects Nov 20, 2025
…ced' and 'none' strategies

On-behalf-of: @SAP christoph.mewes@sap.com
@xrstf xrstf force-pushed the cluster-isolation branch from 0922334 to 8989855 Compare November 20, 2025 18:59
@xrstf

xrstf commented Nov 20, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review!

@coderabbitai

coderabbitai Bot commented Nov 20, 2025

Copy link
Copy Markdown

@xrstf: I will review the changes in this pull request.


🧠 Learnings used
Learnt from: mjudeikis
Repo: kube-bind/kube-bind PR: 351
File: contrib/kcp/test/e2e/binding.go:49-56
Timestamp: 2025-11-04T11:51:36.024Z
Learning: In kube-bind e2e tests (contrib/kcp/test/e2e/), workspace-level isolation prevents conflicts between test runs, making it safe to use hardcoded resource names like "test-binding" without risk of concurrent test collisions.
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ntnn

ntnn commented Nov 21, 2025

Copy link
Copy Markdown
Member

@coderabbitai full-review

@coderabbitai

coderabbitai Bot commented Nov 21, 2025

Copy link
Copy Markdown

@ntnn: I will perform a full review of all the changes in this pull request.


🧠 Learnings used
Learnt from: mjudeikis
Repo: kube-bind/kube-bind PR: 351
File: contrib/kcp/test/e2e/binding.go:49-56
Timestamp: 2025-11-04T11:51:36.024Z
Learning: In kube-bind e2e tests (contrib/kcp/test/e2e/), workspace-level isolation prevents conflicts between test runs, making it safe to use hardcoded resource names like "test-binding" without risk of concurrent test collisions.
✅ Actions performed

Full review triggered.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 21, 2025
On-behalf-of: @SAP christoph.mewes@sap.com
coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 24, 2025
On-behalf-of: @SAP christoph.mewes@sap.com
On-behalf-of: @SAP christoph.mewes@sap.com
coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 24, 2025
@xrstf

xrstf commented Nov 24, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai It's okay, you don't like me, I don't like you either.

@coderabbitai

coderabbitai Bot commented Nov 24, 2025

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@xrstf: I'm here to assist with code reviews and any questions you have about this pull request. If there's something specific you'd like me to address or if you have concerns about the review process, please let me know.


🧠 Learnings used
Learnt from: mjudeikis
Repo: kube-bind/kube-bind PR: 351
File: contrib/kcp/test/e2e/binding.go:49-56
Timestamp: 2025-11-04T11:51:36.024Z
Learning: In kube-bind e2e tests (contrib/kcp/test/e2e/), workspace-level isolation prevents conflicts between test runs, making it safe to use hardcoded resource names like "test-binding" without risk of concurrent test collisions.

@xrstf xrstf force-pushed the cluster-isolation branch from 5d3ed5e to 0f3969b Compare November 24, 2025 17:29
@xrstf xrstf changed the title WIP: Add namespaced isolation mode for cluster-scoped objects Add namespaced isolation mode for cluster-scoped objects Nov 24, 2025
mjudeikis
mjudeikis previously approved these changes Nov 26, 2025

@mjudeikis mjudeikis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Few nits, but not worth cmmenting as nothing core chaning :)
very nicelly done :) thanks!

Comment thread docs/content/usage/synchronization.md Outdated
cnvergence
cnvergence previously approved these changes Nov 26, 2025

@cnvergence cnvergence left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks for providing the doc and explaining everything in detail
🍿

On-behalf-of: @SAP christoph.mewes@sap.com
@xrstf xrstf dismissed stale reviews from cnvergence and mjudeikis via 7fe2ac9 November 26, 2025 11:46
@xrstf xrstf merged commit 18cec9f into kbind-dev:main Nov 26, 2025
15 of 16 checks passed
@xrstf xrstf deleted the cluster-isolation branch November 26, 2025 12:38
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.

Implement Isolation

4 participants