github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edgemesh/pkg/plugin/plugin.go (about)

     1  package plugin
     2  
     3  import (
     4  	"github.com/go-chassis/go-archaius"
     5  	"github.com/go-chassis/go-chassis/control"
     6  	"github.com/go-chassis/go-chassis/core/config"
     7  	"github.com/go-chassis/go-chassis/core/config/model"
     8  	"github.com/go-chassis/go-chassis/core/loadbalancer"
     9  	"github.com/go-chassis/go-chassis/core/registry"
    10  
    11  	meshConfig "github.com/kubeedge/kubeedge/edgemesh/pkg/config"
    12  	_ "github.com/kubeedge/kubeedge/edgemesh/pkg/plugin/panel"
    13  	meshRegistry "github.com/kubeedge/kubeedge/edgemesh/pkg/plugin/registry"
    14  )
    15  
    16  // Install installs go-chassis plugins
    17  func Install() {
    18  	// service discovery
    19  	opt := registry.Options{}
    20  	registry.DefaultServiceDiscoveryService = meshRegistry.NewEdgeServiceDiscovery(opt)
    21  	// load balance
    22  	loadbalancer.InstallStrategy(meshConfig.Config.LBStrategy, func() loadbalancer.Strategy {
    23  		switch meshConfig.Config.LBStrategy {
    24  		case loadbalancer.StrategyRoundRobin:
    25  			return &loadbalancer.RoundRobinStrategy{}
    26  		case loadbalancer.StrategyRandom:
    27  			return &loadbalancer.RandomStrategy{}
    28  		case loadbalancer.StrategySessionStickiness:
    29  			return &loadbalancer.SessionStickinessStrategy{}
    30  		default:
    31  			return &loadbalancer.RoundRobinStrategy{}
    32  		}
    33  	})
    34  	// control panel
    35  	config.GlobalDefinition = &model.GlobalCfg{
    36  		Panel: model.ControlPanel{
    37  			Infra: "edge",
    38  		},
    39  		Ssl: make(map[string]string),
    40  	}
    41  	opts := control.Options{
    42  		Infra:   config.GlobalDefinition.Panel.Infra,
    43  		Address: config.GlobalDefinition.Panel.Settings["address"],
    44  	}
    45  	control.Init(opts)
    46  	// init archaius
    47  	archaius.Init()
    48  }