// NewBalancer initializes a new balancer
//TODO: Graceful shutdown on initialization errors
NewBalancer initializes a new balancer
TODO: Graceful shutdown on initialization errors
// NewBalancer initializes a new balancer // TODO : Graceful shutdown on initialization errors
func NewBalancer(config *config.BalancerConfig) (Balancer, error) {
	store, err := store.New(config)
	if err != nil {
		return nil, err
	}
	state, err := state.New()
	if err != nil {
		return nil, err
	}
	ipvsMngr, err := ipvs.New()
	if err != nil {
		return nil, err
	}
	vipMngr, err := vip.New(config)
	if err != nil {
		return nil, err
	}
	iptablesMngr, err := iptables.New(config)
	if err != nil {
		return nil, err
	}
	ipam, err := ipam.New(state, config)
	if err != nil {
		return nil, err
	}
	metrics := metrics.NewMetrics(state, config)
	el, err := election.New(config, "election")
	if err != nil {
		return nil, err
	}
	changesCh := make(chan bool)
	balancer := &FusisBalancer{
		changesCh:    changesCh,
		store:        store,
		state:        state,
		ipvsMngr:     ipvsMngr,
		iptablesMngr: iptablesMngr,
		vipMngr:      vipMngr,
		config:       config,
		ipam:         ipam,
		election:     el,
		metrics:      metrics,
	}
	if balancer.config.EnableHealthChecks {
		balancer.healthMonitor = health.NewMonitor(store)
		go balancer.watchDestinationsHealth()
	}
	if balancer.isAnycast() {
		bgpMngr, err := bgp.NewBgpService(config)
		if err != nil {
			return nil, err
		}
		balancer.bgpMngr = bgpMngr
		go bgpMngr.Serve()
	}
	if err := fusis_net.DelVips(balancer.config.Interfaces.Inbound); err != nil {
		return nil, fmt.Errorf("Error cleaning up network vips: %v", err)
	}
	go balancer.watchLeaderChanges()
	go balancer.watchStore()
	go balancer.reconcile()
	go metrics.Monitor()
	if err := balancer.loadState(); err != nil {
		return nil, errors.Wrap(err, "failed to load initial state")
	}
	return balancer, nil
}
func NewBalancer ( config * config . BalancerConfig ) ( Balancer , error ) { store , err := store . New ( config ) if err != nil { return nil , err } state , err := state . New ( ) if err != nil { return nil , err } ipvsMngr , err := ipvs . New ( ) if err != nil { return nil , err } vipMngr , err := vip . New ( config ) if err != nil { return nil , err } iptablesMngr , err := iptables . New ( config ) if err != nil { return nil , err } ipam , err := ipam . New ( state , config ) if err != nil { return nil , err } metrics := metrics . NewMetrics ( state , config ) el , err := election . New ( config , " " ) if err != nil { return nil , err } changesCh := make ( chan bool ) balancer := & FusisBalancer { changesCh : changesCh , store : store , state : state , ipvsMngr : ipvsMngr , iptablesMngr : iptablesMngr , vipMngr : vipMngr , config : config , ipam : ipam , election : el , metrics : metrics , } if balancer . config . EnableHealthChecks { balancer . healthMonitor = health . NewMonitor ( store ) go balancer . watchDestinationsHealth ( ) } if balancer . isAnycast ( ) { bgpMngr , err := bgp . NewBgpService ( config ) if err != nil { return nil , err } balancer . bgpMngr = bgpMngr go bgpMngr . Serve ( ) } if err := fusis_net . DelVips ( balancer . config . Interfaces . Inbound ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } go balancer . watchLeaderChanges ( ) go balancer . watchStore ( ) go balancer . reconcile ( ) go metrics . Monitor ( ) if err := balancer . loadState ( ) ; err != nil { return nil , errors . Wrap ( err , " " ) } return balancer , nil }
NewBalancer initializes a new balancer
TODO: Graceful shutdown on initialization errors
NewBalancer initializes a new balancer TODO : Graceful shutdown on initialization errors
/* Cleanup all VIPs on the network interface */