#!/usr/bin/env bash set -euo pipefail usage() { cat <<'USAGE' Run a service smoke test from a persistent pod, then exec curl inside it. Usage: NAMESPACE= tools/smoke-service.sh http://service.namespace.svc/path Optional environment: POD_NAME Reusable smoke pod name (default: service-smoke) SMOKE_IMAGE Image with curl installed (default: curlimages/curl:8.10.1) CLEANUP Delete the smoke pod after the test (default: false) USAGE } if [[ "${1:-}" == "-h" || "${1:-}" == "--help" || $# -ne 1 ]]; then usage exit 0 fi target_url="$1" NAMESPACE="${NAMESPACE:-default}" POD_NAME="${POD_NAME:-service-smoke}" SMOKE_IMAGE="${SMOKE_IMAGE:-curlimages/curl:8.10.1}" CLEANUP="${CLEANUP:-false}" if ! command -v kubectl >/dev/null 2>&1; then echo "ERROR: missing required command: kubectl" >&2 exit 1 fi if ! kubectl get pod "$POD_NAME" -n "$NAMESPACE" >/dev/null 2>&1; then kubectl run "$POD_NAME" \ -n "$NAMESPACE" \ --image="$SMOKE_IMAGE" \ --restart=Never \ --command -- sleep 3600 fi kubectl wait -n "$NAMESPACE" --for=condition=Ready "pod/$POD_NAME" --timeout=90s kubectl exec -n "$NAMESPACE" "$POD_NAME" -- curl -fsS "$target_url" if [[ "$CLEANUP" == "true" ]]; then kubectl delete pod "$POD_NAME" -n "$NAMESPACE" --wait=false fi