Exemple #1
0
func (cmd *Command) Run(args []string) error {
	url, args, err := findVulcanUrl(args)
	if err != nil {
		return err
	}
	cmd.vulcanUrl = url
	cmd.client = api.NewClient(cmd.vulcanUrl, cmd.registry)

	app := cli.NewApp()
	app.Name = "vctl"
	app.Usage = "Command line interface to a running vulcan instance"
	app.Flags = flags()

	app.Commands = []cli.Command{
		NewLogCommand(cmd),
		NewKeyCommand(cmd),
		NewTopCommand(cmd),
		NewHostCommand(cmd),
		NewBackendCommand(cmd),
		NewFrontendCommand(cmd),
		NewServerCommand(cmd),
		NewListenerCommand(cmd),
	}
	app.Commands = append(app.Commands, NewMiddlewareCommands(cmd)...)
	return app.Run(args)
}
func NewRegistry(
	addr, backendID, serverID, ipAddress string, port uint,
	ttl time.Duration) *Registry {
	return &Registry{
		api.NewClient(addr, registry.GetRegistry()),
		backendID,
		serverID,
		fmt.Sprintf("http://%s:%d", ipAddress, port),
		ttl,
	}
}
Exemple #3
0
func createRouter(routerName, configPrefix string) (router.Router, error) {
	vURL, err := config.GetString(configPrefix + ":api-url")
	if err != nil {
		return nil, err
	}
	domain, err := config.GetString(configPrefix + ":domain")
	if err != nil {
		return nil, err
	}
	client := api.NewClient(vURL, registry.GetRegistry())
	vRouter := &vulcandRouter{
		client: client,
		prefix: configPrefix,
		domain: domain,
	}
	return vRouter, nil
}
Exemple #4
0
func main() {

	flag.Parse()
	log.Println("Connecting to kubernetes via url " + kServer)
	log.Println("Connecting to vulcand via url " + vServer)
	log.Println("Provided label query: " + labelQuery)
	log.Println("Observing endpoints within namespace: " + namespace)

	vClient := vClient.NewClient(vServer, vPlugin.NewRegistry())
	kClient, err := kClient.New(&kClient.Config{Host: kServer})

	if err != nil {
		log.Println("Error encountered when connecting to kubernetes api." + err.Error())
		panic(err)
	}

	var labelSelector labels.Selector = nil

	if labelQuery != "" {
		labelSelector, err = labels.Parse(labelQuery)
		if err != nil {
			log.Println("Error parsing the provided label query.")
			panic(err)
		}
	} else {
		labelSelector = labels.Everything()
	}

	socket, err := kClient.Endpoints(namespace).
		Watch(labelSelector, fields.Everything(), api.ListOptions{Watch: true})

	if err != nil {
		log.Println("Error obtaining a watch on the kubernetes endpoints.")
		panic(err)
	}

	// poll the channel indefinitely
	for {

		select {
		case event := <-socket.ResultChan():
			switch event.Type {
			case watch.Added:
				endpoint, _ := deserialize(event.Object)
				ensureEndpointConfiguredForVulcand(vClient, endpoint)
				log.Println("Endpoint was added: \n" + endpoint.Name)
			case watch.Modified:
				endpoint, _ := deserialize(event.Object)
				ensureEndpointConfiguredForVulcand(vClient, endpoint)
				log.Println("Endpoint was modified: \n" + endpoint.Name)
			case watch.Deleted:
				endpoint, _ := deserialize(event.Object)
				removeUnusedEndpointsFromVulcand(vClient, endpoint)
				log.Println("Endpoint was deleted: \n" + endpoint.Name)
			case watch.Error:
				log.Println("Encountered an error from the endpoints socket. Continuing...")
			}
		default:
			time.Sleep(1 * time.Second)
		}

	}

}