forked from stolostron/multicluster-global-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.go
56 lines (47 loc) · 2.02 KB
/
spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package spec
import (
"context"
"fmt"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/stolostron/multicluster-global-hub/agent/pkg/configs"
"github.com/stolostron/multicluster-global-hub/agent/pkg/spec/syncers"
"github.com/stolostron/multicluster-global-hub/agent/pkg/spec/workers"
"github.com/stolostron/multicluster-global-hub/pkg/constants"
"github.com/stolostron/multicluster-global-hub/pkg/logger"
"github.com/stolostron/multicluster-global-hub/pkg/transport"
)
func AddToManager(context context.Context, mgr ctrl.Manager, transportClient transport.TransportClient,
agentConfig *configs.AgentConfig,
) error {
log := logger.DefaultZapLogger()
if transportClient.GetConsumer() == nil {
return fmt.Errorf("the consumer is not initialized")
}
if transportClient.GetProducer() == nil {
return fmt.Errorf("the producer is not initialized")
}
// add worker pool to manager
workers, err := workers.AddWorkerPoolToMgr(mgr, agentConfig.SpecWorkPoolSize, mgr.GetConfig())
if err != nil {
return fmt.Errorf("failed to add k8s workers pool to runtime manager: %w", err)
}
// add bundle dispatcher to manager
dispatcher, err := AddGenericDispatcher(mgr, transportClient.GetConsumer(), *agentConfig)
if err != nil {
return fmt.Errorf("failed to add bundle dispatcher to runtime manager: %w", err)
}
// register syncer to the dispatcher
if agentConfig.EnableGlobalResource {
dispatcher.RegisterSyncer(constants.GenericSpecMsgKey,
syncers.NewGenericSyncer(workers, agentConfig))
dispatcher.RegisterSyncer(constants.ManagedClustersLabelsMsgKey,
syncers.NewManagedClusterLabelSyncer(workers))
}
dispatcher.RegisterSyncer(constants.CloudEventTypeMigrationFrom,
syncers.NewManagedClusterMigrationFromSyncer(mgr.GetClient(), transportClient))
dispatcher.RegisterSyncer(constants.CloudEventTypeMigrationTo,
syncers.NewManagedClusterMigrationToSyncer(mgr.GetClient(), transportClient))
dispatcher.RegisterSyncer(constants.ResyncMsgKey, syncers.NewResyncer())
log.Info("added the spec controllers to manager")
return nil
}