Files
cozystack/.github/workflows/e2e-proxmox.yaml
T
Alexey Artamonov d6a4835ea5 ci(workflows): run push and schedule workflows only in cozystack/cozystack
A private copy of the repository, used to verify an embargoed security
fix because GitHub runs no CI in an advisory's temporary fork, receives
every workflow file with each sync. Without a repository guard, each
sync and each cron tick there would build, publish, prune and cut
releases with that copy's credentials. Pull request events stay allowed
in the workflows that also check pull requests, since checking the fix
is what the copy is for.

Every job carries the guard rather than only the root jobs, because a
job whose condition calls a status function runs even when the job it
needs was skipped. A contract test holds new push and schedule
workflows to the same rule. It reads 'on' in every form GitHub accepts,
requires whatever follows the guard to be one parenthesized group,
because && binds tighter than || and a trailing '|| (...)' would reopen
the job, and fails on a workflow it cannot parse instead of leaving
that workflow unchecked.

Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
Assisted-by: LLM
2026-11-25 15:49:33 +03:00

169 lines
8.1 KiB
YAML

name: E2E (proxmox)
# The Proxmox substrate's own lane, separate from every other e2e workflow for
# one reason that cannot be engineered away: it needs a Proxmox hypervisor, and
# the oracle-vm-* runners the other lanes use will never have one.
#
# Deliberately NOT triggered by pull_request. A self-hosted runner executes
# whatever the workflow checks out, and this one holds credentials to a
# hypervisor and a live cluster; letting an arbitrary fork PR start it would
# hand both to its author. Manual dispatch and a schedule are the whole trigger
# surface, and both come from someone who already has write access.
on:
workflow_dispatch:
inputs:
keep_tenant:
description: "Leave the tenant in place after the run, for debugging"
type: boolean
default: false
schedule:
# Nightly, offset from the upstream lanes so a shared hypervisor is not
# asked to do two things at once.
- cron: "40 2 * * *"
permissions:
contents: read
concurrency:
# One hypervisor, one tenant namespace, fixed VM ids — two runs would fight
# over all three. Never cancel in progress: a killed run leaks VMs.
group: e2e-proxmox
cancel-in-progress: false
jobs:
e2e:
name: Proxmox substrate
# The job needs a self-hosted runner carrying the `proxmox` label. On a
# repository without one a scheduled run would sit in the queue until GitHub
# cancels it, so the schedule fires only where the stand is declared;
# manual dispatch always runs. The runner must be v2.327.1 or newer, the
# minimum the checkout README names for its node24 runtime.
if: ${{ github.repository == 'cozystack/cozystack' && (github.event_name == 'workflow_dispatch' || vars.PROXMOX_NIGHTLY == 'true') }}
runs-on: [self-hosted, proxmox]
timeout-minutes: 90
env:
COZY_PROXMOX_NS: tenant-e2eproxmox
COZY_PROXMOX_CLUSTER: k8s-e2e
# No fallbacks: an unset variable fails the first step below instead of
# sending a key to a guessed address or probing a storage the stand lacks.
COZY_PROXMOX_STORAGE: ${{ vars.PROXMOX_STORAGE }}
COZY_PVE_SSH: ${{ vars.PROXMOX_SSH }}
COZY_PVE_SSH_KEY: ${{ github.workspace }}/.ssh-pve
COZY_KEEP_TENANT: ${{ inputs.keep_tenant == true }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Require the stand's variables
env:
PVE_URL: ${{ vars.PROXMOX_URL }}
PVE_REGION: ${{ vars.PROXMOX_REGION }}
run: |
set -eu
for v in COZY_PROXMOX_STORAGE COZY_PVE_SSH PVE_URL PVE_REGION; do
eval "val=\${$v:-}"
[ -n "$val" ] || { echo "$v is unset: set the PROXMOX_* repository variables for this stand" >&2; exit 1; }
done
- name: Stage credentials
id: stage
env:
KUBECONFIG_B64: ${{ secrets.COZY_KUBECONFIG }}
PVE_SSH_KEY: ${{ secrets.PROXMOX_SSH_KEY }}
PVE_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
PVE_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
PVE_URL: ${{ vars.PROXMOX_URL }}
PVE_REGION: ${{ vars.PROXMOX_REGION }}
run: |
set -eu
umask 077
printf '%s' "$KUBECONFIG_B64" | base64 -d > "$GITHUB_WORKSPACE/.kubeconfig"
# Unless the current context resolves to a server, client-go either
# fails or falls back to its defaults, in-cluster credentials among
# them, and the calls below would reach a cluster other than the
# stand's. Tear down repeats this check.
server=$(kubectl --kubeconfig "$GITHUB_WORKSPACE/.kubeconfig" config view --minify \
-o jsonpath='{.clusters[0].cluster.server}' 2>"$RUNNER_TEMP/kubeconfig-check.err" || true)
if [ -z "$server" ]; then
echo "COZY_KUBECONFIG does not resolve to a server" >&2
# Empty when the context resolves to a cluster with no server.
cat "$RUNNER_TEMP/kubeconfig-check.err" >&2
exit 1
fi
# OpenSSH refuses a private key whose last line has no newline ("error
# in libcrypto"), and `gh secret set` strips it from a key read from
# stdin. A second newline, when the secret kept its own, is harmless.
printf '%s\n' "$PVE_SSH_KEY" > "$COZY_PVE_SSH_KEY"
# The credentials the management-side CSI controller and CCM read. A
# Secret rather than values so no token is ever written into a
# rendered HelmRelease.
kubectl --kubeconfig "$GITHUB_WORKSPACE/.kubeconfig" create namespace "$COZY_PROXMOX_NS" \
--dry-run=client -o yaml | kubectl --kubeconfig "$GITHUB_WORKSPACE/.kubeconfig" apply -f -
kubectl --kubeconfig "$GITHUB_WORKSPACE/.kubeconfig" -n "$COZY_PROXMOX_NS" \
create secret generic proxmox-credentials \
--from-literal=url="$PVE_URL" \
--from-literal=token_id="$PVE_TOKEN_ID" \
--from-literal=token_secret="$PVE_TOKEN_SECRET" \
--from-literal=region="$PVE_REGION" \
--dry-run=client -o yaml | kubectl --kubeconfig "$GITHUB_WORKSPACE/.kubeconfig" apply -f -
- name: Enable the suite
# It ships disabled so the normal lanes cannot select it; this is the
# one place that is allowed to turn it on.
run: mv hack/e2e-chainsaw/kubernetes-proxmox/chainsaw-test.yaml.disabled
hack/e2e-chainsaw/kubernetes-proxmox/chainsaw-test.yaml
- name: Run the Proxmox suite
env:
KUBECONFIG: ${{ github.workspace }}/.kubeconfig
run: |
chainsaw test \
--config hack/e2e-chainsaw/.chainsaw.yaml \
--test-dir hack/e2e-chainsaw/kubernetes-proxmox
- name: Tear down
# always(), because the whole point of the teardown is the failing run:
# a leaked tenant leaves VMs on the hypervisor and the next run inherits
# them.
if: always() && !inputs.keep_tenant
env:
STAGE_OUTCOME: ${{ steps.stage.outcome }}
run: |
set -eu
kc="$GITHUB_WORKSPACE/.kubeconfig"
# The suite runs only after Stage succeeds, so without that this run
# created no tenant.
if [ "$STAGE_OUTCOME" != success ]; then
echo "::notice::Tear down skipped: Stage credentials ended $STAGE_OUTCOME, so this run created no tenant"
exit 0
fi
# The check Stage makes. Every call names the file, so none falls back
# to this self-hosted runner's own kubeconfig. Failing it here means
# the file broke after Stage, and the tenant may still be live.
server=$(kubectl --kubeconfig "$kc" config view --minify \
-o jsonpath='{.clusters[0].cluster.server}' 2>"$RUNNER_TEMP/kubeconfig-check.err" || true)
if [ -z "$server" ]; then
echo "::error::Tear down did not run: $kc no longer resolves to a server, so tenant e2eproxmox and its VMs may still be live"
cat "$RUNNER_TEMP/kubeconfig-check.err"
exit 1
fi
# A failed delete must not stop the ones after it: stopping there leaves
# behind exactly the VMs this step exists to remove. The step still
# fails at the end.
rc=0
kubectl --kubeconfig "$kc" delete kubernetesnodes.apps.cozystack.io -n "$COZY_PROXMOX_NS" --all --ignore-not-found || rc=1
kubectl --kubeconfig "$kc" delete kubernetes.apps.cozystack.io -n "$COZY_PROXMOX_NS" --all --ignore-not-found || rc=1
kubectl --kubeconfig "$kc" delete tenant.apps.cozystack.io e2eproxmox -n tenant-root --ignore-not-found || rc=1
exit "$rc"
- name: Remove staged credentials
if: always()
# 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"