test images: Updates agnhost guestbook

A previous PR replaced the usage of Redis in the guestbook app test
with Agnhost. The replacement went well for Linux setups and Containers,
which is why the tests are green, but there is a network particularity on
Windows setups which won't allow the test to pass.

The issue was observed with another test hitting the same issue:
https://github.com/kubernetes/kubernetes/issues/83072

Here's exactly what happens during the test:

- frontend containers are created, having the /guestbook endpoint. Its main
  purpose is to forward the call to either agnhost-master (cmd=set), or
  agnhost-slave (cmd=get).
- agnhost-master container is created, having the /set endpoint, and the
  /register endpoint, through which the agnhost-slave containers would
  register to it. Its purpose is to propagate all data received through /set
  to its clients.
- agnhost-slave containers are created, having the /set and /get endpoints.
  They would register to agnhost-master, and then receive any and all updates
  from it, which was then served through the /get endpoint.

For simplicity, all 3 types have the same agnhost subcommand (agnhost guestbook), being
able to satisfy its given purpose. For this, HTTP servers were being used, including
for the /register endpoints. agnhost-master would send its /set updates as /set HTTP
requests. However, because of the issue listed above, agnhost-master did not receive
the client's IP, but rather the container host's IP, resulting in the request being
sent to the wrong destination.

This PR updates the agnhost guestbook subcommand. Now, the agnhost subscriber nodes will
send their own IP to the /register endpoint (/endpoint?host=myip).
This commit is contained in:
Claudiu Belu 2019-11-19 19:53:51 -08:00
parent 79e1ad2f4b
commit 8cb84feef3

View File

@ -83,9 +83,11 @@ func registerNode(registerTo, port string) {
return
}
request := fmt.Sprintf("register?host=%s", getIP(hostPort).String())
log.Printf("Registering to master: %s/%s", hostPort, request)
start := time.Now()
for time.Since(start) < timeout {
response, err := dialHTTP("register", hostPort)
response, err := dialHTTP(request, hostPort)
if err != nil {
log.Printf("encountered error while registering to master: %v. Retrying in 1 second.", err)
time.Sleep(sleep)
@ -121,12 +123,14 @@ func startHTTPServer(port string) {
// registerHandler will register the caller in this server's list of slaves.
// /set requests will be propagated to slaves, if any.
func registerHandler(w http.ResponseWriter, r *http.Request) {
ip, _, err := net.SplitHostPort(r.RemoteAddr)
values, err := url.Parse(r.URL.RequestURI())
if err != nil {
fmt.Fprintf(w, "userip: %q is not IP:port", r.RemoteAddr)
http.Error(w, fmt.Sprintf("%v", err), http.StatusBadRequest)
return
}
log.Printf("GET /register, IP: %s", ip)
ip := values.Query().Get("host")
log.Printf("GET /register?host=%s", ip)
// send all the store to the slave as well.
output := make(map[string]interface{})
@ -280,3 +284,14 @@ func createHTTPClient(transport *http.Transport) *http.Client {
}
return client
}
func getIP(hostPort string) net.IP {
conn, err := net.Dial("udp", hostPort)
if err != nil {
log.Fatal(err)
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP
}