当前位置: 首页>>代码示例>>Golang>>正文


Golang registry.NewEtcdRegistry函数代码示例

本文整理汇总了Golang中github.com/coreos/fleet/registry.NewEtcdRegistry函数的典型用法代码示例。如果您正苦于以下问题:Golang NewEtcdRegistry函数的具体用法?Golang NewEtcdRegistry怎么用?Golang NewEtcdRegistry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewEtcdRegistry函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getFleetRegistryClient

func getFleetRegistryClient(fleetEndpoints []string) (fleetClient.API, error) {
	var dial func(string, string) (net.Conn, error)

	tlsConfig, err := fleetPkg.ReadTLSConfigFiles("", "", "")
	if err != nil {
		return nil, err
	}

	trans := &http.Transport{
		Dial:            dial,
		TLSClientConfig: tlsConfig,
	}

	timeout := 3 * time.Second
	eCfg := etcd.Config{
		Endpoints: fleetEndpoints,
		Transport: trans,
	}
	eClient, err := etcd.New(eCfg)
	if err != nil {
		return nil, err
	}
	kAPI := etcd.NewKeysAPI(eClient)
	reg := registry.NewEtcdRegistry(kAPI, registry.DefaultKeyPrefix, timeout)

	return &fleetClient.RegistryClient{Registry: reg}, nil
}
开发者ID:ubideo,项目名称:heapster,代码行数:27,代码来源:coreos.go

示例2: getFleetRegistryClient

func getFleetRegistryClient() (fleetClient.API, error) {
	var dial func(string, string) (net.Conn, error)

	tlsConfig, err := fleetPkg.ReadTLSConfigFiles("", "", "")
	if err != nil {
		return nil, err
	}

	trans := &http.Transport{
		Dial:            dial,
		TLSClientConfig: tlsConfig,
	}

	timeout := 3 * 1000 * time.Millisecond

	machines := strings.Split(*argEndpoints, ",")
	eClient, err := etcd.NewClient(machines, trans, timeout)
	if err != nil {
		return nil, err
	}

	reg := registry.NewEtcdRegistry(eClient, "/_coreos.com/fleet/")

	return &fleetClient.RegistryClient{Registry: reg}, nil
}
开发者ID:mikedanese,项目名称:heapster,代码行数:25,代码来源:buddy.go

示例3: getRegistryClient

func getRegistryClient(cCmd *cobra.Command) (client.API, error) {
	var dial func(string, string) (net.Conn, error)
	SSHUserName, _ := cmdFleet.PersistentFlags().GetString("ssh-username")
	tun := getTunnelFlag(cCmd)
	if tun != "" {
		sshClient, err := ssh.NewSSHClient(SSHUserName, tun, getChecker(cCmd), false, getSSHTimeoutFlag(cCmd))
		if err != nil {
			return nil, fmt.Errorf("failed initializing SSH client: %v", err)
		}

		dial = func(network, addr string) (net.Conn, error) {
			tcpaddr, err := net.ResolveTCPAddr(network, addr)
			if err != nil {
				return nil, err
			}
			return sshClient.DialTCP(network, nil, tcpaddr)
		}
	}

	CAFile, _ := cmdFleet.PersistentFlags().GetString("ca-file")
	CertFile, _ := cmdFleet.PersistentFlags().GetString("cert-file")
	KeyFile, _ := cmdFleet.PersistentFlags().GetString("key-file")
	tlsConfig, err := pkg.ReadTLSConfigFiles(CAFile, CertFile, KeyFile)
	if err != nil {
		return nil, err
	}

	trans := &http.Transport{
		Dial:            dial,
		TLSClientConfig: tlsConfig,
	}

	endPoint, _ := cmdFleet.PersistentFlags().GetString("endpoint")
	eCfg := etcd.Config{
		Endpoints:               strings.Split(endPoint, ","),
		Transport:               trans,
		HeaderTimeoutPerRequest: getRequestTimeoutFlag(cCmd),
	}

	eClient, err := etcd.New(eCfg)
	if err != nil {
		return nil, err
	}

	etcdKeyPrefix, _ := cmdFleet.PersistentFlags().GetString("etcd-key-prefix")
	kAPI := etcd.NewKeysAPI(eClient)
	reg := registry.NewEtcdRegistry(kAPI, etcdKeyPrefix)

	if msg, ok := checkVersion(reg); !ok {
		stderr(msg)
	}

	return &client.RegistryClient{Registry: reg}, nil
}
开发者ID:pulcy,项目名称:j2,代码行数:54,代码来源:fleetctl.go

示例4: getRegistryClient

func getRegistryClient(config FleetConfig) (client.API, error) {
	var dial func(string, string) (net.Conn, error)
	tun := config.Tunnel
	if tun != "" {
		sshClient, err := ssh.NewSSHClient(config.SSHUserName, tun, getChecker(config), false, config.SSHTimeout)
		if err != nil {
			return nil, fmt.Errorf("failed initializing SSH client: %v", err)
		}

		dial = func(network, addr string) (net.Conn, error) {
			tcpaddr, err := net.ResolveTCPAddr(network, addr)
			if err != nil {
				return nil, err
			}
			return sshClient.DialTCP(network, nil, tcpaddr)
		}
	}

	tlsConfig, err := pkg.ReadTLSConfigFiles(config.CAFile, config.CertFile, config.KeyFile)
	if err != nil {
		return nil, err
	}

	trans := &http.Transport{
		Dial:            dial,
		TLSClientConfig: tlsConfig,
	}

	eCfg := etcd.Config{
		Endpoints:               strings.Split(config.EndPoint, ","),
		Transport:               trans,
		HeaderTimeoutPerRequest: config.RequestTimeout,
	}

	eClient, err := etcd.New(eCfg)
	if err != nil {
		return nil, err
	}

	kAPI := etcd.NewKeysAPI(eClient)
	reg := registry.NewEtcdRegistry(kAPI, config.EtcdKeyPrefix)

	/*if msg, ok := checkVersion(reg); !ok {
		stderr(msg)
	}*/

	return &client.RegistryClient{Registry: reg}, nil
}
开发者ID:pulcy,项目名称:j2,代码行数:48,代码来源:fleet.go

示例5: NewFleetClient

func NewFleetClient() (client.API, error) {
	etcdClient, err := etcdInternal.New(
		etcdInternal.Config{Endpoints: []string{os.Getenv("ETCD_URL")}},
	)

	if err != nil {
		return nil, err
	}

	kAPI := etcdInternal.NewKeysAPI(etcdClient)
	reg := registry.NewEtcdRegistry(
		kAPI,
		registry.DefaultKeyPrefix,
		5*time.Second,
	)

	return &client.RegistryClient{Registry: reg}, nil
}
开发者ID:preachermanx,项目名称:sensu-coreos,代码行数:18,代码来源:check.go

示例6: getRegistryClient

func getRegistryClient() (client.API, error) {
	var dial func(string, string) (net.Conn, error)
	sshTimeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
	tun := getTunnelFlag()
	if tun != "" {
		sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false, sshTimeout)
		if err != nil {
			return nil, fmt.Errorf("failed initializing SSH client: %v", err)
		}

		dial = func(network, addr string) (net.Conn, error) {
			tcpaddr, err := net.ResolveTCPAddr(network, addr)
			if err != nil {
				return nil, err
			}
			return sshClient.DialTCP(network, nil, tcpaddr)
		}
	}

	tlsConfig, err := pkg.ReadTLSConfigFiles(Flags.EtcdCAFile, Flags.EtcdCertFile, Flags.EtcdKeyFile)
	if err != nil {
		return nil, err
	}

	trans := &http.Transport{
		Dial:            dial,
		TLSClientConfig: tlsConfig,
	}

	timeout := time.Duration(Flags.RequestTimeout*1000) * time.Millisecond
	machines := []string{Flags.Endpoint}
	eClient, err := etcd.NewClient(machines, trans, timeout)
	if err != nil {
		return nil, err
	}

	reg := registry.NewEtcdRegistry(eClient, Flags.EtcdKeyPrefix)

	// if msg, ok := checkVersion(reg); !ok {
	// 	stderr(msg)
	// }

	return &client.RegistryClient{Registry: reg}, nil
}
开发者ID:CodeJuan,项目名称:deis,代码行数:44,代码来源:registry.go

示例7: GetNodesInCluster

// GetNodesInCluster return the list of ip address of all the nodes
// running in the cluster currently active (fleetctl list-machines)
func GetNodesInCluster(url []string) []string {
	etcdClient, err := etcd.NewClient(url, &http.Transport{}, time.Second)
	if err != nil {
		log.Debugf("error creating new fleet etcd client: %v", err)
		return []string{}
	}

	fleetClient := registry.NewEtcdRegistry(etcdClient, "/_coreos.com/fleet/")
	machines, err := fleetClient.Machines()
	if err != nil {
		log.Debugf("error creating new fleet etcd client: %v", err)
		return []string{}
	}

	var machineList []string
	for _, m := range machines {
		machineList = append(machineList, m.PublicIP)
	}

	return machineList
}
开发者ID:ngpestelos,项目名称:deis,代码行数:23,代码来源:machines.go

示例8: GetNodesWithMetadata

// GetNodesWithMetadata returns the ip address of the nodes with all the specified roles
func GetNodesWithMetadata(url []string, metadata map[string][]string) ([]string, error) {
	etcdClient, err := etcd.NewClient(url, &http.Transport{}, time.Second)
	if err != nil {
		log.Debugf("error creating new fleet etcd client: %v", err)
		return nil, err
	}

	fleetClient := registry.NewEtcdRegistry(etcdClient, "/_coreos.com/fleet/")
	machines, err := fleetClient.Machines()
	if err != nil {
		log.Debugf("error creating new fleet etcd client: %v", err)
		return nil, err
	}

	var machineList []string
	for _, m := range machines {
		if hasMetadata(m, metadata) {
			machineList = append(machineList, m.PublicIP)
		}
	}

	return machineList, nil
}
开发者ID:ngpestelos,项目名称:deis,代码行数:24,代码来源:machines.go

示例9: getFleetRegistryClient

func getFleetRegistryClient(fleetEndpoints []string) (fleetClient.API, error) {
	var dial func(string, string) (net.Conn, error)

	tlsConfig, err := fleetPkg.ReadTLSConfigFiles("", "", "")
	if err != nil {
		return nil, err
	}

	trans := &http.Transport{
		Dial:            dial,
		TLSClientConfig: tlsConfig,
	}

	timeout := 3 * time.Second

	eClient, err := etcd.NewClient(fleetEndpoints, trans, timeout)
	if err != nil {
		return nil, err
	}

	reg := registry.NewEtcdRegistry(eClient, etcdRegistry)

	return &fleetClient.RegistryClient{Registry: reg}, nil
}
开发者ID:DreadPirateShawn,项目名称:heapster,代码行数:24,代码来源:coreos.go

示例10: getETCDClient

func getETCDClient(driverEndpoint string, etcdKeyPrefix string) (client.API, error) {
	log.Printf("Using ETCD connection for requests")

	trans := &http.Transport{}

	eCfg := etcd.Config{
		Endpoints: strings.Split(driverEndpoint, ","),
		Transport: trans,
	}

	eClient, err := etcd.New(eCfg)
	if err != nil {
		return nil, err
	}

	keysAPI := etcd.NewKeysAPI(eClient)
	reg := registry.NewEtcdRegistry(keysAPI, etcdKeyPrefix, defaultTimeout)

	if msg, ok := checkVersion(reg); !ok {
		log.Printf(msg)
	}

	return &client.RegistryClient{Registry: reg}, nil
}
开发者ID:brendangibat,项目名称:terraform-provider-fleet,代码行数:24,代码来源:provider.go

示例11: New

func New(cfg config.Config) (*Server, error) {
	agentTTL, err := time.ParseDuration(cfg.AgentTTL)
	if err != nil {
		return nil, err
	}

	mgr, err := systemd.NewSystemdUnitManager(systemd.DefaultUnitsDirectory)
	if err != nil {
		return nil, err
	}

	mach, err := newMachineFromConfig(cfg, mgr)
	if err != nil {
		return nil, err
	}

	tlsConfig, err := pkg.ReadTLSConfigFiles(cfg.EtcdCAFile, cfg.EtcdCertFile, cfg.EtcdKeyFile)
	if err != nil {
		return nil, err
	}

	eCfg := etcd.Config{
		Transport: &http.Transport{TLSClientConfig: tlsConfig},
		Endpoints: cfg.EtcdServers,
	}
	eClient, err := etcd.New(eCfg)
	if err != nil {
		return nil, err
	}

	etcdRequestTimeout := time.Duration(cfg.EtcdRequestTimeout*1000) * time.Millisecond
	kAPI := etcd.NewKeysAPI(eClient)
	reg := registry.NewEtcdRegistry(kAPI, cfg.EtcdKeyPrefix, etcdRequestTimeout)

	pub := agent.NewUnitStatePublisher(reg, mach, agentTTL)
	gen := unit.NewUnitStateGenerator(mgr)

	a := agent.New(mgr, gen, reg, mach, agentTTL)

	var rStream pkg.EventStream
	if !cfg.DisableWatches {
		rStream = registry.NewEtcdEventStream(kAPI, cfg.EtcdKeyPrefix)
	}
	lManager := lease.NewEtcdLeaseManager(kAPI, cfg.EtcdKeyPrefix, etcdRequestTimeout)

	ar := agent.NewReconciler(reg, rStream)

	e := engine.New(reg, lManager, rStream, mach)

	listeners, err := activation.Listeners(false)
	if err != nil {
		return nil, err
	}

	hrt := heart.New(reg, mach)
	mon := heart.NewMonitor(agentTTL)

	apiServer := api.NewServer(listeners, api.NewServeMux(reg, cfg.TokenLimit))
	apiServer.Serve()

	eIval := time.Duration(cfg.EngineReconcileInterval*1000) * time.Millisecond

	srv := Server{
		agent:       a,
		aReconciler: ar,
		usGen:       gen,
		usPub:       pub,
		engine:      e,
		mach:        mach,
		hrt:         hrt,
		mon:         mon,
		api:         apiServer,
		stop:        nil,
		engineReconcileInterval: eIval,
		disableEngine:           cfg.DisableEngine,
	}

	return &srv, nil
}
开发者ID:steveeJ,项目名称:fleet,代码行数:79,代码来源:server.go

示例12: New

func New(cfg config.Config, listeners []net.Listener) (*Server, error) {
	agentTTL, err := time.ParseDuration(cfg.AgentTTL)
	if err != nil {
		return nil, err
	}

	mgr, err := systemd.NewSystemdUnitManager(cfg.UnitsDirectory, cfg.SystemdUser)
	if err != nil {
		return nil, err
	}

	mach, err := newMachineFromConfig(cfg, mgr)
	if err != nil {
		return nil, err
	}

	tlsConfig, err := pkg.ReadTLSConfigFiles(cfg.EtcdCAFile, cfg.EtcdCertFile, cfg.EtcdKeyFile)
	if err != nil {
		return nil, err
	}

	eCfg := etcd.Config{
		Transport:               &http.Transport{TLSClientConfig: tlsConfig},
		Endpoints:               cfg.EtcdServers,
		HeaderTimeoutPerRequest: (time.Duration(cfg.EtcdRequestTimeout*1000) * time.Millisecond),
		Username:                cfg.EtcdUsername,
		Password:                cfg.EtcdPassword,
	}

	eClient, err := etcd.New(eCfg)
	if err != nil {
		return nil, err
	}

	kAPI := etcd.NewKeysAPI(eClient)

	var (
		reg        engine.CompleteRegistry
		genericReg interface{}
	)
	lManager := lease.NewEtcdLeaseManager(kAPI, cfg.EtcdKeyPrefix)

	if !cfg.EnableGRPC {
		genericReg = registry.NewEtcdRegistry(kAPI, cfg.EtcdKeyPrefix)
		if obj, ok := genericReg.(engine.CompleteRegistry); ok {
			reg = obj
		}
	} else {
		etcdReg := registry.NewEtcdRegistry(kAPI, cfg.EtcdKeyPrefix)
		genericReg = rpc.NewRegistryMux(etcdReg, mach, lManager)
		if obj, ok := genericReg.(engine.CompleteRegistry); ok {
			reg = obj
		}
	}

	pub := agent.NewUnitStatePublisher(reg, mach, agentTTL)
	gen := unit.NewUnitStateGenerator(mgr)

	a := agent.New(mgr, gen, reg, mach, agentTTL)

	var rStream pkg.EventStream
	if !cfg.DisableWatches {
		rStream = registry.NewEtcdEventStream(kAPI, cfg.EtcdKeyPrefix)
	}

	ar := agent.NewReconciler(reg, rStream)

	var e *engine.Engine
	if !cfg.EnableGRPC {
		e = engine.New(reg, lManager, rStream, mach, nil)
	} else {
		regMux := genericReg.(*rpc.RegistryMux)
		e = engine.New(reg, lManager, rStream, mach, regMux.EngineChanged)
		if cfg.DisableEngine {
			go regMux.ConnectToRegistry(e)
		}
	}

	if len(listeners) == 0 {
		listeners, err = activation.Listeners(false)
		if err != nil {
			return nil, err
		}
	}

	hrt := heart.New(reg, mach)
	mon := NewMonitor(agentTTL)

	apiServer := api.NewServer(listeners, api.NewServeMux(reg, cfg.TokenLimit))
	apiServer.Serve()

	eIval := time.Duration(cfg.EngineReconcileInterval*1000) * time.Millisecond

	srv := Server{
		agent:       a,
		aReconciler: ar,
		usGen:       gen,
		usPub:       pub,
		engine:      e,
		mach:        mach,
//.........这里部分代码省略.........
开发者ID:jonboulle,项目名称:fleet,代码行数:101,代码来源:server.go

示例13: New

func New(cfg config.Config) (*Server, error) {
	agentTTL, err := time.ParseDuration(cfg.AgentTTL)
	if err != nil {
		return nil, err
	}

	mgr, err := systemd.NewSystemdUnitManager(systemd.DefaultUnitsDirectory)
	if err != nil {
		return nil, err
	}

	mach, err := newMachineFromConfig(cfg, mgr)
	if err != nil {
		return nil, err
	}

	tlsConfig, err := pkg.ReadTLSConfigFiles(cfg.EtcdCAFile, cfg.EtcdCertFile, cfg.EtcdKeyFile)
	if err != nil {
		return nil, err
	}
	etcdRequestTimeout := time.Duration(cfg.EtcdRequestTimeout*1000) * time.Millisecond
	// set a per server request timeout that is the global request timeout divided by the number of quorum nodes (i.e. 3 out of 5)
	// this ensures that the the retry logic in etcd can try at least 3 servers before the global timeout fires and cancels the entire request
	quorumCount := (len(cfg.EtcdServers) / 2) + 1
	etcdRequestPerServerTimeout := etcdRequestTimeout
	if quorumCount > 1 {
		etcdRequestPerServerTimeout = time.Duration(int64(etcdRequestTimeout) / int64(quorumCount))
	}
	log.Infof("Etcd endpoints: %v", strings.Join(cfg.EtcdServers, ","))
	log.Infof("Setting global request timeout of %v and per server request timeout of %v using a quorum count of %v", etcdRequestTimeout, etcdRequestPerServerTimeout, quorumCount)

	eCfg := etcd.Config{
		Transport:               &http.Transport{TLSClientConfig: tlsConfig},
		Endpoints:               cfg.EtcdServers,
		HeaderTimeoutPerRequest: etcdRequestPerServerTimeout,
	}
	eClient, err := etcd.New(eCfg)
	if err != nil {
		return nil, err
	}

	kAPI := etcd.NewKeysAPI(eClient)
	reg := registry.NewEtcdRegistry(kAPI, cfg.EtcdKeyPrefix, etcdRequestTimeout)

	pub := agent.NewUnitStatePublisher(reg, mach, agentTTL)
	gen := unit.NewUnitStateGenerator(mgr)

	a := agent.New(mgr, gen, reg, mach, agentTTL)

	rStream := registry.NewEtcdEventStream(kAPI, cfg.EtcdKeyPrefix)
	lManager := lease.NewEtcdLeaseManager(kAPI, cfg.EtcdKeyPrefix, etcdRequestTimeout)

	ar := agent.NewReconciler(reg, rStream)

	e := engine.New(reg, lManager, rStream, mach)

	listeners, err := activation.Listeners(false)
	if err != nil {
		return nil, err
	}

	hrt := heart.New(reg, mach)
	mon := heart.NewMonitor(agentTTL)

	apiServer := api.NewServer(listeners, api.NewServeMux(reg))
	apiServer.Serve()

	eIval := time.Duration(cfg.EngineReconcileInterval*1000) * time.Millisecond

	srv := Server{
		agent:       a,
		aReconciler: ar,
		usGen:       gen,
		usPub:       pub,
		engine:      e,
		mach:        mach,
		hrt:         hrt,
		mon:         mon,
		api:         apiServer,
		stop:        nil,
		engineReconcileInterval: eIval,
	}

	return &srv, nil
}
开发者ID:WPMedia,项目名称:fleet,代码行数:85,代码来源:server.go

示例14: New

func New(cfg config.Config) (*Server, error) {
	etcdRequestTimeout := time.Duration(cfg.EtcdRequestTimeout*1000) * time.Millisecond
	agentTTL, err := time.ParseDuration(cfg.AgentTTL)
	if err != nil {
		return nil, err
	}

	mgr, err := systemd.NewSystemdUnitManager(systemd.DefaultUnitsDirectory)
	if err != nil {
		return nil, err
	}

	mach, err := newMachineFromConfig(cfg, mgr)
	if err != nil {
		return nil, err
	}

	tlsConfig, err := pkg.ReadTLSConfigFiles(cfg.EtcdCAFile, cfg.EtcdCertFile, cfg.EtcdKeyFile)
	if err != nil {
		return nil, err
	}

	eTrans := &http.Transport{TLSClientConfig: tlsConfig}
	eClient, err := etcd.NewClient(cfg.EtcdServers, eTrans, etcdRequestTimeout)
	if err != nil {
		return nil, err
	}

	reg := registry.NewEtcdRegistry(eClient, cfg.EtcdKeyPrefix)

	pub := agent.NewUnitStatePublisher(reg, mach, agentTTL)
	gen := unit.NewUnitStateGenerator(mgr)

	a := agent.New(mgr, gen, reg, mach, agentTTL)

	rStream := registry.NewEtcdEventStream(eClient, cfg.EtcdKeyPrefix)

	ar := agent.NewReconciler(reg, rStream)

	e := engine.New(reg, rStream, mach)

	listeners, err := activation.Listeners(false)
	if err != nil {
		return nil, err
	}

	hrt := heart.New(reg, mach)
	mon := heart.NewMonitor(agentTTL)

	apiServer := api.NewServer(listeners, api.NewServeMux(reg))
	apiServer.Serve()

	eIval := time.Duration(cfg.EngineReconcileInterval*1000) * time.Millisecond

	srv := Server{
		agent:       a,
		aReconciler: ar,
		usGen:       gen,
		usPub:       pub,
		engine:      e,
		mach:        mach,
		hrt:         hrt,
		mon:         mon,
		api:         apiServer,
		stop:        nil,
		engineReconcileInterval: eIval,
	}

	return &srv, nil
}
开发者ID:ericcapricorn,项目名称:fleet,代码行数:70,代码来源:server.go

示例15: fleetAPI

func fleetAPI() fleet.API {
	if *fleetEndpoint == "" {
		glog.Fatalln("No --fleet-fleetEndpoint provided.")
	}
	var fleetClient fleet.API

	switch *fleetDriver {
	case "http":
		ep, err := url.Parse(*fleetEndpoint)
		if err != nil {
			glog.Fatal(err)
		}

		var trans http.RoundTripper

		switch ep.Scheme {
		case "unix", "file":
			// This commonly happens if the user misses the leading slash after the scheme.
			// For example, "unix://var/run/fleet.sock" would be parsed as host "var".
			if len(ep.Host) > 0 {
				glog.Fatalf("unable to connect to host %q with scheme %q\n", ep.Host, ep.Scheme)
			}

			// The Path field is only used for dialing and should not be used when
			// building any further HTTP requests.
			sockPath := ep.Path
			ep.Path = ""

			// http.Client doesn't support the schemes "unix" or "file", but it
			// is safe to use "http" as dialFunc ignores it anyway.
			ep.Scheme = "http"

			// The Host field is not used for dialing, but will be exposed in debug logs.
			ep.Host = "domain-sock"

			trans = &http.Transport{
				Dial: func(s, t string) (net.Conn, error) {
					// http.Client does not natively support dialing a unix domain socket, so the
					// dial function must be overridden.
					return net.Dial("unix", sockPath)
				},
			}
		case "http", "https":
			trans = http.DefaultTransport
		default:
			glog.Fatalf("Unknown scheme in fleet fleetEndpoint: %s\n", ep.Scheme)
		}

		c := &http.Client{
			Transport: trans,
		}

		fleetClient, err = fleet.NewHTTPClient(c, *ep)
		if err != nil {
			glog.Fatalf("Failed to create FleetHttpClient: %s\n", err)
		}
	case "etcd":
		// Code vaguely oriented on fleetctls getRegistryClient()
		// https://github.com/coreos/fleet/blob/2e21d3bfd5959a70513c5e0d3c2500dc3c0811cf/fleetctl/fleetctl.go#L312
		timeout := time.Duration(5 * time.Second)
		machines := strings.Split(*fleetEndpoint, ",")

		trans := &http.Transport{}

		eClient, err := etcd.NewClient(machines, trans, timeout)
		if err != nil {
			glog.Fatalln("Failed to build etcd client: " + err.Error())
		}

		reg := registry.NewEtcdRegistry(eClient, registry.DefaultKeyPrefix)
		fleetClient = &fleet.RegistryClient{reg}
	default:
		glog.Fatalf("Unknown fleet driver: %s\n", *fleetDriver)
	}
	glog.Infof("using fleet driver: %s with fleetEndpoint: %s", *fleetDriver, *fleetEndpoint)

	return fleetClient
}
开发者ID:giantswarm,项目名称:fleet-unit-replicator,代码行数:78,代码来源:main.go


注:本文中的github.com/coreos/fleet/registry.NewEtcdRegistry函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。