コード例 #1
0
func newVulcandServer(ip string, port int) (*vulcand.Server, error) {
	serverURL, err := url.Parse(fmt.Sprintf("http://%v:%v/", ip, port))
	if err != nil {
		return nil, err
	}
	return vulcand.NewServer(ip, serverURL.String())
}
コード例 #2
0
ファイル: testutils.go プロジェクト: davemkirk/vulcand
func MakeServer(url string) engine.Server {
	s, err := engine.NewServer(UID("server"), url)
	if err != nil {
		panic(err)
	}
	return *s
}
コード例 #3
0
ファイル: server.go プロジェクト: davemkirk/vulcand
func (cmd *Command) upsertServerAction(c *cli.Context) {
	s, err := engine.NewServer(c.String("id"), c.String("url"))
	if err != nil {
		cmd.printError(err)
		return
	}
	if err := cmd.client.UpsertServer(engine.BackendKey{Id: c.String("backend")}, *s, c.Duration("ttl")); err != nil {
		cmd.printError(err)
		return
	}
	cmd.printOk("server upserted")
}
コード例 #4
0
ファイル: router.go プロジェクト: RichardKnop/tsuru
func (r *vulcandRouter) AddRoute(name string, address *url.URL) error {
	usedName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	serverKey := engine.ServerKey{
		Id:         r.serverName(address.String()),
		BackendKey: engine.BackendKey{Id: r.backendName(usedName)},
	}
	if found, _ := r.client.GetServer(serverKey); found != nil {
		return router.ErrRouteExists
	}
	server, err := engine.NewServer(serverKey.Id, address.String())
	if err != nil {
		return err
	}
	return r.client.UpsertServer(serverKey.BackendKey, *server, engine.NoTTL)
}
コード例 #5
0
func (kv *kube2vulcand) newService(obj interface{}) {
	if s, ok := obj.(*kapi.Service); ok {
		// We only care about external services, which are declared as LoadBalancer (because they cloudprovider to make one)
		if s.Spec.Type == kapi.ServiceTypeLoadBalancer {
			// TODO: refactor to use the same KubeClient as the service poller ?
			kubeClient, err := newKubeClient()
			if err != nil {
				glog.Errorf("Failed to create a kubernetes client: %v", err)
				return
			}
			nodesList, err := kubeClient.Nodes().List(kLabel.Everything(), kSelector.Everything())
			if err != nil {
				glog.Errorf("Failed get nodes list: %v", err)
				return
			}
			nodes := nodesList.Items
			instances := []instance{}
			for _, port := range s.Spec.Ports {
				if port.Protocol != kapi.ProtocolTCP {
					continue
				}
				var instanceName string
				if port.Name == "" {
					instanceName = s.Name
				} else {
					instanceName = port.Name + "." + s.Name
				}
				currentInstance := instance{
					Name: instanceName,
				}
				for _, node := range nodes {
					// POPO
					url := fmt.Sprintf("http://%s:%d", node.Status.Addresses[0].Address, port.NodePort)
					s := vulcandServer{
						URL:  url,
						Name: getHash(url),
					}
					currentInstance.Servers = append(currentInstance.Servers, s)
				}
				instances = append(instances, currentInstance)
			}
			for _, i := range instances {
				if err := kv.addVulcandBackend(i); err != nil {
					glog.Errorf("Failed to add Vulcand Backend : ", err)
				}
				if err := kv.addVulcandFrontend(i); err != nil {
					glog.Errorf("Failed to add Vulcand Frontend : ", err)
				}
				for _, server := range i.Servers {
					srv, err := vulcandng.NewServer(server.Name, server.URL)
					if err != nil {
						glog.Errorf("Failed to create a Vulcand server", err)
						continue
					}
					if err := kv.vulcandClient.UpsertServer(vulcandng.BackendKey{Id: i.Name}, *srv, 0); err != nil {
						glog.Errorf("Failed to create Vulcand Server : ", err)
					}
				}
			}
		}
	}
}