From 5e6772ec3f6f9b50ae58af974a0bb65747854137 Mon Sep 17 00:00:00 2001 From: Mattia Eleuteri Date: Mon, 23 Nov 2026 13:24:41 +0100 Subject: [PATCH] fix(cluster-api): name the kubeconfig the upgrade hook runs with The provider upgrade hook reaches the API through the kubeconfig its Job mounts at /scripts/kubeconfig and exports as KUBECONFIG, never through the in-cluster config. The script only named KUBE_CONTEXT, so hack/check-hook-request-timeout.bats, which since it started reading files/ exempts a script only when it names KUBECONFIG, took its "kubectl --context ... --request-timeout=10s" for an in-cluster call and failed "no in-cluster kubectl call carries a non-zero --request-timeout" on main. Require KUBECONFIG alongside the other inputs instead of loosening the check or dropping the timeout: the per-call timeout is safe because the explicit kubeconfig is what serves it, and the script now refuses to fall back to the in-cluster config, where the timeout would hit the bug the check guards against. Tested with bats on hack/check-hook-request-timeout.bats, hack/capi-upgrade_test.bats and hack/capi-upgrade-chart_test.bats; with the script change reverted, the check and the new missing-KUBECONFIG test both fail. Fixes: 9680ed64dfe5 ("feat(cluster-api)!: update Cluster API to v1.14.4 (#4902)") Assisted-by: LLM Signed-off-by: Mattia Eleuteri --- hack/capi-upgrade-chart_test.bats | 2 ++ hack/capi-upgrade_test.bats | 8 ++++++++ .../system/capi-providers-core/files/upgrade-providers.sh | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) 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