Skip to content

Commit 8b7174b

Browse files
committed
Update with feedback
Signed-off-by: Marvin Beckers <[email protected]>
1 parent 120cef5 commit 8b7174b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

designs/multi-cluster.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ objects. This proposal is about adding native support for multi-cluster use-case
3838
to controller-runtime.
3939

4040
With this change, it will be possible to implement pluggable cluster providers
41-
that automatically start and stop watches (and thus, cluster-aware reconcilers) when
41+
that automatically start and stop sources (and thus, cluster-aware reconcilers) when
4242
the cluster provider adds ("engages") or removes ("disengages") a cluster.
4343

4444
## Motivation
@@ -58,19 +58,18 @@ This change is important because:
5858

5959
- Provide an interface for plugging in a "cluster provider", which provides a dynamic set of clusters that should be reconciled by registered controllers.
6060
- Provide a way to natively write controllers that
61-
1. (UNIFORM MULTI-CLUSTER CONTROLLER) operate on multiple clusters in a uniform way,
61+
1. use the cluster provider Go interface that can be implemented by 3rd parties outside of controller-runtime to adapt an existing multi-cluster-compatible code-base to a concrete environment.
62+
2. (UNIFORM MULTI-CLUSTER CONTROLLER) operate on multiple clusters in a uniform way,
6263
i.e. reconciling the same resources on multiple clusters, **optionally**
6364
- sourcing information from one central hub cluster
6465
- sourcing information cross-cluster.
6566

6667
Example: distributed `ReplicaSet` controller, reconciling `ReplicaSets` on multiple clusters.
67-
2. (AGGREGATING MULTI-CLUSTER CONTROLLER) operate on one central hub cluster aggregating information from multiple clusters.
68+
3. (AGGREGATING MULTI-CLUSTER CONTROLLER) operate on one central hub cluster aggregating information from multiple clusters.
6869

6970
Example: distributed `Deployment` controller, aggregating `ReplicaSets` across multiple clusters back into a central `Deployment` object.
7071
- Allow clusters to dynamically join and leave the set of clusters a controller operates on.
7172
- Allow logical clusters where a set of clusters is actually backed by one physical informer store.
72-
- Allow 3rd-parties to plug in their multi-cluster adapter (in source code) into
73-
an existing multi-cluster-compatible code-base.
7473
- Minimize the amount of changes to make a controller-runtime controller
7574
multi-cluster-compatible, in a way that 3rd-party projects have no reason to
7675
object these kind of changes.
@@ -231,9 +230,16 @@ if err != nil {
231230
client := cl.GetClient()
232231
```
233232

234-
Due to the BYO `request` type, controllers need to be built like this:
233+
Due to the BYO `request` type, controllers using the `For` builder function need to be built/changed like this:
235234

236235
```golang
236+
// previous
237+
builder.TypedControllerManagedBy[reconcile.Request](mgr).
238+
Named("single-cluster-controller").
239+
For(&corev1.Pod{}).
240+
Complete(reconciler)
241+
242+
// new
237243
builder.TypedControllerManagedBy[ClusterRequest](mgr).
238244
Named("multi-cluster-controller").
239245
Watches(&corev1.Pod{}, &ClusterRequestEventHandler{}).
@@ -243,7 +249,7 @@ builder.TypedControllerManagedBy[ClusterRequest](mgr).
243249
With `ClusterRequest` and `ClusterRequestEventHandler` being BYO types. `reconciler`
244250
can be e.g. of type `reconcile.TypedFunc[ClusterRequest]`.
245251

246-
`ClusterRequest` will likely often look like this:
252+
`ClusterRequest` will likely often look like this (but since it is a BYO type, it could store other information as well):
247253

248254
```golang
249255
type ClusterRequest struct {
@@ -252,18 +258,12 @@ type ClusterRequest struct {
252258
}
253259
```
254260

255-
Controllers that use `For` or `Owns` cannot be converted to multi-cluster controllers
256-
without changing to `Watches` as the BYO `request` type cannot be used with them:
257-
258-
```golang
259-
// pkg/builder/controller.go
260-
if reflect.TypeFor[request]() != reflect.TypeOf(reconcile.Request{}) {
261-
return fmt.Errorf("For() can only be used with reconcile.Request, got %T", *new(request))
262-
}
263-
```
261+
Controllers that use `Owns` cannot be converted to multi-cluster controllers
262+
without a BYO type re-implementation of `handler.EnqueueRequestForOwner` matching
263+
the BYO type, which is considered out of scope for now.
264264

265-
With the described changes (use `GetCluster(ctx, clusterName)` and making `reconciler`
266-
a `TypedFunc[ClusterRequest`) an existing controller will automatically act as
265+
With the described changes (use `GetCluster(ctx, clusterName)`, making `reconciler`
266+
a `TypedFunc[ClusterRequest]` and migrating to `Watches`) an existing controller will automatically act as
267267
*uniform multi-cluster controller*. It will reconcile resources from cluster `X`
268268
in cluster `X`.
269269

@@ -273,7 +273,7 @@ the controller.
273273

274274
Controllers that should be triggered by events on the hub cluster can continue
275275
to use `For` and `Owns` and explicitly pass the intention to engage only with the
276-
"default" cluster:
276+
"default" cluster (this is only necessary if a cluster provider is plugged in):
277277

278278
```golang
279279
builder.NewControllerManagedBy(mgr).

0 commit comments

Comments
 (0)