-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (38 loc) · 1.13 KB
/
main.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
package main
import (
"fmt"
"os"
"github.com/loft-sh/vcluster-sdk/plugin"
synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context"
"github.com/loft-sh/vcluster/pkg/util/translate"
"k8s.io/klog/v2"
"kubedb.dev/vcluster-plugin/api"
"kubedb.dev/vcluster-plugin/syncers"
)
func main() {
ctx := plugin.MustInit()
_, err := Init(ctx)
if err != nil {
klog.Fatalf("validate config: %v", err)
}
plugin.MustRegister(syncers.NewPostgresSyncer(ctx))
// plugin.MustRegister(hooks.NewPodHook(cfg))
// plugin.MustRegister(hooks.NewSecretHook())
plugin.MustStart()
}
func Init(ctx *synccontext.RegisterContext) (*api.PluginConfig, error) {
// set suffix
// https://github.com/loft-sh/vcluster/blob/v0.19.7/cmd/vcluster/cmd/start.go#L61-L68
translate.VClusterName = ctx.Config.Name
if translate.VClusterName == "" {
translate.VClusterName = "vcluster"
}
// https://github.com/loft-sh/vcluster-sdk/blob/main/e2e/test_plugin/main.go#L43
var cfg api.PluginConfig
klog.Info(os.Getenv("PLUGIN_CONFIG"))
err := plugin.UnmarshalConfig(&cfg)
if err != nil {
return nil, fmt.Errorf("unmarshal config: %w", err)
}
return &cfg, nil
}