You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -35,6 +37,10 @@ Multi-cluster use-cases require the creation of multiple managers and/or cluster
35
37
objects. This proposal is about adding native support for multi-cluster use-cases
36
38
to controller-runtime.
37
39
40
+
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
42
+
the cluster provider adds ("engages") or removes ("disengages") a cluster.
43
+
38
44
## Motivation
39
45
40
46
This change is important because:
@@ -50,6 +56,7 @@ This change is important because:
50
56
51
57
### Goals
52
58
59
+
- Provide an interface for plugging in a "cluster provider", which provides a dynamic set of clusters that should be reconciled by registered controllers.
53
60
- Provide a way to natively write controllers that
54
61
1. (UNIFORM MULTI-CLUSTER CONTROLLER) operate on multiple clusters in a uniform way,
55
62
i.e. reconciling the same resources on multiple clusters, **optionally**
@@ -59,12 +66,8 @@ This change is important because:
59
66
Example: distributed `ReplicaSet` controller, reconciling `ReplicaSets` on multiple clusters.
60
67
2. (AGGREGATING MULTI-CLUSTER CONTROLLER) operate on one central hub cluster aggregating information from multiple clusters.
61
68
62
-
Example: distributed `Deployment` controller, aggregating `ReplicaSets` back into the`Deployment` object.
69
+
Example: distributed `Deployment` controller, aggregating `ReplicaSets`across multiple clusters back into a central`Deployment` object.
63
70
- Allow clusters to dynamically join and leave the set of clusters a controller operates on.
64
-
- Allow event sources to be cross-cluster:
65
-
1. Multi-cluster events that trigger reconciliation in the one central hub cluster.
66
-
2. Central hub cluster events to trigger reconciliation on multiple clusters.
67
-
- Allow (informer) indexes that span multiple clusters.
68
71
- Allow logical clusters where a set of clusters is actually backed by one physical informer store.
69
72
- Allow 3rd-parties to plug in their multi-cluster adapter (in source code) into
70
73
an existing multi-cluster-compatible code-base.
@@ -80,7 +83,7 @@ logic.
80
83
### Examples
81
84
82
85
- Run a controller-runtime controller against a kubeconfig with arbitrary many contexts, all being reconciled.
83
-
- Run a controller-runtime controller against cluster-managers like kind, Cluster-API, Open-Cluster-Manager or Hypershift.
86
+
- Run a controller-runtime controller against clustermanagers like kind, ClusterAPI, Open-Cluster-Manager or Hypershift.
84
87
- Run a controller-runtime controller against a kcp shard with a wildcard watch.
85
88
86
89
### Non-Goals/Future Work
@@ -94,17 +97,32 @@ logic.
94
97
## Proposal
95
98
96
99
The `ctrl.Manager`_SHOULD_ be extended to get an optional `cluster.Provider` via
97
-
`ctrl.Options` implementing
100
+
`ctrl.Options`, implementing:
98
101
99
102
```golang
100
103
// pkg/cluster
104
+
105
+
// Provider defines methods to retrieve clusters by name. The provider is
106
+
// responsible for discovering and managing the lifecycle of each cluster.
107
+
//
108
+
// Example: A Cluster API provider would be responsible for discovering and
109
+
// managing clusters that are backed by Cluster API resources, which can live
110
+
// in multiple namespaces in a single management cluster.
A mixed set of sources is possible as shown here in the example.
202
288
203
289
## User Stories
204
290
205
291
### Controller Author with no interest in multi-cluster wanting to old behaviour.
206
292
207
293
- Do nothing. Controller-runtime behaviour is unchanged.
208
294
209
-
### Multi-Cluster Integrator wanting to support cluster managers like Cluster-API or kind
295
+
### Multi-Cluster Integrator wanting to support cluster managers like ClusterAPI or kind
210
296
211
297
- Implement the `cluster.Provider` interface, either via polling of the cluster registry
212
298
or by watching objects in the hub cluster.
213
-
- For every new cluster create an instance of `cluster.Cluster`.
299
+
- For every new cluster create an instance of `cluster.Cluster` and call `mgr.Engage`.
214
300
215
301
### Multi-Cluster Integrator wanting to support apiservers with logical cluster (like kcp)
216
302
@@ -223,7 +309,8 @@ A mixed set of sources is possible as shown here in the example.
223
309
### Controller Author without self-interest in multi-cluster, but open for adoption in multi-cluster setups
224
310
225
311
- Replace `mgr.GetClient()` and `mgr.GetCache` with `mgr.GetCluster(req.ClusterName).GetClient()` and `mgr.GetCluster(req.ClusterName).GetCache()`.
226
-
- Make manager and controller plumbing vendor'able to allow plugging in multi-cluster provider.
312
+
- Switch from `For` and `Owns` builder calls to `watches`
313
+
- Make manager and controller plumbing vendor'able to allow plugging in multi-cluster provider and BYO request type.
227
314
228
315
### Controller Author who wants to support certain multi-cluster setups
229
316
@@ -234,12 +321,11 @@ A mixed set of sources is possible as shown here in the example.
234
321
235
322
- The standard behaviour of controller-runtime is unchanged for single-cluster controllers.
236
323
- The activation of the multi-cluster mode is through attaching the `cluster.Provider` to the manager.
237
-
To make it clear that the semantics are experimental, we make the `Options.provider` field private
238
-
and adds `Options.WithExperimentalClusterProvider` method.
324
+
To make it clear that the semantics are experimental, we name the `manager.Options` field
325
+
`ExperimentalClusterProvider`.
239
326
- We only extend these interfaces and structs:
240
-
-`ctrl.Manager` with `GetCluster(ctx, clusterName string) (cluster.Cluster, error)`
241
-
-`cluster.Cluster` with `Name() string`
242
-
-`reconcile.Request` with `ClusterName string`
327
+
-`ctrl.Manager` with `GetCluster(ctx, clusterName string) (cluster.Cluster, error)` and `cluster.Aware`.
328
+
-`cluster.Cluster` with `Name() string`.
243
329
We think that the behaviour of these extensions is well understood and hence low risk.
244
330
Everything else behind the scenes is an implementation detail that can be changed
245
331
at any time.
@@ -258,24 +344,12 @@ A mixed set of sources is possible as shown here in the example.
258
344
- We could deepcopy the builder instead of the sources and handlers. This would
259
345
lead to one controller and one workqueue per cluster. For the reason outlined
260
346
in the previous alternative, this is not desireable.
261
-
- We could skip adding `ClusterName` to `reconcile.Request` and instead pass the
262
-
cluster through in the context. On the one hand, this looks attractive as it
263
-
would avoid having to touch reconcilers at all to make them multi-cluster-compatible.
264
-
On the other hand, with `cluster.Cluster` embedded into `manager.Manager`, not
265
-
every method of `cluster.Cluster` carries a context. So virtualizing the cluster
266
-
in the manager leads to contradictions in the semantics.
267
-
268
-
For example, it can well be that every cluster has different REST mapping because
269
-
installed CRDs are different. Without a context, we cannot return the right
270
-
REST mapper.
271
-
272
-
An alternative would be to add a context to every method of `cluster.Cluster`,
273
-
which is a much bigger and uglier change than what is proposed here.
274
-
275
347
276
348
## Implementation History
277
349
278
350
-[PR #2207 by @vincepri : WIP: ✨ Cluster Provider and cluster-aware controllers](https://github.com/kubernetes-sigs/controller-runtime/pull/2207) – with extensive review
279
-
-[PR #2208 by @stttsreplace#2207: WIP: ✨ Cluster Provider and cluster-aware controllers](https://github.com/kubernetes-sigs/controller-runtime/pull/2726) –
351
+
-[PR #2726 by @stttsreplacing#2207: WIP: ✨ Cluster Provider and cluster-aware controllers](https://github.com/kubernetes-sigs/controller-runtime/pull/2726) –
280
352
picking up #2207, addressing lots of comments and extending the approach to what kcp needs, with a `fleet-namespace` example that demonstrates a similar setup as kcp with real logical clusters.
353
+
-[PR #3019 by @embik, replacing #2726: ✨ WIP: Cluster provider and cluster-aware controllers](https://github.com/kubernetes-sigs/controller-runtime/pull/3019) -
354
+
picking up #2726, reworking existing code to support the recent `Typed*` generic changes of the codebase.
281
355
-[github.com/kcp-dev/controller-runtime](https://github.com/kcp-dev/controller-runtime) – the kcp controller-runtime fork
0 commit comments