From 5e90cb51d8ad107c1b83f9e7d86f65bf7366d3eb Mon Sep 17 00:00:00 2001 From: Brendon Lloyd <blloyd@revacomm.com> Date: Fri, 24 Sep 2021 09:57:18 -1000 Subject: [PATCH] Trap ERR signals and print the script currently running, the line number, and the command that failed before exiting. --- docs/airgap/scripts/deploy-images.sh | 1 + docs/airgap/scripts/package_images.sh | 1 + docs/airgap/scripts/registry.sh | 1 + scripts/hosts.sh | 1 + scripts/install_flux.sh | 1 + scripts/package/gits.sh | 1 + tests/ci/k3d/deploy_k3d.sh | 1 + tests/ci/k3d/metallb/install_metallb.sh | 1 + tests/deploy/00_deploy_flux.sh | 1 + tests/deploy/01_deploy_bigbang.sh | 1 + tests/deploy/02_wait_for_helmreleases.sh | 1 + tests/tests/01_virtualservices.sh | 1 + tests/tests/02_non_ironbank.sh | 1 + tests/tests/03_helm_tests.sh | 1 + 14 files changed, 14 insertions(+) diff --git a/docs/airgap/scripts/deploy-images.sh b/docs/airgap/scripts/deploy-images.sh index 684cab8c5d..181386e4ae 100644 --- a/docs/airgap/scripts/deploy-images.sh +++ b/docs/airgap/scripts/deploy-images.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR REGISTRY_PACKAGE_IMAGE="registry:package" REGISTRY_PACKAGE_TGZ="${REGISTRY_PACKAGE_IMAGE}.tar.gz" diff --git a/docs/airgap/scripts/package_images.sh b/docs/airgap/scripts/package_images.sh index 1d67e3026c..a792acc82f 100644 --- a/docs/airgap/scripts/package_images.sh +++ b/docs/airgap/scripts/package_images.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR IMAGES_TXT="images.txt" REGISTRY_IMAGE="registry:2" diff --git a/docs/airgap/scripts/registry.sh b/docs/airgap/scripts/registry.sh index c277cd051b..c69864cf62 100644 --- a/docs/airgap/scripts/registry.sh +++ b/docs/airgap/scripts/registry.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR # Installs/Configures: # - Docker Registy Container with self-signed cert diff --git a/scripts/hosts.sh b/scripts/hosts.sh index 6e033a257c..393453906b 100755 --- a/scripts/hosts.sh +++ b/scripts/hosts.sh @@ -1,5 +1,6 @@ #!/bin/bash set -e +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR ## Adds all the vs hostnames and LB IP to /etc/hosts ## Get the LB Hostname diff --git a/scripts/install_flux.sh b/scripts/install_flux.sh index 5908126789..339354f5b0 100755 --- a/scripts/install_flux.sh +++ b/scripts/install_flux.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR # # global defaults diff --git a/scripts/package/gits.sh b/scripts/package/gits.sh index 44e0caec23..1ab383e5a7 100755 --- a/scripts/package/gits.sh +++ b/scripts/package/gits.sh @@ -1,5 +1,6 @@ #!/bin/bash set -ex +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR mkdir -p repos/ diff --git a/tests/ci/k3d/deploy_k3d.sh b/tests/ci/k3d/deploy_k3d.sh index 0b436bfe92..eb184a964f 100644 --- a/tests/ci/k3d/deploy_k3d.sh +++ b/tests/ci/k3d/deploy_k3d.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -ex +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR # if keycloak label or all packages label add deploy k3d without loadbalancer so metallb can be used if [[ "${CI_COMMIT_BRANCH}" == "${CI_DEFAULT_BRANCH}" ]] || [[ ! -z "$CI_COMMIT_TAG" ]] || [[ $CI_MERGE_REQUEST_LABELS =~ "keycloak" || $CI_MERGE_REQUEST_LABELS =~ "all-packages" ]]; then k3d cluster create ${CI_JOB_ID} --config tests/ci/k3d/disable-servicelb-config.yaml --network ${CI_JOB_ID} diff --git a/tests/ci/k3d/metallb/install_metallb.sh b/tests/ci/k3d/metallb/install_metallb.sh index d60e34f550..38b8d4871f 100644 --- a/tests/ci/k3d/metallb/install_metallb.sh +++ b/tests/ci/k3d/metallb/install_metallb.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -ex +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR if [[ "${CI_COMMIT_BRANCH}" == "${CI_DEFAULT_BRANCH}" ]] || [[ ! -z "$CI_COMMIT_TAG" ]] || [[ $CI_MERGE_REQUEST_LABELS =~ "keycloak" || $CI_MERGE_REQUEST_LABELS =~ "all-packages" ]]; then kubectl create -f tests/ci/k3d/metallb/metallb.yaml diff --git a/tests/deploy/00_deploy_flux.sh b/tests/deploy/00_deploy_flux.sh index 7c507dfe56..2eb7acd800 100644 --- a/tests/deploy/00_deploy_flux.sh +++ b/tests/deploy/00_deploy_flux.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -ex +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR # install flux with the dedicated helper script ./scripts/install_flux.sh \ diff --git a/tests/deploy/01_deploy_bigbang.sh b/tests/deploy/01_deploy_bigbang.sh index f048aa34be..9ff17762c9 100755 --- a/tests/deploy/01_deploy_bigbang.sh +++ b/tests/deploy/01_deploy_bigbang.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -ex +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR if [[ "${CI_COMMIT_BRANCH}" == "${CI_DEFAULT_BRANCH}" ]] || [[ ! -z "$CI_COMMIT_TAG" ]] || [[ $CI_MERGE_REQUEST_LABELS =~ "all-packages" ]]; then echo "all-packages label enabled, or on default branch or tag, enabling all addons" diff --git a/tests/deploy/02_wait_for_helmreleases.sh b/tests/deploy/02_wait_for_helmreleases.sh index 7110d25765..9e6fe34d49 100755 --- a/tests/deploy/02_wait_for_helmreleases.sh +++ b/tests/deploy/02_wait_for_helmreleases.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR ## Array of core HRs CORE_HELMRELEASES=("gatekeeper" "istio-operator" "istio" "monitoring" "eck-operator" "ek" "fluent-bit" "twistlock" "cluster-auditor" "jaeger" "kiali") diff --git a/tests/tests/01_virtualservices.sh b/tests/tests/01_virtualservices.sh index c0d2004727..466b104da1 100755 --- a/tests/tests/01_virtualservices.sh +++ b/tests/tests/01_virtualservices.sh @@ -2,6 +2,7 @@ # exit on error set -e +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR # Populate /etc/hosts ip=$(kubectl -n istio-system get service public-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') diff --git a/tests/tests/02_non_ironbank.sh b/tests/tests/02_non_ironbank.sh index b67d7e81fc..110f09ccdc 100755 --- a/tests/tests/02_non_ironbank.sh +++ b/tests/tests/02_non_ironbank.sh @@ -2,6 +2,7 @@ # exit on error set -e +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR # Quick check for non iron bank images echo "Showing images not from ironbank:" diff --git a/tests/tests/03_helm_tests.sh b/tests/tests/03_helm_tests.sh index e91c99b27f..d92fd6b087 100755 --- a/tests/tests/03_helm_tests.sh +++ b/tests/tests/03_helm_tests.sh @@ -2,6 +2,7 @@ # exit on error set -e +trap 'echo exit at ${0}:${LINENO}, command was: ${BASH_COMMAND} 1>&2' ERR # Check clusterType and get original CoreDNS config clusterType="unknown" -- GitLab