Skip to content

Commit bd9699e

Browse files
committed
manager: add GetManager
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
1 parent a5da96b commit bd9699e

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

pkg/manager/manager.go

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,11 @@ import (
3535
"github.com/multicluster-runtime/multicluster-runtime/pkg/multicluster"
3636
)
3737

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-
5638
// LocalCluster is the name of the local cluster.
5739
const LocalCluster = ""
5840

5941
// 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.
6143
type Manager interface {
6244
// Add will set requested dependencies on the component, and cause the component to be
6345
// started when Start is called.
@@ -111,7 +93,11 @@ type Manager interface {
11193
// ClusterFromContext returns the default cluster set in the context.
11294
ClusterFromContext(ctx context.Context) (cluster.Cluster, error)
11395

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).
115101
GetLocalManager() manager.Manager
116102

117103
// 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)
217203
}
218204
return nil //nolint:govet // cancel is called in the error case only.
219205
}
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

Comments
 (0)