Example #1
0
func removeUnusedEndpointsFromVulcand(client *vClient.Client, endpoints api.Endpoints) {

	name := endpoints.Name + "." + endpoints.Namespace

	backend, err := client.GetBackend(engine.BackendKey{Id: name})

	if err != nil {
		log.Println("Encountered error when getting backend to remove unused endpoints: " + err.Error())
		return
	}

	servers, err := client.GetServers(engine.BackendKey{Id: name})

	if err != nil {
		log.Println("Encountered error when getting servers to remove unused endpoints: " + err.Error())
		return
	}

	js, _ := json.Marshal(backend)
	log.Println(js)

	js, _ = json.Marshal(servers)
	log.Println(js)
}
Example #2
0
func ensureEndpointConfiguredForVulcand(client *vClient.Client, endpoints api.Endpoints) {

	name := endpoints.Name + "." + endpoints.Namespace

	backend := engine.Backend{Id: name, Type: "http",
		Settings: engine.HTTPBackendSettings{
			Timeouts:  engine.HTTPBackendTimeouts{Read: "5s", Dial: "5s", TLSHandshake: "10s"},
			KeepAlive: engine.HTTPBackendKeepAlive{Period: "30s", MaxIdleConnsPerHost: 12}}}

	err := client.UpsertBackend(backend)

	if err != nil {
		log.Println("Encountered error when creating backend in vulcand: " + err.Error())
	}

	// add servers to the backend
	for _, element := range endpoints.Subsets {
		for _, address := range element.Addresses {
			url := "http://" + address.IP + ":" + strconv.Itoa(element.Ports[0].Port)
			log.Println("Attempting to add server to backend " + backend.GetUniqueId().Id + " using url: " + url)
			err = client.UpsertServer(backend.GetUniqueId(), engine.Server{Id: url, URL: url}, time.Second*5)
			if err != nil {
				log.Println("Encountered error when adding server to backend: " + err.Error())
			}
		}
	}

	// make sure there's a frontend
	frontend := engine.Frontend{Id: name, Type: "http", Route: "Path(`/`)", BackendId: name}
	err = client.UpsertFrontend(frontend, time.Second*5)

	if err != nil {
		log.Println("Encountered error when creating frontend in vulcand: " + err.Error())
	}

}