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..d3cb7b7acce8 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,27 @@ function wait_until_pods_running() { return 1 } +# 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 + 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() {