summaryrefslogtreecommitdiff
path: root/edgemesh/pkg/plugin/plugin.go
blob: 9c6dd8c296c0ad0f4181cc7e70a74bfa7ff0f23f (about) (plain)
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
package plugin

import (
	"k8s.io/klog/v2"

	"github.com/go-chassis/go-archaius"
	"github.com/go-chassis/go-chassis/control"
	"github.com/go-chassis/go-chassis/core/config"
	"github.com/go-chassis/go-chassis/core/config/model"
	"github.com/go-chassis/go-chassis/core/loadbalancer"
	"github.com/go-chassis/go-chassis/core/registry"

	meshConfig "github.com/kubeedge/kubeedge/edgemesh/pkg/config"
	// Register panel to aviod panic error
	_ "github.com/kubeedge/kubeedge/edgemesh/pkg/plugin/panel"
	meshRegistry "github.com/kubeedge/kubeedge/edgemesh/pkg/plugin/registry"
)

// Install installs go-chassis plugins
func Install() {
	// service discovery
	opt := registry.Options{}
	registry.DefaultServiceDiscoveryService = meshRegistry.NewEdgeServiceDiscovery(opt)
	// load balance
	loadbalancer.InstallStrategy(meshConfig.Config.LBStrategy, func() loadbalancer.Strategy {
		switch meshConfig.Config.LBStrategy {
		case loadbalancer.StrategyRoundRobin:
			return &loadbalancer.RoundRobinStrategy{}
		case loadbalancer.StrategyRandom:
			return &loadbalancer.RandomStrategy{}
		case loadbalancer.StrategySessionStickiness:
			return &loadbalancer.SessionStickinessStrategy{}
		default:
			return &loadbalancer.RoundRobinStrategy{}
		}
	})
	// control panel
	config.GlobalDefinition = &model.GlobalCfg{
		Panel: model.ControlPanel{
			Infra: "edge",
		},
		Ssl: make(map[string]string),
	}
	opts := control.Options{
		Infra:   config.GlobalDefinition.Panel.Infra,
		Address: config.GlobalDefinition.Panel.Settings["address"],
	}
	if err := control.Init(opts); err != nil {
		klog.Errorf("failed to init control: %v", err)
	}
	// init archaius
	if err := archaius.Init(); err != nil {
		klog.Errorf("failed to init arahaius: %v", err)
	}
}