-
Notifications
You must be signed in to change notification settings - Fork 2
/
hoh_config_db_to_transport_syncer.go
38 lines (33 loc) · 1.41 KB
/
hoh_config_db_to_transport_syncer.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
package dbsyncer
import (
"fmt"
"time"
configv1 "github.com/open-cluster-management/hub-of-hubs-data-types/apis/config/v1"
"github.com/open-cluster-management/hub-of-hubs-spec-transport-bridge/pkg/bundle"
"github.com/open-cluster-management/hub-of-hubs-spec-transport-bridge/pkg/db"
"github.com/open-cluster-management/hub-of-hubs-spec-transport-bridge/pkg/intervalpolicy"
"github.com/open-cluster-management/hub-of-hubs-spec-transport-bridge/pkg/transport"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
)
const (
configTableName = "configs"
configsMsgKey = "Configs"
)
// AddHoHConfigDBToTransportSyncer adds hub-of-hubs config db to transport syncer to the manager.
func AddHoHConfigDBToTransportSyncer(mgr ctrl.Manager, db db.HubOfHubsSpecDB, transport transport.Transport,
syncInterval time.Duration) error {
if err := mgr.Add(&genericDBToTransportSyncer{
log: ctrl.Log.WithName("hoh-config-db-to-transport-syncer"),
db: db,
dbTableName: configTableName,
transport: transport,
transportBundleKey: configsMsgKey,
createObjFunc: func() metav1.Object { return &configv1.Config{} },
createBundleFunc: bundle.NewBaseBundle,
intervalPolicy: intervalpolicy.NewExponentialBackoffIntervalPolicy(syncInterval),
}); err != nil {
return fmt.Errorf("failed to add db to transport syncer - %w", err)
}
return nil
}