@@ -35,29 +35,11 @@ import (
35
35
"github.com/multicluster-runtime/multicluster-runtime/pkg/multicluster"
36
36
)
37
37
38
- // Manager is like crossplane-manager, without the cluster.Cluster interface.
39
- var _ manager.Manager = & probe {}
40
-
41
- type probe struct {
42
- Manager
43
- cluster.Cluster
44
- }
45
-
46
- // Add adds a runnable.
47
- func (p * probe ) Add (_ manager.Runnable ) error {
48
- return nil
49
- }
50
-
51
- // Start starts the manager.
52
- func (p * probe ) Start (_ context.Context ) error {
53
- return nil
54
- }
55
-
56
38
// LocalCluster is the name of the local cluster.
57
39
const LocalCluster = ""
58
40
59
41
// Manager is a multi-cluster-aware manager, like the controller-runtime Cluster,
60
- // but without the direct cluster.Cluster methods .
42
+ // but without the direct embedding of cluster.Cluster.
61
43
type Manager interface {
62
44
// Add will set requested dependencies on the component, and cause the component to be
63
45
// started when Start is called.
@@ -111,7 +93,11 @@ type Manager interface {
111
93
// ClusterFromContext returns the default cluster set in the context.
112
94
ClusterFromContext (ctx context.Context ) (cluster.Cluster , error )
113
95
114
- // GetLocalManager returns the underlying controller-runtime manager of the host.
96
+ // GetManager returns a manager for the given cluster name.
97
+ GetManager (ctx context.Context , clusterName string ) (manager.Manager , error )
98
+
99
+ // GetLocalManager returns the underlying controller-runtime manager of the
100
+ // host. This is equivalent to GetManager(LocalCluster).
115
101
GetLocalManager () manager.Manager
116
102
117
103
// GetProvider returns the multicluster provider, or nil if it is not set.
@@ -217,3 +203,30 @@ func (m *mcManager) Engage(ctx context.Context, name string, cl cluster.Cluster)
217
203
}
218
204
return nil //nolint:govet // cancel is called in the error case only.
219
205
}
206
+
207
+ func (m * mcManager ) GetManager (ctx context.Context , clusterName string ) (manager.Manager , error ) {
208
+ cl , err := m .GetCluster (ctx , clusterName )
209
+ if err != nil {
210
+ return nil , err
211
+ }
212
+ return & scopedManager {
213
+ Manager : m ,
214
+ Cluster : cl ,
215
+ }, nil
216
+ }
217
+
218
+ var _ manager.Manager = & scopedManager {}
219
+
220
+ type scopedManager struct {
221
+ Manager
222
+ cluster.Cluster
223
+ }
224
+
225
+ func (p * scopedManager ) Add (r manager.Runnable ) error {
226
+ return p .Manager .GetLocalManager ().Add (r )
227
+ }
228
+
229
+ // Start starts the manager.
230
+ func (p * scopedManager ) Start (ctx context.Context ) error {
231
+ return p .Manager .GetLocalManager ().Start (ctx )
232
+ }
0 commit comments