Add namespaced isolation mode for cluster-scoped objects#394
Conversation
|
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 |
|
@coderabbitai review this please |
|
@xrstf: I will review the changes in this pull request. 🧠 Learnings used✅ Actions performedReview triggered.
|
…ced' and 'none' strategies On-behalf-of: @SAP christoph.mewes@sap.com
0922334 to
8989855
Compare
|
@coderabbitai review! |
|
@xrstf: I will review the changes in this pull request. 🧠 Learnings used✅ Actions performedReview triggered.
|
|
@coderabbitai full-review |
|
@ntnn: I will perform a full review of all the changes in this pull request. 🧠 Learnings used✅ Actions performedFull review triggered. |
On-behalf-of: @SAP christoph.mewes@sap.com
On-behalf-of: @SAP christoph.mewes@sap.com
|
@coderabbitai It's okay, you don't like me, I don't like you either. |
|
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 |
On-behalf-of: @SAP christoph.mewes@sap.com
5d3ed5e to
0f3969b
Compare
mjudeikis
left a comment
There was a problem hiding this comment.
Few nits, but not worth cmmenting as nothing core chaning :)
very nicelly done :) thanks!
cnvergence
left a comment
There was a problem hiding this comment.
Looks good, thanks for providing the doc and explaining everything in detail
🍿
Summary
This PR implements two new scoping methods for cluster-scoped objects:
nonedoesn'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.namespacedtransforms 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. OncecreateProviderObjectis 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 (likecreateProviderObject,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).createProviderObjectshould 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
Since the entire
APIServiceNamespacehandling 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:ServiceNamespacedis the strategy for natively namespaced (on both sides) objects.Prefixedis the old cluster-scoped behaviour.Namespacedis one of the new cluster-scoped behaviours.Noneis one of the new cluster-scoped behaviours.In the CRD however we only expose the latter three, since we always use the
ServiceNamespacedstrategy 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
typespackage in the konnector to make it independent of thecontrollers/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