コード例 #1
0
ファイル: runner.go プロジェクト: imjorge/flynn
func main() {
	var config Config
	config.Backend.Type = "vxlan"
	if backend := os.Getenv("BACKEND"); backend != "" {
		config.Backend.Type = backend
	}
	config.Network = os.Getenv("NETWORK")
	if config.Network == "" {
		config.Network = "100.100.0.0/16"
	}
	flag.StringVar(&config.SubnetMin, "subnet-min", "", "container network min subnet")
	flag.StringVar(&config.SubnetMax, "subnet-max", "", "container network max subnet")
	flag.UintVar(&config.SubnetLen, "subnet-len", 0, "container network subnet length")
	flag.UintVar(&config.Backend.VNI, "vni", 0, "vxlan network identifier")
	flag.UintVar(&config.Backend.Port, "port", 0, "vxlan communication port (UDP)")
	flag.Parse()

	// wait for discoverd to come up
	status, err := cluster.WaitForHostStatus(os.Getenv("EXTERNAL_IP"), func(status *host.HostStatus) bool {
		return status.Discoverd != nil && status.Discoverd.URL != ""
	})
	if err != nil {
		log.Fatal(err)
	}

	// create service and config if not present
	client := discoverd.NewClientWithURL(status.Discoverd.URL)
	if err := client.AddService(serviceName, nil); err != nil && !hh.IsObjectExistsError(err) {
		log.Fatalf("error creating discoverd service: %s", err)
	}
	data, err := json.Marshal(map[string]Config{"config": config})
	if err != nil {
		log.Fatal(err)
	}
	err = client.Service(serviceName).SetMeta(&discoverd.ServiceMeta{Data: data})
	if err != nil && !hh.IsObjectExistsError(err) {
		log.Fatalf("error creating discoverd service metadata: %s", err)
	}

	flanneld, err := exec.LookPath("flanneld")
	if err != nil {
		log.Fatal(err)
	}

	if err := syscall.Exec(
		flanneld,
		[]string{
			flanneld,
			"-discoverd-url=" + status.Discoverd.URL,
			"-iface=" + os.Getenv("EXTERNAL_IP"),
			"-http-port=" + os.Getenv("PORT"),
			fmt.Sprintf("-notify-url=http://%s:1113/host/network", os.Getenv("EXTERNAL_IP")),
		},
		os.Environ(),
	); err != nil {
		log.Fatal(err)
	}
}
コード例 #2
0
ファイル: registry_test.go プロジェクト: devick/flynn
func newTest(t *testing.T) (s *test) {
	defer func() {
		if t.Failed() {
			s.cleanup()
			t.FailNow()
		}
	}()

	client, killDiscoverd := testutil.BootDiscoverd(t, "")

	serviceName := "flannel-test"
	if err := client.AddService(serviceName, nil); err != nil {
		t.Errorf("error adding service: %s", err)
	}

	service := client.Service(serviceName)
	events := make(chan *discoverd.Event)
	stream, err := service.Watch(events)
	if err != nil {
		t.Errorf("error creating watch: %s", err)
	}

	data := []byte(`{"config":{"network": "10.3.0.0/16"}}`)
	if err := service.SetMeta(&discoverd.ServiceMeta{Data: data}); err != nil {
		t.Errorf("error setting meta: %s", err)
	}

	registry, err := NewRegistry(client, serviceName)
	if err != nil {
		t.Errorf("error creating registry: %s", err)
	}

	return &test{
		T:        t,
		client:   client,
		service:  service,
		events:   events,
		registry: registry,
		cleanup: func() {
			stream.Close()
			killDiscoverd()
		},
	}
}
コード例 #3
0
ファイル: store.go プロジェクト: tombh/flynn
// ServiceLeader returns the leader for a service.
func (s *ProxyStore) ServiceLeader(service string) (*discoverd.Instance, error) {
	host := s.Peers[rand.Intn(len(s.Peers))]
	client := discoverd.NewClientWithURL("http://" + host)
	return client.Service(service).Leader()
}