#!/usr/bin/env bash set -xe UPGRADE_VERSION=$(git ls-remote --tags origin -l 'spire-0.*' | awk -F. '{print $2}' | sort -n | tail -n 1 | sed 's/^/v0./; s/$/.0/') UPGRADE_REPO=https://spiffe.github.io/helm-charts-hardened SCRIPT="$(readlink -f "$0")" SCRIPTPATH="$(dirname "${SCRIPT}")" TESTDIR="${SCRIPTPATH}/../../../.github/tests" DEPS="${TESTDIR}/dependencies" # shellcheck source=/dev/null source "${SCRIPTPATH}/../../../.github/scripts/parse-versions.sh" # shellcheck source=/dev/null source "${TESTDIR}/common.sh" "${SCRIPTPATH}/../../../.github/scripts/prepare-local-chart-deps.sh" helm_install=(helm upgrade --install --create-namespace) ns=spire-server UPGRADE_ARGS="" CLEANUP=1 for i in "$@"; do case $i in -u) if [[ -z "$UPGRADE_VERSION" ]]; then echo "Failed to detect previous version." exit 1 fi UPGRADE_ARGS="--repo $UPGRADE_REPO --version $UPGRADE_VERSION" shift # past argument=value ;; -c) CLEANUP=0 shift # past argument=value ;; esac done teardown() { print_helm_releases print_spire_workload_status spire-server spire-system if [[ "$1" -ne 0 ]]; then get_namespace_details spire-server spire-system fi if [ "${CLEANUP}" -eq 1 ]; then helm uninstall --namespace "${ns}" spire 2>/dev/null || true kubectl delete ns "${ns}" 2>/dev/null || true kubectl delete ns spire-system 2>/dev/null || true helm uninstall --namespace cert-manager cert-manager 2>/dev/null || true kubectl delete ns cert-manager 2>/dev/null || true helm uninstall --namespace ingress-nginx 2>/dev/null || true kubectl delete ns ingress-nginx 2>/dev/null || true fi } trap 'EC=$? && trap - SIGTERM && teardown $EC' SIGINT SIGTERM EXIT if [[ -n "$UPGRADE_ARGS" ]]; then pushd "${SCRIPTPATH}" git clone https://github.com/spiffe/helm-charts-hardened "${UPGRADE_VERSION}" pushd "${UPGRADE_VERSION}" git checkout "${UPGRADE_VERSION/v/spire-}" helm install --create-namespace -n spire-system spire-crds charts/spire-crds ./tests/integration/production/run-tests.sh -c popd popd # Any other upgrade steps go here. (Upgrade crds, delete statefulsets without cascade, etc.) helm upgrade -n spire-system spire-crds charts/spire-crds --wait else kubectl create namespace spire-system 2>/dev/null || true kubectl label namespace spire-system pod-security.kubernetes.io/enforce=privileged || true kubectl create namespace "${ns}" 2>/dev/null || true kubectl label namespace "${ns}" pod-security.kubernetes.io/enforce=restricted || true "${helm_install[@]}" cert-manager cert-manager --version "$VERSION_CERT_MANAGER" --repo "$HELM_REPO_CERT_MANAGER" \ --namespace cert-manager \ --create-namespace \ --set installCRDs=true \ --wait kubectl apply -f "${DEPS}/testcert.yaml" -n spire-server "${helm_install[@]}" ingress-nginx ingress-nginx --version "$VERSION_INGRESS_NGINX" --repo "$HELM_REPO_INGRESS_NGINX" \ --namespace ingress-nginx \ --create-namespace \ --set controller.extraArgs.enable-ssl-passthrough=,controller.admissionWebhooks.enabled=false,controller.service.type=ClusterIP \ --set controller.ingressClassResource.default=true \ --wait ip=$(kubectl get svc -n ingress-nginx ingress-nginx-controller -o go-template='{{ .spec.clusterIP }}') echo "$ip" oidc-discovery.production.other cat > /tmp/dummydns <