From 99af475f1c62aa35168a3d04ef7ed287875169df Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Wed, 26 Apr 2023 11:51:31 +0200 Subject: [PATCH] Resolve shellcheck issues Signed-off-by: Marco Franssen --- .../tests/namespace-override/post-install.sh | 9 ++-- .../tests/namespace-override/pre-install.sh | 3 +- .../tests/production-example/post-install.sh | 24 ++++++---- .github/tests/prometheus/pre-install.sh | 6 ++- .../tests/spire-oidc-insecure/pre-install.sh | 6 ++- .../pre-install.sh | 6 ++- .github/workflows/scripts/update-versions.sh | 22 +++++----- helm-docs.sh | 44 +++++++++---------- 8 files changed, 70 insertions(+), 50 deletions(-) diff --git a/.github/tests/namespace-override/post-install.sh b/.github/tests/namespace-override/post-install.sh index c565da6..09feb6b 100755 --- a/.github/tests/namespace-override/post-install.sh +++ b/.github/tests/namespace-override/post-install.sh @@ -3,7 +3,8 @@ set -x SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "$SCRIPT") +SCRIPTPATH=$(dirname "${SCRIPT}") +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" k_wait () { kubectl wait --for condition=available --timeout 30s --namespace "$1" "$2" "$3" | tail -n 1 @@ -30,7 +31,7 @@ cat <>"$GITHUB_STEP_SUMMARY" | spire-spiffe-oidc-discovery-provider |
$(k_wait spire-server deployments.apps "${RELEASE}-spiffe-oidc-discovery-provider")
| EOF -if [ $1 -ne 0 ]; then +if [[ "$1" -ne 0 ]]; then echo echo '```' echo '==> Events of namespace spire-server' @@ -53,8 +54,8 @@ if [ $1 -ne 0 ]; then 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 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 line; do echo logs for $line; kubectl logs -n spire-system $line --all-containers=true --ignore-errors=true; done + 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" diff --git a/.github/tests/namespace-override/pre-install.sh b/.github/tests/namespace-override/pre-install.sh index 91bd6f0..3d778a6 100755 --- a/.github/tests/namespace-override/pre-install.sh +++ b/.github/tests/namespace-override/pre-install.sh @@ -1,3 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash + kubectl create namespace "spire-system" kubectl create namespace "spire-server" diff --git a/.github/tests/production-example/post-install.sh b/.github/tests/production-example/post-install.sh index ee0963e..1f78c43 100755 --- a/.github/tests/production-example/post-install.sh +++ b/.github/tests/production-example/post-install.sh @@ -3,10 +3,16 @@ set -x SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "$SCRIPT") +SCRIPTPATH=$(dirname "${SCRIPT}") +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" -k_wait=(kubectl wait --for condition=available --timeout 30s --namespace) -k_rollout_status=(kubectl rollout status --watch --timeout 30s --namespace) +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 +} function get_namespace_details { cat <>"$GITHUB_STEP_SUMMARY" @@ -38,14 +44,14 @@ cat <>"$GITHUB_STEP_SUMMARY" | 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)" | +| 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 -if [ $1 -ne 0 ]; then +if [[ "$1" -ne 0 ]]; then get_namespace_details spire-server get_namespace_details spire-systen fi diff --git a/.github/tests/prometheus/pre-install.sh b/.github/tests/prometheus/pre-install.sh index de23418..9057040 100755 --- a/.github/tests/prometheus/pre-install.sh +++ b/.github/tests/prometheus/pre-install.sh @@ -1,3 +1,7 @@ #!/usr/bin/env bash -helm install kube-prometheus-stack kube-prometheus-stack --version $VERSION_KUBE_PROMETHEUS_STACK --repo $HELM_REPO_KUBE_PROMETHEUS_STACK -n "$scenario" --wait +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 diff --git a/.github/tests/spire-oidc-insecure/pre-install.sh b/.github/tests/spire-oidc-insecure/pre-install.sh index 6d39ad2..2433e0e 100755 --- a/.github/tests/spire-oidc-insecure/pre-install.sh +++ b/.github/tests/spire-oidc-insecure/pre-install.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash -helm install ingress-nginx ingress-nginx --version "$VERSION_INGRESS_NGINX" --repo "$HELM_REPO_INGRESS_NGINX" -n "$scenario" --set controller.extraArgs.enable-ssl-passthrough= +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= kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller -n "$scenario" diff --git a/.github/tests/upstream-authority-cert-manager/pre-install.sh b/.github/tests/upstream-authority-cert-manager/pre-install.sh index 9cf3ea5..1e1f8b2 100755 --- a/.github/tests/upstream-authority-cert-manager/pre-install.sh +++ b/.github/tests/upstream-authority-cert-manager/pre-install.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +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 SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -kubectl apply -f $SCRIPT_DIR/cert-manager-ca.yaml -n "$scenario" +kubectl apply -f "${SCRIPT_DIR}/cert-manager-ca.yaml" -n "$scenario" diff --git a/.github/workflows/scripts/update-versions.sh b/.github/workflows/scripts/update-versions.sh index 46b438e..71a2fb0 100755 --- a/.github/workflows/scripts/update-versions.sh +++ b/.github/workflows/scripts/update-versions.sh @@ -1,24 +1,24 @@ #!/usr/bin/env bash SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "$SCRIPT") +SCRIPTPATH=$(dirname "${SCRIPT}") -CHARTJSON=$SCRIPTPATH/../../tests/charts.json +CHARTJSON="${SCRIPTPATH}/../../tests/charts.json" jq -r ".[].name" "${CHARTJSON}" | while read -r CHART; do ENTRYQUERY='.[] | select(.name == "'$CHART'")' REPO_URL="$(jq -r "$ENTRYQUERY | .repo" "${CHARTJSON}")" VERSION="$(jq -r "$ENTRYQUERY | .version" "${CHARTJSON}")" - echo Processing: ${CHART} - echo " repo: $REPO_URL" - echo " current version: $VERSION" - helm repo add "$CHART" "$REPO_URL" > /dev/null - helm repo update "$CHART" > /dev/null - LATEST_VERSION=$(helm search repo --regexp "$CHART/$CHART\v" -o json | jq -r '.[0].version') - echo " latest version: $LATEST_VERSION" - if [ "x$VERSION" != "x$LATEST_VERSION" ]; then + echo Processing: "${CHART}" + echo " repo: ${REPO_URL}" + echo " current version: ${VERSION}" + helm repo add "${CHART}" "${REPO_URL}" > /dev/null + helm repo update "${CHART}" > /dev/null + LATEST_VERSION=$(helm search repo --regexp "${CHART}/${CHART}\v" -o json | jq -r '.[0].version') + echo " latest version: ${LATEST_VERSION}" + if [ "x${VERSION}" != "x${LATEST_VERSION}" ]; then echo " New version found!" - jq "( $ENTRYQUERY ).version |= "'"${LATEST_VERSION}"' "${CHARTJSON}" > /tmp/$$ + jq "(${ENTRYQUERY}).version |= "'"${LATEST_VERSION}"' "${CHARTJSON}" > /tmp/$$ mv /tmp/$$ "${CHARTJSON}" fi done diff --git a/helm-docs.sh b/helm-docs.sh index d77d15c..a41b43f 100755 --- a/helm-docs.sh +++ b/helm-docs.sh @@ -6,31 +6,31 @@ SCRIPTPATH=$(dirname "$0") HELM_DOCS_VERSION="1.11.0" case "$(uname -s)" in - Linux*) - machine=Linux - shasum=sha256sum - exe=helm-docs - ;; - Darwin*) - machine=Darwin - shasum=shasum - exe=helm-docs - ;; - MINGW64*) - machine=Windows - shasum=sha256sum - exe=helm-docs.exe - ;; + Linux*) + machine=Linux + shasum=sha256sum + exe=helm-docs + ;; + Darwin*) + machine=Darwin + shasum=shasum + exe=helm-docs + ;; + MINGW64*) + machine=Windows + shasum=sha256sum + exe=helm-docs.exe + ;; esac function install_helm_docs { - curl -LO https://github.com/norwoodj/helm-docs/releases/download/v"${HELM_DOCS_VERSION}"/helm-docs_"${HELM_DOCS_VERSION}"_${machine}_x86_64.tar.gz - curl -L --output /tmp/checksums_helm-docs.txt https://github.com/norwoodj/helm-docs/releases/download/v${HELM_DOCS_VERSION}/checksums.txt - grep helm-docs_${HELM_DOCS_VERSION}_${machine}_x86_64.tar.gz /tmp/checksums_helm-docs.txt | $shasum -c - - mkdir -p "$SCRIPTPATH/bin" - tar -xf helm-docs_"${HELM_DOCS_VERSION}"_${machine}_x86_64.tar.gz ${exe} - mv ${exe} "$SCRIPTPATH/bin/" - rm helm-docs_"${HELM_DOCS_VERSION}"_${machine}_x86_64.tar.gz + curl -LO "https://github.com/norwoodj/helm-docs/releases/download/v${HELM_DOCS_VERSION}/helm-docs_${HELM_DOCS_VERSION}_${machine}_x86_64.tar.gz" + curl -L --output /tmp/checksums_helm-docs.txt "https://github.com/norwoodj/helm-docs/releases/download/v${HELM_DOCS_VERSION}/checksums.txt" + grep "helm-docs_${HELM_DOCS_VERSION}_${machine}_x86_64.tar.gz" /tmp/checksums_helm-docs.txt | $shasum -c - + mkdir -p "$SCRIPTPATH/bin" + tar -xf "helm-docs_${HELM_DOCS_VERSION}_${machine}_x86_64.tar.gz" "${exe}" + mv "${exe}" "$SCRIPTPATH/bin/" + rm "helm-docs_${HELM_DOCS_VERSION}_${machine}_x86_64.tar.gz" } if [ ! -f "$SCRIPTPATH/bin/${exe}" ] ; then