diff --git a/hack/capi-upgrade-chart_test.bats b/hack/capi-upgrade-chart_test.bats index 2bad9bfe0..22b545af2 100644 --- a/hack/capi-upgrade-chart_test.bats +++ b/hack/capi-upgrade-chart_test.bats @@ -83,6 +83,8 @@ setup() { [ "$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.volumes[] | select(.name == "scripts") | .configMap.name' "$RENDERED")" = capi-providers-core-upgrade ] [ "$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].volumeMounts[] | select(.name == "scripts") | .mountPath' "$RENDERED")" = /scripts ] [ "$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].env[] | select(.name == "KUBE_CONTEXT") | .value' "$RENDERED")" = capi-upgrade ] + [ "$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].env[] | select(.name == "KUBECONFIG") | .value' "$RENDERED")" = /scripts/kubeconfig ] + [ "$(yq --no-doc 'select(.kind == "ConfigMap" and .metadata.name == "capi-providers-core-upgrade") | .data.kubeconfig | from_yaml | .current-context' "$RENDERED")" = capi-upgrade ] image="$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].image' "$RENDERED")" [[ "$image" =~ @sha256:[0-9a-f]{64}$ ]] } diff --git a/hack/capi-upgrade_test.bats b/hack/capi-upgrade_test.bats index 9e6c59568..e40b4bf47 100644 --- a/hack/capi-upgrade_test.bats +++ b/hack/capi-upgrade_test.bats @@ -53,6 +53,14 @@ accepted_patches() { jq --slurp --compact-output '[.[] | select(.accepted == true) | {name, version: (.patch[] | select(.path == "/spec/version" and .op == "replace") | .value)}]' "$CAPI_TEST_LOG" } +@test "the script refuses to reach the API without the hook's kubeconfig" { + unset KUBECONFIG + run bash "$UPGRADE_SCRIPT" + [ "$status" -ne 0 ] + [[ "$output" == *KUBECONFIG* ]] + [ ! -s "$CAPI_TEST_LOG" ] +} + @test "fresh installations do not create or patch providers" { fixture '.providers = {}' run bash "$UPGRADE_SCRIPT" diff --git a/packages/system/capi-providers-core/files/upgrade-providers.sh b/packages/system/capi-providers-core/files/upgrade-providers.sh index d5d56709e..6894731bc 100644 --- a/packages/system/capi-providers-core/files/upgrade-providers.sh +++ b/packages/system/capi-providers-core/files/upgrade-providers.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -: "${KUBE_CONTEXT:?}" "${NAMESPACE:?}" "${BRIDGE_VERSION:?}" "${TARGET_VERSION:?}" +: "${KUBECONFIG:?}" "${KUBE_CONTEXT:?}" "${NAMESPACE:?}" "${BRIDGE_VERSION:?}" "${TARGET_VERSION:?}" fail() { printf 'CAPI upgrade: %s\n' "$*" >&2