Example #1
0
func run(be backend.Backend, sm *subnet.SubnetManager, exit chan int) {
	var err error
	defer func() {
		if err == nil || err == task.ErrCanceled {
			exit <- 0
		} else {
			log.Error(err)
			exit <- 1
		}
	}()

	iface, ipaddr, err := lookupIface()
	if err != nil {
		return
	}

	if iface.MTU == 0 {
		err = fmt.Errorf("Failed to determine MTU for %s interface", ipaddr)
		return
	}

	log.Infof("Using %s as external interface", ipaddr)

	sn, err := be.Init(iface, ipaddr, opts.httpPort, opts.ipMasq)
	if err != nil {
		return
	}

	writeSubnetFile(sn)
	notifyWebhook(sn)

	if err = httpServer(sm, ipaddr.String(), opts.httpPort); err != nil {
		err = fmt.Errorf("error starting HTTP server: %s", err)
		return
	}
	if opts.discoverdURL != "" {
		disc.NewClientWithURL(opts.discoverdURL).AddServiceAndRegister("flannel", net.JoinHostPort(ipaddr.String(), opts.httpPort))
	}

	log.Infof("%s mode initialized", be.Name())
	be.Run()
}
Example #2
0
func makeSubnetManager() *subnet.SubnetManager {
	var registryFn func() (subnet.Registry, error)
	client := disc.NewClientWithURL(opts.discoverdURL)
	registryFn = func() (subnet.Registry, error) {
		return discoverd.NewRegistry(client, "flannel")
	}

	for {
		reg, err := registryFn()
		if err != nil {
			log.Error("Failed to create subnet registry: ", err)
			time.Sleep(time.Second)
			continue
		}

		sm, err := subnet.NewSubnetManager(reg)
		if err == nil {
			return sm
		}

		log.Error("Failed to create SubnetManager: ", err)
		time.Sleep(time.Second)
	}
}