From 0cacc44fc94531a0824b6e3163ba428495fa3122 Mon Sep 17 00:00:00 2001 From: hasheddan Date: Mon, 11 May 2020 13:45:28 -0500 Subject: [PATCH 1/3] Retry resolving TCP address in agnhost/guestbook Currently the guestbook application will fail if unable to resolve TCP address on first attempt. If pod networking is not setup when the application starts then it will be unable to resolve, leading to frequent failures. This moves the address resolution into the retry block so it will try again if unsuccessful on first attempt. Signed-off-by: hasheddan --- test/images/agnhost/VERSION | 2 +- test/images/agnhost/agnhost.go | 2 +- test/images/agnhost/guestbook/guestbook.go | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION index 6d28a11dd0e..5c6fb54899b 100644 --- a/test/images/agnhost/VERSION +++ b/test/images/agnhost/VERSION @@ -1 +1 @@ -2.16 +2.17 diff --git a/test/images/agnhost/agnhost.go b/test/images/agnhost/agnhost.go index bbad09a51b0..618cde93bd0 100644 --- a/test/images/agnhost/agnhost.go +++ b/test/images/agnhost/agnhost.go @@ -49,7 +49,7 @@ import ( ) func main() { - rootCmd := &cobra.Command{Use: "app", Version: "2.16"} + rootCmd := &cobra.Command{Use: "app", Version: "2.17"} rootCmd.AddCommand(auditproxy.CmdAuditProxy) rootCmd.AddCommand(connect.CmdConnect) diff --git a/test/images/agnhost/guestbook/guestbook.go b/test/images/agnhost/guestbook/guestbook.go index 9c63e44b307..ab783517dd5 100644 --- a/test/images/agnhost/guestbook/guestbook.go +++ b/test/images/agnhost/guestbook/guestbook.go @@ -77,16 +77,18 @@ func registerNode(registerTo, port string) { } hostPort := net.JoinHostPort(registerTo, backendPort) - _, err := net.ResolveTCPAddr("tcp", hostPort) - if err != nil { - log.Fatalf("--slaveof param and/or --backend-port param are invalid. %v", err) - 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 { + _, err := net.ResolveTCPAddr("tcp", hostPort) + if err != nil { + log.Printf("--slaveof param and/or --backend-port param are invalid. %v. Retrying in 1 second.", err) + time.Sleep(sleep) + continue + } + response, err := dialHTTP(request, hostPort) if err != nil { log.Printf("encountered error while registering to master: %v. Retrying in 1 second.", err) From 9081dfb68d7ed067d88960d42936694b22e166e7 Mon Sep 17 00:00:00 2001 From: hasheddan Date: Tue, 12 May 2020 09:57:39 -0500 Subject: [PATCH 2/3] Improve error messages in agnhost/guestbook This updates the error messages when registering a node to be more explicit about what error occurred and how long it will wait to retry. Signed-off-by: hasheddan --- test/images/agnhost/guestbook/guestbook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/images/agnhost/guestbook/guestbook.go b/test/images/agnhost/guestbook/guestbook.go index ab783517dd5..42e8a015992 100644 --- a/test/images/agnhost/guestbook/guestbook.go +++ b/test/images/agnhost/guestbook/guestbook.go @@ -84,14 +84,14 @@ func registerNode(registerTo, port string) { for time.Since(start) < timeout { _, err := net.ResolveTCPAddr("tcp", hostPort) if err != nil { - log.Printf("--slaveof param and/or --backend-port param are invalid. %v. Retrying in 1 second.", err) + log.Printf("unable to resolve %s, --slaveof param and/or --backend-port param are invalid: %v. Retrying in %s.", hostPort, err, sleep) time.Sleep(sleep) continue } response, err := dialHTTP(request, hostPort) if err != nil { - log.Printf("encountered error while registering to master: %v. Retrying in 1 second.", err) + log.Printf("encountered error while registering to master: %v. Retrying in %s.", err, sleep) time.Sleep(sleep) continue } From 921b76ceaa90059d94044093e3426cc9836a6b1e Mon Sep 17 00:00:00 2001 From: hasheddan Date: Tue, 12 May 2020 13:55:17 -0500 Subject: [PATCH 3/3] Move getting IP address into retry loop for agnhost/guestbook Removes the fatal error from getIP and moves it to retry loop so that application will not immediately crash on failure. Signed-off-by: hasheddan --- test/images/agnhost/guestbook/guestbook.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/images/agnhost/guestbook/guestbook.go b/test/images/agnhost/guestbook/guestbook.go index 42e8a015992..adca83e1438 100644 --- a/test/images/agnhost/guestbook/guestbook.go +++ b/test/images/agnhost/guestbook/guestbook.go @@ -78,11 +78,18 @@ func registerNode(registerTo, port string) { hostPort := net.JoinHostPort(registerTo, backendPort) - 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 { - _, err := net.ResolveTCPAddr("tcp", hostPort) + host, err := getIP(hostPort) + if err != nil { + log.Printf("unable to get IP %s: %v. Retrying in %s.", hostPort, err, sleep) + time.Sleep(sleep) + continue + } + + request := fmt.Sprintf("register?host=%s", host.String()) + log.Printf("Registering to master: %s/%s", hostPort, request) + _, err = net.ResolveTCPAddr("tcp", hostPort) if err != nil { log.Printf("unable to resolve %s, --slaveof param and/or --backend-port param are invalid: %v. Retrying in %s.", hostPort, err, sleep) time.Sleep(sleep) @@ -287,13 +294,13 @@ func createHTTPClient(transport *http.Transport) *http.Client { return client } -func getIP(hostPort string) net.IP { +func getIP(hostPort string) (net.IP, error) { conn, err := net.Dial("udp", hostPort) if err != nil { - log.Fatal(err) + return []byte{}, err } defer conn.Close() localAddr := conn.LocalAddr().(*net.UDPAddr) - return localAddr.IP + return localAddr.IP, nil }