From 35b2a20749b1dc1cda0b5458a0662d00ba994f98 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Fri, 17 Sep 2021 15:09:33 -0500 Subject: [PATCH] Fix check ingress phase There is no check for retrieved $TARGET_IP address, which could cause false negative results in check ingress phase. Change-Id: Ibe0f3709cc5df111169aed33ceeff0595f6bcab1 Signed-off-by: Ruslan Aliev --- .../kubectl_check_ingress_ctrl.sh | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/manifests/function/phase-helpers/check_ingress_ctrl/kubectl_check_ingress_ctrl.sh b/manifests/function/phase-helpers/check_ingress_ctrl/kubectl_check_ingress_ctrl.sh index daa713dc1..df4d646e5 100644 --- a/manifests/function/phase-helpers/check_ingress_ctrl/kubectl_check_ingress_ctrl.sh +++ b/manifests/function/phase-helpers/check_ingress_ctrl/kubectl_check_ingress_ctrl.sh @@ -14,24 +14,40 @@ set -xe -export TARGET_IP=$(kubectl --context $KCTL_CONTEXT \ - --namespace ingress \ - get pods \ - -l app.kubernetes.io/component=controller \ - -o jsonpath='{.items[*].status.hostIP}') +export TIMEOUT=${TIMEOUT:-60} +end=$(($(date +%s) + $TIMEOUT)) +while true; do + export TARGET_IP="$(kubectl --request-timeout 10s \ + --context $KCTL_CONTEXT \ + --namespace ingress \ + get pods \ + -l app.kubernetes.io/component=controller \ + -o jsonpath='{.items[*].status.hostIP}')" + if [ ! -z $TARGET_IP ]; then + break + else + now=$(date +%s) + if [ $now -gt $end ]; then + echo "TARGET_IP is not ready before TIMEOUT=$TIMEOUT" 1>&2 + exit 1 + fi + sleep 10 + fi +done echo "Ensure we can reach ingress controller default backend" 1>&2 if [ "404" != "$(curl --head \ - --write-out '%{http_code}' \ - --silent \ - --output /dev/null \ - $TARGET_IP/should-404)" ]; then - echo "Failed to reach ingress controller default backend." 1>&2 + --write-out '%{http_code}' \ + --silent \ + --output /dev/null \ + $TARGET_IP/should-404)" ]; then + echo "Failed to reach ingress controller default backend." 1>&2 - kubectl --context $KCTL_CONTEXT get all -n flux-system 1>&2 - kubectl --context $KCTL_CONTEXT logs -n flux-system -l app=helm-controller 1>&2 - kubectl --context $KCTL_CONTEXT get hr --all-namespaces -o yaml 1>&2 + kubectl --context $KCTL_CONTEXT get all -n flux-system 1>&2 + kubectl --context $KCTL_CONTEXT logs -n flux-system -l app=helm-controller 1>&2 + kubectl --context $KCTL_CONTEXT get hr --all-namespaces -o yaml 1>&2 + kubectl --context $KCTL_CONTEXT --namespace ingress get pods -l app.kubernetes.io/component=controller -o yaml 1>&2 - exit 1 + exit 1 fi