diff --git a/hack/clickhouse-system-bucket-shared-state.bats b/hack/clickhouse-system-bucket-shared-state.bats index 876e90954..d03434531 100644 --- a/hack/clickhouse-system-bucket-shared-state.bats +++ b/hack/clickhouse-system-bucket-shared-state.bats @@ -179,3 +179,26 @@ STUBEOF } done } + +# cert-manager issues the Secret of a Certificate that still exists again as +# soon as it is deleted, so the Certificate has to go first or its Secret +# outlives the run. +@test "the round-trip cleanup deletes the Certificate before its Secret" { + script=$(yq 'select(.metadata.name == "clickhouse-3-system-bucket-roundtrip") | .spec.steps[] + | select(.name == "run") | .finally[] + | select(.description == "system-bucket round-trip cleanup") | .script.content' \ + hack/e2e-chainsaw/clickhouse/chainsaw-test.yaml) + [ -n "$script" ] || { echo "the run step has no system-bucket round-trip cleanup" >&2; false; } + cat >"$STUB/kubectl" <<'STUBEOF' +#!/bin/bash +echo "$*" >>"$STUB/calls" +STUBEOF + PATH="$STUB:$PATH" NAMESPACE=tenant-root sh -c "$script" + cert=$(grep -nE '^-n tenant-root delete certificate e2e-system-bucket-s3( |$)' "$STUB/calls" | cut -d: -f1) + secret=$(grep -nE '^-n tenant-root delete secret e2e-system-bucket-s3-tls( |$)' "$STUB/calls" | cut -d: -f1) + [ -n "$cert" ] && [ -n "$secret" ] && [ "$cert" -lt "$secret" ] || { + echo "the cleanup does not delete Certificate e2e-system-bucket-s3 before Secret e2e-system-bucket-s3-tls; kubectl calls:" >&2 + cat "$STUB/calls" >&2 + false + } +} diff --git a/hack/e2e-chainsaw/clickhouse/chainsaw-test.yaml b/hack/e2e-chainsaw/clickhouse/chainsaw-test.yaml index a4c4aef40..774941ced 100644 --- a/hack/e2e-chainsaw/clickhouse/chainsaw-test.yaml +++ b/hack/e2e-chainsaw/clickhouse/chainsaw-test.yaml @@ -559,10 +559,12 @@ spec: ' # Chainsaw did not apply these: the jobs come from the script and the # Backup from the controller, and deleting a BackupJob reclaims no Backup. - # The Certificate's Secret outlives the Certificate Chainsaw deletes. + # The Certificate's Secret outlives the Certificate, and cert-manager + # issues it again while the Certificate exists, so the Certificate goes + # first rather than at Chainsaw's cleanup after this finally. - description: system-bucket round-trip cleanup script: - timeout: 3m + timeout: 4m content: | set -eu kubectl -n "$NAMESPACE" delete restorejob sysbucket-restore --ignore-not-found --wait=true --timeout=30s @@ -570,4 +572,5 @@ spec: # The driver names the Backup after the BackupJob; by name it is # found even when status.backupRef was never written. kubectl -n "$NAMESPACE" delete backup sysbucket-backup --ignore-not-found --wait=true --timeout=60s + kubectl -n "$NAMESPACE" delete certificate e2e-system-bucket-s3 --ignore-not-found --wait=true --timeout=30s kubectl -n "$NAMESPACE" delete secret e2e-system-bucket-s3-tls --ignore-not-found --wait=true --timeout=30s