Ejemplo n.º 1
0
func (a *BalancerAgent) start() error {
	controller, err := etcdcontrol.NewListener(a.store, a.errorSink)
	if err != nil {
		return err
	}

	a.controller = controller
	a.stop = make(chan struct{})
	a.services = make(chan Services, 1)
	go a.updater()
	go a.generator()
	return nil
}
Ejemplo n.º 2
0
func (d *BalancerDaemon) parseArgs(args []string) error {
	fs := flag.NewFlagSet(args[0], flag.ContinueOnError)

	var promCf prometheus.Config
	var debug bool

	// The bridge specified should be the one where packets sent
	// to service IP addresses go.  So even with weave, that's
	// typically 'docker0'.
	fs.StringVar(&d.netConfig.bridge,
		"bridge", "docker0", "bridge device")
	fs.StringVar(&d.netConfig.chain,
		"chain", "FLUX", "iptables chain name")
	fs.StringVar(&promCf.ListenAddr,
		"listen-prometheus", "",
		"listen for connections from Prometheus on this IP address and port; e.g., :9000")
	fs.StringVar(&promCf.AdvertiseAddr,
		"advertise-prometheus", "",
		"IP address and port to advertise to Prometheus; e.g. 192.168.42.221:9000")

	fs.BoolVar(&debug, "debug", false, "output debugging logs")
	if err := fs.Parse(args[1:]); err != nil {
		return err
	}

	if fs.NArg() > 0 {
		return fmt.Errorf("excess command line arguments")
	}

	if debug {
		log.SetLevel(log.DebugLevel)
	}
	log.Debug("Debug logging on")

	etcdclient, err := etcdutil.NewClientFromEnv()
	if err != nil {
		return err
	}

	d.controller, err = etcdcontrol.NewListener(etcdstore.New(etcdclient),
		d.errorSink)
	if err != nil {
		return err
	}

	if promCf.ListenAddr == "" {
		if promCf.AdvertiseAddr != "" {
			return fmt.Errorf("-advertise-prometheus option must be accompanied by -listen-prometheus")
		}

		d.eventHandler = eventlogger.EventLogger{}
	} else {
		if promCf.AdvertiseAddr == "" {
			promCf.AdvertiseAddr = promCf.ListenAddr
		}

		promCf.ErrorSink = d.errorSink
		promCf.EtcdClient = etcdclient
		handler, err := prometheus.NewEventHandler(promCf)
		if err != nil {
			return err
		}
		d.eventHandler = handler
	}

	return nil
}