From 91083a6b4ea61571281b2917524f1cc5fc05db35 Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Wed, 26 Apr 2023 16:17:29 +0200 Subject: [PATCH] Add post-install scripts to all tests to capture failure details in GitHub workflow summary (#88) --- .github/tests/common.sh | 69 +++++++++++++++++++ .github/tests/extras/post-install.sh | 17 +++++ .../post-install.sh | 17 +++++ .../tests/namespace-override/post-install.sh | 62 +++-------------- .../post-install.sh | 17 +++++ .github/tests/production-example/install.sh | 4 +- .../tests/production-example/post-install.sh | 53 ++------------ .github/tests/prometheus/post-install.sh | 17 +++++ .github/tests/prometheus/pre-install.sh | 10 ++- .../tests/spire-oidc-insecure/post-install.sh | 17 +++++ .../tests/spire-oidc-insecure/pre-install.sh | 4 +- .../post-install.sh | 17 +++++ .../pre-install.sh | 4 +- .../upstream-authority-disk/post-install.sh | 17 +++++ .github/workflows/scripts/update-versions.sh | 4 +- 15 files changed, 220 insertions(+), 109 deletions(-) create mode 100755 .github/tests/common.sh create mode 100644 .github/tests/extras/post-install.sh create mode 100644 .github/tests/federation-bundle-endpoint/post-install.sh create mode 100644 .github/tests/no-spire-controller-manager/post-install.sh create mode 100644 .github/tests/prometheus/post-install.sh create mode 100644 .github/tests/spire-oidc-insecure/post-install.sh create mode 100755 .github/tests/upstream-authority-cert-manager/post-install.sh create mode 100755 .github/tests/upstream-authority-disk/post-install.sh diff --git a/.github/tests/common.sh b/.github/tests/common.sh new file mode 100755 index 0000000..c550721 --- /dev/null +++ b/.github/tests/common.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +get_namespace_details () { +cat <>"$GITHUB_STEP_SUMMARY" +### Namespace $1 + +#### Events + +\`\`\`shell +$(kubectl --request-timeout=30s get events --output wide --namespace "$1") +\`\`\` + +#### Pods + +\`\`\`shell +$(kubectl --request-timeout=30s describe pods --namespace "$1") +\`\`\` + +#### Logs + +\`\`\`shell +$(kubectl get pods -o name -n "$1" | while read -r line; do echo logs for "${line}"; kubectl logs -n "$1" "${line}" --all-containers=true --ignore-errors=true; done) +\`\`\` + +EOF +} + +k_wait () { + kubectl wait --for condition=available --timeout 30s --namespace "$1" "$2" "$3" | tail -n 1 +} + +k_rollout_status () { + kubectl rollout status --watch --timeout 30s --namespace "$1" "$2" "$3" | tail -n 1 +} + +get_spire_release_name () { + helm ls -A | grep '^spire' | awk '{print $1}' +} + +print_spire_workload_status () { + local ns1 + local ns2 + + ns1="$1" + ns2="${2:-$1}" + + release_name="$(get_spire_release_name)" + + cat <>"$GITHUB_STEP_SUMMARY" +### Spire + +| Namespace | Workload | Status | +| --------- | ---------------------------------------------- | ------ | +| ${ns1} | ${release_name}-server |
$(k_rollout_status "${ns1}" statefulset "${release_name}-server")
| +| ${ns2} | ${release_name}-spiffe-csi-driver |
$(k_rollout_status "${ns2}" daemonset "${release_name}-spiffe-csi-driver")
| +| ${ns2} | ${release_name}-agent |
$(k_rollout_status "${ns2}" daemonset "${release_name}-agent")
| +| ${ns1} | ${release_name}-spiffe-oidc-discovery-provider |
$(k_rollout_status "${ns1}" deployments.apps "${release_name}-spiffe-oidc-discovery-provider")
| + +EOF +} + +print_helm_releases () { + cat <>"$GITHUB_STEP_SUMMARY" +### Releases + +$(helm ls -A | sed 's/\t/ | /g' | sed 's/^/| /' | sed 's/$/ |/' | sed '/^| NAME.*/a| - | - | - | - | - | - | - |') + +EOF +} diff --git a/.github/tests/extras/post-install.sh b/.github/tests/extras/post-install.sh new file mode 100644 index 0000000..1278f29 --- /dev/null +++ b/.github/tests/extras/post-install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" + +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" + +print_helm_releases +print_spire_workload_status "${scenario}" + +if [[ "$1" -ne 0 ]]; then + get_namespace_details "${scenario}" +fi diff --git a/.github/tests/federation-bundle-endpoint/post-install.sh b/.github/tests/federation-bundle-endpoint/post-install.sh new file mode 100644 index 0000000..1278f29 --- /dev/null +++ b/.github/tests/federation-bundle-endpoint/post-install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" + +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" + +print_helm_releases +print_spire_workload_status "${scenario}" + +if [[ "$1" -ne 0 ]]; then + get_namespace_details "${scenario}" +fi diff --git a/.github/tests/namespace-override/post-install.sh b/.github/tests/namespace-override/post-install.sh index 09feb6b..7fbaf11 100755 --- a/.github/tests/namespace-override/post-install.sh +++ b/.github/tests/namespace-override/post-install.sh @@ -2,60 +2,18 @@ set -x -SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "${SCRIPT}") +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" scenario="${scenario:-$(basename "${SCRIPTPATH}")}" -k_wait () { - kubectl wait --for condition=available --timeout 30s --namespace "$1" "$2" "$3" | tail -n 1 -} +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" -k_rollout_status () { - kubectl rollout status --watch --timeout 30s --namespace "$1" "$2" "$3" | tail -n 1 -} - -RELEASE=$(helm ls --no-headers -n "${scenario}" | awk '{print $1}' | grep 'spire-[^-]*$') - -cat <>"$GITHUB_STEP_SUMMARY" -### release -| release | -| ------- | -| $RELEASE | - -### spire -| workload | Status | -| -------- | ------ | -| spire-server |
$(k_rollout_status spire-server statefulset "${RELEASE}-server")
| -| spire-spiffe-csi-driver |
$(k_rollout_status spire-system daemonset "${RELEASE}-spiffe-csi-driver")
| -| spire-agent |
$(k_rollout_status spire-system daemonset "${RELEASE}-agent")
| -| spire-spiffe-oidc-discovery-provider |
$(k_wait spire-server deployments.apps "${RELEASE}-spiffe-oidc-discovery-provider")
| -EOF +print_helm_releases +print_spire_workload_status spire-server spire-system if [[ "$1" -ne 0 ]]; then - echo - echo '```' - echo '==> Events of namespace spire-server' - echo '........................................................................................................................' - echo '>>> kubectl --request-timeout=30s get events --output wide --namespace spire-server' - kubectl --request-timeout=30s get events --output wide --namespace spire-server - echo '........................................................................................................................' - echo '<== Events of namespace spire-server' - echo '........................................................................................................................' - echo '>>> kubectl --request-timeout=30s describe pods --namespace spire-server' - kubectl --request-timeout=30s describe pods --namespace spire-server - echo '========================================================================================================================' - echo '==> Events of namespace spire-system' - echo '........................................................................................................................' - echo '>>> kubectl --request-timeout=30s get events --output wide --namespace spire-system' - kubectl --request-timeout=30s get events --output wide --namespace spire-system - echo '........................................................................................................................' - echo '<== Events of namespace spire-system' - echo '........................................................................................................................' - echo '>>> kubectl --request-timeout=30s describe pods --namespace spire-system' - kubectl --request-timeout=30s describe pods --namespace spire-system - echo '========================================================================================================================' - kubectl get pods -o name -n spire-server | while read -r line; do echo logs for "${line}"; kubectl logs -n spire-server "${line}"--all-containers=true --ignore-errors=true; done - kubectl get pods -o name -n spire-system | while read -r line; do echo logs for "${line}"; kubectl logs -n spire-system "${line}" --all-containers=true --ignore-errors=true; done - echo '========================================================================================================================' - echo '```' -fi | cat >> "$GITHUB_STEP_SUMMARY" + get_namespace_details spire-server + get_namespace_details spire-systen +fi + diff --git a/.github/tests/no-spire-controller-manager/post-install.sh b/.github/tests/no-spire-controller-manager/post-install.sh new file mode 100644 index 0000000..1278f29 --- /dev/null +++ b/.github/tests/no-spire-controller-manager/post-install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" + +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" + +print_helm_releases +print_spire_workload_status "${scenario}" + +if [[ "$1" -ne 0 ]]; then + get_namespace_details "${scenario}" +fi diff --git a/.github/tests/production-example/install.sh b/.github/tests/production-example/install.sh index 442a97b..c2b5cfe 100755 --- a/.github/tests/production-example/install.sh +++ b/.github/tests/production-example/install.sh @@ -2,8 +2,8 @@ set -xe -SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "$SCRIPT") +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" helm install \ --namespace spire-server \ diff --git a/.github/tests/production-example/post-install.sh b/.github/tests/production-example/post-install.sh index 1f78c43..29335e6 100755 --- a/.github/tests/production-example/post-install.sh +++ b/.github/tests/production-example/post-install.sh @@ -2,56 +2,17 @@ set -x -SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "${SCRIPT}") +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" scenario="${scenario:-$(basename "${SCRIPTPATH}")}" -k_wait () { - kubectl wait --for condition=available --timeout 30s --namespace "$1" "$2" "$3" | tail -n 1 -} +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" -k_rollout_status () { - kubectl rollout status --watch --timeout 30s --namespace "$1" "$2" "$3" | tail -n 1 -} - -function get_namespace_details { -cat <>"$GITHUB_STEP_SUMMARY" -### Namespace $1 - -#### Events - -\`\`\`shell -$(kubectl --request-timeout=30s get events --output wide --namespace "$1") -\`\`\` - -#### Pods - -\`\`\`shell -$(kubectl --request-timeout=30s describe pods --namespace "$1") -\`\`\` - -#### Logs - -\`\`\`shell -$(kubectl get pods -o name -n "$1" | while read -r line; do echo logs for "${line}"; kubectl logs -n "$1" "${line}" --all-containers=true --ignore-errors=true; done) -\`\`\` - -EOF -} - -cat <>"$GITHUB_STEP_SUMMARY" -### spire - -| workload | Status | -| ------------------------------------ | ------ | -| spire-server | "$(k_rollout_status spire-server statefulset spire-server)" | -| spire-controller-manager | "$(k_rollout_status spire-server statefulset spire-controller-manager)" | -| spire-spiffe-oidc-discovery-provider | "$(k_wait spire-server deployments.apps spire-spiffe-oidc-discovery-provider)" | -| spire-spiffe-csi-driver | "$(k_rollout_status spire-system daemonset spire-spiffe-csi-driver)" | -| spire-agent | "$(k_rollout_status spire-system daemonset spire-agent)" | -EOF +print_helm_releases +print_spire_workload_status spire-server spire-system if [[ "$1" -ne 0 ]]; then get_namespace_details spire-server - get_namespace_details spire-systen + get_namespace_details spire-system fi diff --git a/.github/tests/prometheus/post-install.sh b/.github/tests/prometheus/post-install.sh new file mode 100644 index 0000000..1278f29 --- /dev/null +++ b/.github/tests/prometheus/post-install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" + +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" + +print_helm_releases +print_spire_workload_status "${scenario}" + +if [[ "$1" -ne 0 ]]; then + get_namespace_details "${scenario}" +fi diff --git a/.github/tests/prometheus/pre-install.sh b/.github/tests/prometheus/pre-install.sh index 9057040..e63cb46 100755 --- a/.github/tests/prometheus/pre-install.sh +++ b/.github/tests/prometheus/pre-install.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash -SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "${SCRIPT}") +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" scenario="${scenario:-$(basename "${SCRIPTPATH}")}" -helm install kube-prometheus-stack kube-prometheus-stack --version "${VERSION_KUBE_PROMETHEUS_STACK}" --repo "${HELM_REPO_KUBE_PROMETHEUS_STACK}" -n "${scenario}" --wait +helm install kube-prometheus-stack kube-prometheus-stack \ + --version "${VERSION_KUBE_PROMETHEUS_STACK}" \ + --repo "${HELM_REPO_KUBE_PROMETHEUS_STACK}" \ + -n "${scenario}" \ + --wait diff --git a/.github/tests/spire-oidc-insecure/post-install.sh b/.github/tests/spire-oidc-insecure/post-install.sh new file mode 100644 index 0000000..1278f29 --- /dev/null +++ b/.github/tests/spire-oidc-insecure/post-install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" + +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" + +print_helm_releases +print_spire_workload_status "${scenario}" + +if [[ "$1" -ne 0 ]]; then + get_namespace_details "${scenario}" +fi diff --git a/.github/tests/spire-oidc-insecure/pre-install.sh b/.github/tests/spire-oidc-insecure/pre-install.sh index 2433e0e..d27cc96 100755 --- a/.github/tests/spire-oidc-insecure/pre-install.sh +++ b/.github/tests/spire-oidc-insecure/pre-install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "${SCRIPT}") +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" scenario="${scenario:-$(basename "${SCRIPTPATH}")}" helm install ingress-nginx ingress-nginx --version "${VERSION_INGRESS_NGINX}" --repo "${HELM_REPO_INGRESS_NGINX}" -n "$scenario" --set controller.extraArgs.enable-ssl-passthrough= diff --git a/.github/tests/upstream-authority-cert-manager/post-install.sh b/.github/tests/upstream-authority-cert-manager/post-install.sh new file mode 100755 index 0000000..9ef78ac --- /dev/null +++ b/.github/tests/upstream-authority-cert-manager/post-install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +SCRIPT=$(readlink -f "$0") +SCRIPTPATH="$(dirname "${SCRIPT}")" +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" + +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" + +print_helm_releases +print_spire_workload_status "${scenario}" + +if [ "$1" != '0' ]; then + get_namespace_details "${scenario}" +fi diff --git a/.github/tests/upstream-authority-cert-manager/pre-install.sh b/.github/tests/upstream-authority-cert-manager/pre-install.sh index 1e1f8b2..9508f5d 100755 --- a/.github/tests/upstream-authority-cert-manager/pre-install.sh +++ b/.github/tests/upstream-authority-cert-manager/pre-install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "${SCRIPT}") +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" scenario="${scenario:-$(basename "${SCRIPTPATH}")}" helm install cert-manager cert-manager --namespace cert-manager --create-namespace --version "$VERSION_CERT_MANAGER" --set installCRDs=true --repo "$HELM_REPO_CERT_MANAGER" --wait diff --git a/.github/tests/upstream-authority-disk/post-install.sh b/.github/tests/upstream-authority-disk/post-install.sh new file mode 100755 index 0000000..9ef78ac --- /dev/null +++ b/.github/tests/upstream-authority-disk/post-install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +SCRIPT=$(readlink -f "$0") +SCRIPTPATH="$(dirname "${SCRIPT}")" +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" + +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" + +print_helm_releases +print_spire_workload_status "${scenario}" + +if [ "$1" != '0' ]; then + get_namespace_details "${scenario}" +fi diff --git a/.github/workflows/scripts/update-versions.sh b/.github/workflows/scripts/update-versions.sh index 71a2fb0..b2be7d4 100755 --- a/.github/workflows/scripts/update-versions.sh +++ b/.github/workflows/scripts/update-versions.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "${SCRIPT}") +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" CHARTJSON="${SCRIPTPATH}/../../tests/charts.json"