mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
fix(e2e): drop the job-level runner.temp and pin the tenant kubeconfig handling
jobs.e2e.env set COZY_PROXMOX_WORKDIR from runner.temp, but the runner
context is not available in job-level env, so GitHub would refuse the
whole workflow at load time and the Proxmox lane would stop starting.
actionlint reports it as `context "runner" is not allowed here`.
Drop the variable. run-proxmox.sh already falls back to RUNNER_TEMP,
which the runner exports into every step, and the cleanup step removes
the file from there.
Pin the behaviour the previous commit added, none of which a test
covered: the fetched kubeconfig carries no group or other bits under
umask 022, apply-tenant removes a file an earlier run left, and the
suite's finally removes the file on the keep_tenant path, so diagnostics
after it prints no tenant section. Each case goes red with its line
removed.
Signed-off-by: Marian Koreniuk <moriarti@cp.if.ua>
Assisted-by: LLM
(cherry picked from commit 3d97e912b4)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
1 parent
2af6053079
commit
77227c55e9
3 files changed
+69
-11
No files matched your search
@@ -49,11 +49,6 @@ jobs:
|
||||
COZY_PVE_SSH: ${{ vars.PROXMOX_SSH }}
|
||||
COZY_PVE_SSH_KEY: ${{ github.workspace }}/.ssh-pve
|
||||
COZY_KEEP_TENANT: ${{ inputs.keep_tenant == true }}
|
||||
# Where run-proxmox.sh keeps the tenant's super-admin kubeconfig for the
|
||||
# run. runner.temp is emptied by the runner between jobs, and the cleanup
|
||||
# step below removes the file as well; see the script for why neither is
|
||||
# left to /tmp.
|
||||
COZY_PROXMOX_WORKDIR: ${{ runner.temp }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||
@@ -162,6 +157,8 @@ jobs:
|
||||
|
||||
- name: Remove staged credentials
|
||||
if: always()
|
||||
# The tenant kubeconfig is the suite's, fetched by run-proxmox.sh; its
|
||||
# finally removes it too, but a run killed mid-step never reaches that.
|
||||
run: rm -f "$GITHUB_WORKSPACE/.kubeconfig" "$COZY_PVE_SSH_KEY" "$COZY_PROXMOX_WORKDIR/proxmox-e2e-tenant.kubeconfig"
|
||||
# The tenant kubeconfig is the suite's, fetched by run-proxmox.sh into
|
||||
# RUNNER_TEMP, which the runner exports into every step (the runner
|
||||
# context is not allowed in job-level env); its finally removes it too,
|
||||
# but a run killed mid-step never reaches that.
|
||||
run: rm -f "$GITHUB_WORKSPACE/.kubeconfig" "$COZY_PVE_SSH_KEY" "$RUNNER_TEMP/proxmox-e2e-tenant.kubeconfig"
|
||||
@@ -26,9 +26,10 @@ STORAGE="${COZY_PROXMOX_STORAGE:?COZY_PROXMOX_STORAGE is required, the PVE stora
|
||||
# a fixed path under /tmp: the file is a credential for the whole tenant, so it
|
||||
# must not outlive the run on a shared runner, and dump_diagnostics reads
|
||||
# whatever is at this path, so a file left by a previous run would be reported
|
||||
# as this run's tenant. The workflow points this at runner.temp, which the
|
||||
# runner empties between jobs; apply-tenant removes a leftover before it does
|
||||
# anything else, and the suite's finally removes the file when the run ends.
|
||||
# as this run's tenant. On the workflow's runner this is RUNNER_TEMP, which the
|
||||
# runner exports into every step and empties between jobs; apply-tenant removes
|
||||
# a leftover before it does anything else, and the suite's finally removes the
|
||||
# file when the run ends.
|
||||
WORKDIR="${COZY_PROXMOX_WORKDIR:-${RUNNER_TEMP:-${TMPDIR:-/tmp}}}"
|
||||
TENANT_KUBECONFIG="$WORKDIR/proxmox-e2e-tenant.kubeconfig"
|
||||
FIXTURE="$(cd "$(dirname "$0")/.." && pwd)/kubernetes-proxmox/tenant.yaml"
|
||||
|
||||
@@ -61,3 +61,63 @@ RUNNER="$REPO_ROOT/hack/e2e-chainsaw/_lib/run-proxmox.sh"
|
||||
rm -rf "$stub"
|
||||
case "$out" in *"is gone from main-pool"*) ;; *) echo "$out" >&2; exit 1 ;; esac
|
||||
}
|
||||
|
||||
# The tenant's super-admin kubeconfig is a credential for the whole tenant, kept
|
||||
# under RUNNER_TEMP for one run. The workflow sets no path of its own, so these
|
||||
# cases go through the same RUNNER_TEMP fallback the runner provides, with the
|
||||
# override cleared.
|
||||
KUBECONFIG_NAME=proxmox-e2e-tenant.kubeconfig
|
||||
SUITE="$REPO_ROOT/hack/e2e-chainsaw/kubernetes-proxmox/chainsaw-test.yaml.disabled"
|
||||
|
||||
@test "tenant-node writes the tenant kubeconfig without group or other bits under umask 022" {
|
||||
work="$(mktemp -d)"
|
||||
stub="$(mktemp -d)"
|
||||
# The secret read answers a kubeconfig and the first tenant read fails, which
|
||||
# ends the check right after the fetch with the file in place.
|
||||
cat > "$stub/kubectl" <<'STUB'
|
||||
#!/bin/sh
|
||||
case "$*" in *"get secret"*) printf '%s' YXBpVmVyc2lvbjogdjEK; exit 0 ;; esac
|
||||
exit 1
|
||||
STUB
|
||||
chmod +x "$stub/kubectl"
|
||||
rc=0
|
||||
(umask 022; PATH="$stub:$PATH" RUNNER_TEMP="$work" COZY_PROXMOX_WORKDIR= COZY_PVE_SSH=x COZY_PROXMOX_STORAGE=s "$RUNNER" tenant-node) >/dev/null 2>&1 || rc=$?
|
||||
mode="$(ls -l "$work/$KUBECONFIG_NAME" | cut -c1-10)"
|
||||
rm -rf "$work" "$stub"
|
||||
[ "$rc" -ne 0 ]
|
||||
[ "$mode" = "-rw-------" ] || { echo "FAIL: the tenant kubeconfig was written $mode" >&2; exit 1; }
|
||||
}
|
||||
|
||||
@test "apply-tenant removes a tenant kubeconfig an earlier run left behind" {
|
||||
work="$(mktemp -d)"
|
||||
stub="$(mktemp -d)"
|
||||
printf 'an earlier run\n' > "$work/$KUBECONFIG_NAME"
|
||||
printf '#!/bin/sh\ncat >/dev/null\n' > "$stub/kubectl"
|
||||
chmod +x "$stub/kubectl"
|
||||
PATH="$stub:$PATH" RUNNER_TEMP="$work" COZY_PROXMOX_WORKDIR= COZY_PVE_SSH=x COZY_PROXMOX_STORAGE=s "$RUNNER" apply-tenant
|
||||
left=no
|
||||
[ ! -e "$work/$KUBECONFIG_NAME" ] || left=yes
|
||||
rm -rf "$work" "$stub"
|
||||
[ "$left" = no ] || { echo "FAIL: apply-tenant left the earlier run's kubeconfig in place" >&2; exit 1; }
|
||||
}
|
||||
|
||||
@test "the suite's finally removes the tenant kubeconfig, so diagnostics after it prints no tenant section" {
|
||||
# keep_tenant exits the finally before its deletes, and the kubeconfig has to
|
||||
# be gone on that path as well. Diagnostics reads whatever is at the path, so
|
||||
# a file left there would be reported as the next run's tenant.
|
||||
work="$(mktemp -d)"
|
||||
stub="$(mktemp -d)"
|
||||
printf 'this run\n' > "$work/$KUBECONFIG_NAME"
|
||||
printf '#!/bin/sh\necho "stub $*"\n' > "$stub/kubectl"
|
||||
printf '#!/bin/sh\nexit 0\n' > "$stub/ssh"
|
||||
chmod +x "$stub/kubectl" "$stub/ssh"
|
||||
finally="$(yq -r '.spec.steps[] | select(.name == "replacement-converges-unattended") | .finally[0].script.content' "$SUITE")"
|
||||
[ -n "$finally" ]
|
||||
PATH="$stub:$PATH" RUNNER_TEMP="$work" COZY_PROXMOX_WORKDIR= COZY_KEEP_TENANT=true sh -c "$finally" >/dev/null
|
||||
out="$(PATH="$stub:$PATH" RUNNER_TEMP="$work" COZY_PROXMOX_WORKDIR= COZY_PVE_SSH=x COZY_PROXMOX_STORAGE=s "$RUNNER" diagnostics 2>&1)"
|
||||
left=no
|
||||
[ ! -e "$work/$KUBECONFIG_NAME" ] || left=yes
|
||||
rm -rf "$work" "$stub"
|
||||
[ "$left" = no ] || { echo "FAIL: the suite's finally left the tenant kubeconfig in place" >&2; exit 1; }
|
||||
case "$out" in *"tenant nodes and pods"*) echo "$out" >&2; exit 1 ;; esac
|
||||
}
|
||||
Reference in new issue
Block a user