func Run(ctx *cli.Context) { SetLogLevel(ctx.String("log-level")) var ( derr, ierr chan error ) //Bind to cluster store store, err := NewStore(ctx.String("cluster-store")) if err != nil { panic(err) } if !ctx.Bool("no-network") { d, err := dnet.NewDriver("global", ctx.String("interface"), store) if err != nil { panic(err) } h := network.NewHandler(d) derr = make(chan error) go func() { derr <- h.ServeUnix("root", "dnet") }() Log.Infof("Running Driver plugin 'dnet', bound on interface %s", ctx.String("interface")) } if !ctx.Bool("no-ipam") { i, err := dipam.NewIpam() if err != nil { panic(err) } h := ipam.NewHandler(i) ierr = make(chan error) go func() { ierr <- h.ServeUnix("root", "dhcp") }() Log.Infof("Running IPAM plugin 'dhcp'") } if derr == nil && ierr == nil { Log.Errorf("You started the daemon without anything to do") os.Exit(127) } select { case err := <-derr: panic(err) case err := <-ierr: panic(err) } }
func main() { // Display the version on "-v" // Use a new flag set so as not to conflict with existing libraries which use "flag" flagSet := flag.NewFlagSet("Calico", flag.ExitOnError) version := flagSet.Bool("v", false, "Display version") err := flagSet.Parse(os.Args[1:]) if err != nil { log.Fatalln(err) } if *version { fmt.Println(VERSION) os.Exit(0) } initializeClient() errChannel := make(chan error) networkHandler := network.NewHandler(driver.NewNetworkDriver(client)) ipamHandler := ipam.NewHandler(driver.NewIpamDriver(client)) go func(c chan error) { log.Infoln("calico-net has started.") err := networkHandler.ServeUnix("root", networkPluginName) log.Infoln("calico-net has stopped working.") c <- err }(errChannel) go func(c chan error) { log.Infoln("calico-ipam has started.") err := ipamHandler.ServeUnix("root", ipamPluginName) log.Infoln("calico-ipam has stopped working.") c <- err }(errChannel) err = <-errChannel log.Fatalln(err) }
func main() { flag.Parse() // Scan the arguments list if *versionFlag { fmt.Println("Version:", APP_VERSION) return } if *consulHostFlag == "" { cha := os.Getenv("CONSUL_HTTP_ADDR") if cha != "" { *consulHostFlag = cha } else { *consulHostFlag = "localhost:8500" } } cfg := new(datastore.ScopeCfg) cfg.Client.Address = *consulHostFlag cfg.Client.Provider = "consul" cfg.Client.Config = &store.Config{ConnectionTimeout: 10 * time.Second} addrs := new(ipam.AddressSpacesResponse) addrs.GlobalDefaultAddressSpace = "MySuperAwesomeGlobal" addrs.LocalDefaultAddressSpace = "MySuperAwesomeLocal" d, err := driver.NewIPAMDriver(addrs, cfg) if err != nil { fmt.Println(err) return } h := ipam.NewHandler(d) log.Debugf("I'm listening on %s", *listenAddress) err = h.ServeTCP("kvipamdriver", *listenAddress) if err != nil { log.Errorf("ServeTCP returned error: %s", err.Error()) } }