|
57 | 57 | # SPIRE delegation fixture: |
58 | 58 | # Set OPENSHELL_E2E_KUBE_SPIRE_DELEGATION=1 to install pinned SPIRE hardened |
59 | 59 | # charts (ci/values-spire-delegation-stack.yaml) before OpenShell, with the |
60 | | -# agent admin socket exposed for the shared supervisor. The release is |
61 | | -# removed again on exit. Tests create sandbox registration entries. |
| 60 | +# agent admin socket exposed for the shared supervisor. The fixture needs a |
| 61 | +# cluster without SPIRE CRDs and creates a fresh namespace |
| 62 | +# (OPENSHELL_E2E_SPIRE_NAMESPACE, default openshell-e2e-spire); it removes |
| 63 | +# both, and the registration entries tests label with that namespace, on exit. |
62 | 64 | # |
63 | 65 | # Credential-driver fixture: |
64 | 66 | # Set OPENSHELL_E2E_CREDENTIAL_DRIVERS=1 to enable one credential storage |
@@ -121,7 +123,8 @@ VAULT_CA_CONFIG_MAP="openbao-ca" |
121 | 123 | VAULT_DNS_ALIAS="${VAULT_RELEASE_NAME}-0" |
122 | 124 | VAULT_CA_FILE="${WORKDIR}/openbao-ca.crt" |
123 | 125 | SPIRE_FIXTURE_DEPLOYED=0 |
124 | | -SPIRE_NAMESPACE="${OPENSHELL_E2E_SPIRE_NAMESPACE:-spire}" |
| 126 | +SPIRE_NAMESPACE="${OPENSHELL_E2E_SPIRE_NAMESPACE:-openshell-e2e-spire}" |
| 127 | +SPIRE_CRDS=(clusterspiffeids.spire.spiffe.io clusterstaticentries.spire.spiffe.io clusterfederatedtrustdomains.spire.spiffe.io) |
125 | 128 | SPIRE_CHART_REPO="https://spiffe.github.io/helm-charts-hardened/" |
126 | 129 | SPIRE_CHART_VERSION="${OPENSHELL_E2E_SPIRE_CHART_VERSION:-0.30.3}" |
127 | 130 | SPIRE_CRDS_CHART_VERSION="${OPENSHELL_E2E_SPIRE_CRDS_CHART_VERSION:-0.6.1}" |
@@ -494,37 +497,47 @@ provision_vault_auth() { |
494 | 497 | } |
495 | 498 |
|
496 | 499 | deploy_spire_fixture() { |
497 | | - echo "Installing SPIRE ${SPIRE_CHART_VERSION} fixture in namespace ${SPIRE_NAMESPACE}..." |
| 500 | + # The fixture owns only what it creates: refuse a cluster that already has |
| 501 | + # the namespace or SPIRE CRDs, so cleanup can never remove another install. |
| 502 | + local crd |
| 503 | + for crd in "${SPIRE_CRDS[@]}"; do |
| 504 | + if kctl get crd "${crd}" >/dev/null 2>&1; then |
| 505 | + echo "ERROR: CRD ${crd} already exists; the SPIRE fixture needs a cluster without SPIRE." >&2 |
| 506 | + exit 2 |
| 507 | + fi |
| 508 | + done |
| 509 | + if ! kctl create namespace "${SPIRE_NAMESPACE}" >/dev/null; then |
| 510 | + echo "ERROR: could not create a fresh SPIRE fixture namespace ${SPIRE_NAMESPACE}; set OPENSHELL_E2E_SPIRE_NAMESPACE to an unused name." >&2 |
| 511 | + exit 2 |
| 512 | + fi |
498 | 513 | SPIRE_FIXTURE_DEPLOYED=1 |
499 | | - helmctl upgrade --install spire-crds spire-crds --repo "${SPIRE_CHART_REPO}" \ |
| 514 | + echo "Installing SPIRE ${SPIRE_CHART_VERSION} fixture in namespace ${SPIRE_NAMESPACE}..." |
| 515 | + helmctl install spire-crds spire-crds --repo "${SPIRE_CHART_REPO}" \ |
500 | 516 | --version "${SPIRE_CRDS_CHART_VERSION}" \ |
501 | | - --namespace "${SPIRE_NAMESPACE}" --create-namespace --wait |
502 | | - helmctl upgrade --install spire spire --repo "${SPIRE_CHART_REPO}" \ |
| 517 | + --namespace "${SPIRE_NAMESPACE}" --wait |
| 518 | + helmctl install spire spire --repo "${SPIRE_CHART_REPO}" \ |
503 | 519 | --version "${SPIRE_CHART_VERSION}" \ |
504 | 520 | --namespace "${SPIRE_NAMESPACE}" \ |
505 | 521 | --values "${ROOT}/deploy/helm/openshell/ci/values-spire-delegation-stack.yaml" \ |
506 | 522 | --wait --timeout 5m |
507 | 523 | kctl -n "${SPIRE_NAMESPACE}" rollout status daemonset/spire-agent --timeout=180s |
| 524 | + # Tests label the registration entries they create with this namespace. |
508 | 525 | export OPENSHELL_E2E_SPIRE_NAMESPACE="${SPIRE_NAMESPACE}" |
509 | 526 | } |
510 | 527 |
|
511 | 528 | cleanup_spire_fixture() { |
512 | 529 | [ "${SPIRE_FIXTURE_DEPLOYED}" = "1" ] || return 0 |
513 | 530 | kctl delete clusterstaticentries.spire.spiffe.io \ |
514 | | - -l app.kubernetes.io/managed-by=openshell-e2e --ignore-not-found \ |
| 531 | + -l "openshell.ai/e2e-spire-fixture=${SPIRE_NAMESPACE}" --ignore-not-found \ |
515 | 532 | >/dev/null 2>&1 || true |
516 | 533 | helmctl uninstall spire --namespace "${SPIRE_NAMESPACE}" --wait --timeout 120s \ |
517 | 534 | >/dev/null 2>&1 || true |
518 | 535 | helmctl uninstall spire-crds --namespace "${SPIRE_NAMESPACE}" --wait --timeout 60s \ |
519 | 536 | >/dev/null 2>&1 || true |
520 | | - # The CRD chart keeps its CRDs on uninstall; remove only the ones it owned. |
521 | | - local crd |
522 | | - for crd in clusterspiffeids clusterstaticentries clusterfederatedtrustdomains; do |
523 | | - crd="${crd}.spire.spiffe.io" |
524 | | - if [ "$(kctl get crd "${crd}" -o jsonpath='{.metadata.annotations.meta\.helm\.sh/release-namespace}' 2>/dev/null)" = "${SPIRE_NAMESPACE}" ]; then |
525 | | - kctl delete crd "${crd}" --wait=false >/dev/null 2>&1 || true |
526 | | - fi |
527 | | - done |
| 537 | + # The CRD chart keeps its CRDs on uninstall. None existed before the |
| 538 | + # fixture, so these are the fixture's own. |
| 539 | + kctl delete crd "${SPIRE_CRDS[@]}" --ignore-not-found --wait=false \ |
| 540 | + >/dev/null 2>&1 || true |
528 | 541 | kctl delete namespace "${SPIRE_NAMESPACE}" --wait=true --timeout=120s \ |
529 | 542 | --ignore-not-found >/dev/null 2>&1 || true |
530 | 543 | SPIRE_FIXTURE_DEPLOYED=0 |
|
0 commit comments