From df6ccc32c3ad082a4b92b29dc6b966b947ab67a4 Mon Sep 17 00:00:00 2001 From: Nghia Tran Date: Fri, 29 Jun 2018 15:45:52 -0700 Subject: [PATCH 1/2] Integreation tests waits for external IP of knative-ingressgateway. --- test/e2e-tests.sh | 1 + test/library.sh | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index bf21ddba9c66..1d5afa92cadf 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -292,6 +292,7 @@ set +o pipefail wait_until_pods_running knative-serving wait_until_pods_running istio-system +wait_until_service_has_external_ip istio-system knative-ingressgateway abort_if_failed # Run the tests diff --git a/test/library.sh b/test/library.sh index 0b2baccba0ec..f5c30ce22d2d 100755 --- a/test/library.sh +++ b/test/library.sh @@ -80,10 +80,11 @@ function delete_gcr_images() { # Parameters: $1 - namespace. function wait_until_pods_running() { echo -n "Waiting until all pods in namespace $1 are up" + local ns=$1 for i in {1..150}; do # timeout after 5 minutes + local has_pending=$(kubectl get pods -n $ns -o jsonpath='{.items[*].status.phase}' | grep Pending) local pods="$(kubectl get pods -n $1 2>/dev/null | grep -v NAME)" - local not_running=$(echo "${pods}" | grep -v Running | wc -l) - if [[ -n "${pods}" && ${not_running} == 0 ]]; then + if [[ -n "${pods}" && -z ${has_pending} ]]; then echo -e "\nAll pods are up:" kubectl get pods -n $1 return 0 @@ -96,6 +97,25 @@ function wait_until_pods_running() { return 1 } +# Waits until the given service has an external IP address. +function wait_until_service_has_external_ip() { + local ns=$1 + local svc=$2 + echo -n "Waiting until service $svc in namespace $ns has an external IP" + for i in {1..150}; do # timeout after 15 minutes + local ip=$(kubectl get svc -n $ns $svc -o jsonpath="{.status.loadBalancer.ingress[0].ip}") + if [[ -n "${ip}" ]]; then + echo -e "\nService $svc.$ns has IP $ip" + return 0 + fi + echo -n "." + sleep 6 + done + echo -e "\n\nERROR: timeout waiting for service $svc.$ns to have external IP" + kubectl get pods -n $1 + return 1 +} + # Returns the name of the Knative Serving pod of the given app. # Parameters: $1 - Knative Serving app name. function get_knative_pod() { From ededf39ecd8d34ac1350126ce6c9d40df0e0c98b Mon Sep 17 00:00:00 2001 From: Nghia Tran Date: Fri, 29 Jun 2018 16:17:04 -0700 Subject: [PATCH 2/2] Update per PR feedback. --- test/library.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/library.sh b/test/library.sh index f5c30ce22d2d..d3cb7b7acce8 100755 --- a/test/library.sh +++ b/test/library.sh @@ -80,11 +80,11 @@ function delete_gcr_images() { # Parameters: $1 - namespace. function wait_until_pods_running() { echo -n "Waiting until all pods in namespace $1 are up" - local ns=$1 + local ns="$1" for i in {1..150}; do # timeout after 5 minutes - local has_pending=$(kubectl get pods -n $ns -o jsonpath='{.items[*].status.phase}' | grep Pending) + local has_pending="$(kubectl get pods -n $ns -o jsonpath='{.items[*].status.phase}' | grep Pending)" local pods="$(kubectl get pods -n $1 2>/dev/null | grep -v NAME)" - if [[ -n "${pods}" && -z ${has_pending} ]]; then + if [[ -n "${pods}" && -z "${has_pending}" ]]; then echo -e "\nAll pods are up:" kubectl get pods -n $1 return 0 @@ -98,6 +98,8 @@ function wait_until_pods_running() { } # Waits until the given service has an external IP address. +# Parameters: $1 - namespace. +# Parameters: $2 - service name. function wait_until_service_has_external_ip() { local ns=$1 local svc=$2