diff --git a/.gitea/workflows/deploy-trade-r001-canary.yaml b/.gitea/workflows/deploy-trade-r001-canary.yaml index 4dbd84c..b9a2de3 100644 --- a/.gitea/workflows/deploy-trade-r001-canary.yaml +++ b/.gitea/workflows/deploy-trade-r001-canary.yaml @@ -87,37 +87,56 @@ jobs: env: KUBECONFIG: /tmp/kubeconfig run: | - kubectl -n trade-r001-canary delete pod canary-netcheck --ignore-not-found=true - kubectl -n trade-r001-canary run canary-netcheck \ - --image=python:3.12-alpine \ - --restart=Never \ - --command -- sleep 600 - kubectl -n trade-r001-canary wait --for=condition=Ready pod/canary-netcheck --timeout=180s - kubectl -n trade-r001-canary exec canary-netcheck -- python - <<'PY' - import socket + pod_name="$(kubectl -n trade-r001-canary get pod -l app.kubernetes.io/name=trade-ingestor -o jsonpath='{.items[0].metadata.name}')" + kubectl -n trade-r001-canary exec -i "$pod_name" -- node - <<'JS' + const net = require('net'); - targets = [ - ("postgres-host.trade-infra.svc.cluster.local", 5432), - ("redis-host.trade-infra.svc.cluster.local", 6379), - ] + const targets = [ + ['postgres-host.trade-infra.svc.cluster.local', 5432], + ['redis-host.trade-infra.svc.cluster.local', 6379], + ]; - for host, port in targets: - with socket.create_connection((host, port), timeout=5): - print(f"OK {host}:{port}") - PY - kubectl -n trade-r001-canary exec canary-netcheck -- python - <<'PY' - import urllib.request + function checkSocket(host, port) { + return new Promise((resolve, reject) => { + const socket = net.createConnection({ host, port, timeout: 5000 }); + socket.on('connect', () => { + console.log(`OK ${host}:${port}`); + socket.end(); + resolve(); + }); + socket.on('timeout', () => { + socket.destroy(new Error(`Timeout ${host}:${port}`)); + }); + socket.on('error', reject); + }); + } - targets = [ - "http://hasura:8080/healthz", - "http://trade-api:8787/healthz", - "http://trade-frontend:8081/healthz", - ] + (async () => { + for (const [host, port] of targets) { + await checkSocket(host, port); + } + })().catch((err) => { + console.error(String(err && err.message ? err.message : err)); + process.exit(1); + }); + JS + kubectl -n trade-r001-canary exec -i "$pod_name" -- node - <<'JS' + const targets = [ + 'http://hasura:8080/healthz', + 'http://trade-api:8787/healthz', + 'http://trade-frontend:8081/healthz', + ]; - for url in targets: - with urllib.request.urlopen(url, timeout=10) as response: - if response.status != 200: - raise SystemExit(f"Unexpected status for {url}: {response.status}") - print(f"OK {url}") - PY - kubectl -n trade-r001-canary delete pod canary-netcheck --wait=true + (async () => { + for (const url of targets) { + const response = await fetch(url, { signal: AbortSignal.timeout(10000) }); + if (!response.ok) { + throw new Error(`Unexpected status for ${url}: ${response.status}`); + } + console.log(`OK ${url}`); + } + })().catch((err) => { + console.error(String(err && err.message ? err.message : err)); + process.exit(1); + }); + JS