Skip to content

Commit 7904295

Browse files
committed
fix(ci): harden smoke diagnostics
1 parent 7e33de7 commit 7904295

4 files changed

Lines changed: 82 additions & 1 deletion

File tree

scripts/ci/ci_assets_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ func TestSecurityScanWorkflowUsesExistingHelper(t *testing.T) {
240240
}
241241
}
242242

243+
func TestCollectKindDiagnosticsCapturesFrontendTopology(t *testing.T) {
244+
contents := string(readFile(t, repoPath("scripts", "ci", "collect-kind-diagnostics.sh")))
245+
246+
for _, want := range []string{
247+
`run_capture service-topology kubectl get svc,endpoints,endpointslice -A -o yaml`,
248+
} {
249+
if !strings.Contains(contents, want) {
250+
t.Fatalf("kind diagnostics helper missing %q", want)
251+
}
252+
}
253+
}
254+
243255
func TestSmokeScriptForwardsToProgrammedGatewayListener(t *testing.T) {
244256
contents := string(readFile(t, repoPath("test", "e2e", "smoke", "run.sh")))
245257

scripts/ci/collect-kind-diagnostics.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ run_capture pods-all kubectl get pods -A -o wide
1717
run_capture events-all kubectl get events -A --sort-by=.lastTimestamp
1818
run_capture nantian-pods kubectl describe pods -n nantian-gw
1919
run_capture nantian-logs kubectl logs -n nantian-gw -l app.kubernetes.io/part-of=nantian-gw --all-containers=true --tail=300 --prefix=true
20+
run_capture service-topology kubectl get svc,endpoints,endpointslice -A -o yaml
2021
run_capture gateway-resources kubectl get gateway,httproute -A -o yaml
2122
run_capture nantian-images kubectl get pods -n nantian-gw -o json
2223

scripts/ci/smoke_script_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package ci
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
"path/filepath"
7+
"strings"
8+
"testing"
9+
)
10+
11+
func TestSmokeScriptMarksEarlyBootstrapFailureAsFailed(t *testing.T) {
12+
stubDir := filepath.Join(t.TempDir(), "bin")
13+
if err := os.MkdirAll(stubDir, 0o755); err != nil {
14+
t.Fatalf("create stub dir: %v", err)
15+
}
16+
17+
kubectlPath := filepath.Join(stubDir, "kubectl")
18+
kubectlStub := `#!/usr/bin/env bash
19+
set -euo pipefail
20+
21+
if [[ "${1:-}" == "create" ]]; then
22+
printf 'apiVersion: v1\nkind: Namespace\nmetadata:\n name: nantian-e2e\n'
23+
exit 0
24+
fi
25+
26+
if [[ "${1:-}" == "apply" ]]; then
27+
cat >/dev/null
28+
exit 0
29+
fi
30+
31+
if [[ "${1:-}" == "wait" ]]; then
32+
echo "error: timed out waiting for the condition on pods/echo-test" >&2
33+
exit 1
34+
fi
35+
36+
echo "unexpected kubectl invocation: $*" >&2
37+
exit 1
38+
`
39+
if err := os.WriteFile(kubectlPath, []byte(kubectlStub), 0o755); err != nil {
40+
t.Fatalf("write kubectl stub: %v", err)
41+
}
42+
43+
scriptPath, err := filepath.Abs(repoPath("test", "e2e", "smoke", "run.sh"))
44+
if err != nil {
45+
t.Fatalf("resolve smoke script path: %v", err)
46+
}
47+
48+
cmd := exec.Command("bash", scriptPath, "--no-cleanup", "--skip-bootstrap")
49+
cmd.Env = append(
50+
os.Environ(),
51+
"PATH="+stubDir+string(os.PathListSeparator)+os.Getenv("PATH"),
52+
"TIMEOUT=1",
53+
)
54+
55+
output, runErr := cmd.CombinedOutput()
56+
if runErr == nil {
57+
t.Fatalf("expected smoke script to fail, output:\n%s", output)
58+
}
59+
60+
text := string(output)
61+
if !strings.Contains(text, "Smoke test FAILED") {
62+
t.Fatalf("expected FAILED summary, output:\n%s", text)
63+
}
64+
if strings.Contains(text, "Smoke test PASSED") {
65+
t.Fatalf("unexpected PASSED summary on failure, output:\n%s", text)
66+
}
67+
}

test/e2e/smoke/run.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# e2e smoke test — deploy, route, request, verify, cleanup.
33
# Usage: ./run.sh # full cycle (deploy → test → cleanup)
44
# ./run.sh --no-cleanup # keep cluster running for debugging
5-
set -euo pipefail
5+
set -Eeuo pipefail
66

77
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
88
GATEWAY_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
@@ -252,6 +252,7 @@ send_request() {
252252

253253
# ── Main ──
254254
main() {
255+
trap 'FAILED=true' ERR
255256
trap 'cleanup_cluster; if $FAILED; then red "✗ Smoke test FAILED"; else green "✓ Smoke test PASSED"; fi' EXIT
256257

257258
if [[ "$BOOTSTRAP" == "true" ]]; then

0 commit comments

Comments
 (0)