diff --git a/scripts/src/hwlab-node-web-sentinel-cicd.ts b/scripts/src/hwlab-node-web-sentinel-cicd.ts index 2a058c0b..a99d6697 100644 --- a/scripts/src/hwlab-node-web-sentinel-cicd.ts +++ b/scripts/src/hwlab-node-web-sentinel-cicd.ts @@ -2913,19 +2913,29 @@ function callSentinelService(state: SentinelCicdState, method: "GET" | "POST", p const namespace = stringAt(state.runtime, "namespace"); const serviceName = stringAt(state.runtime, "serviceName"); const servicePort = numberAt(state.runtime, "servicePort"); + const deploymentName = stringAt(state.runtime, "deploymentName"); const url = `http://${serviceName}.${namespace}.svc.cluster.local:${servicePort}${pathWithQuery}`; const proxyPath = `/api/v1/namespaces/${namespace}/services/${serviceName}:${servicePort}/proxy${pathWithQuery}`; const bodyB64 = Buffer.from(body === null ? "" : JSON.stringify(body), "utf8").toString("base64"); + const pathB64 = Buffer.from(pathWithQuery, "utf8").toString("base64"); + const postScript = [ + "const path = Buffer.from(process.env.SENTINEL_PATH_B64 || '', 'base64').toString('utf8');", + "const body = Buffer.from(process.env.SENTINEL_BODY_B64 || '', 'base64').toString('utf8');", + `const url = 'http://127.0.0.1:${servicePort}' + path;`, + "fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body }).then(async (response) => {", + " const text = await response.text();", + " process.stdout.write(text);", + " if (!response.ok) process.exit(22);", + "}).catch((error) => {", + " console.error(error && error.stack ? error.stack : String(error));", + " process.exit(23);", + "});", + ].join(" "); const script = method === "GET" ? `kubectl get --raw ${shellQuote(proxyPath)}` : [ "set -eu", - `proxy_path=${shellQuote(proxyPath)}`, - `body_b64=${shellQuote(bodyB64)}`, - "body_file=$(mktemp \"${TMPDIR:-/tmp}/sentinel-service-proxy.body.XXXXXX\")", - "trap 'rm -f \"$body_file\"' EXIT", - "printf %s \"$body_b64\" | base64 -d >\"$body_file\"", - "kubectl create --raw \"$proxy_path\" -f \"$body_file\"", + `kubectl exec -n ${shellQuote(namespace)} deploy/${shellQuote(deploymentName)} -- env SENTINEL_PATH_B64=${shellQuote(pathB64)} SENTINEL_BODY_B64=${shellQuote(bodyB64)} node -e ${shellQuote(postScript)}`, ].join("\n"); const maxAttempts = method === "GET" ? 3 : 1; const attemptTimeoutSeconds = Math.max(5, Math.min(timeoutSeconds, method === "GET" ? 15 : 60));