From 661a547f53c8756330ccd64090f8191bea5aef29 Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Thu, 25 Jun 2026 12:18:10 +0800 Subject: [PATCH] fix: keep env reuse proxy yaml-controlled (#2115) --- scripts/artifact-publish.mjs | 29 ------------------------- scripts/ci-plan.test.mjs | 7 +++--- scripts/src/ci-plan-lib.mjs | 42 +----------------------------------- 3 files changed, 5 insertions(+), 73 deletions(-) diff --git a/scripts/artifact-publish.mjs b/scripts/artifact-publish.mjs index 7b0a3154..dccaff24 100644 --- a/scripts/artifact-publish.mjs +++ b/scripts/artifact-publish.mjs @@ -990,7 +990,6 @@ function normalizeEnvReuseRecipe(recipe) { } function normalizeDownloadStack(value) { - value = effectiveDownloadStackConfig(value, process.env); assert.ok(value && typeof value === "object", "envRecipe.downloadStack must be configured in deploy/deploy.yaml"); const normalized = { httpProxy: normalizeOptionalHttpUrl(value.httpProxy), @@ -1010,34 +1009,6 @@ function normalizeDownloadStack(value) { return normalized; } -function effectiveDownloadStackConfig(value, env = process.env) { - if (!value || typeof value !== "object" || !usesK8sNativeDownloadProxy(env)) return value; - const httpProxy = textEnv(env.HTTP_PROXY) || textEnv(env.http_proxy) || value.httpProxy; - const httpsProxy = textEnv(env.HTTPS_PROXY) || textEnv(env.https_proxy) || httpProxy || value.httpsProxy; - const noProxy = noProxyFromEnv(env) || value.noProxy; - return { - ...value, - httpProxy, - httpsProxy, - noProxy - }; -} - -function usesK8sNativeDownloadProxy(env = process.env) { - return env.HWLAB_DEV_REGISTRY_K8S_NATIVE === "1" || Boolean(textEnv(env.HWLAB_TEKTON_PIPELINERUN)); -} - -function noProxyFromEnv(env = process.env) { - const text = textEnv(env.NO_PROXY) || textEnv(env.no_proxy); - if (!text) return null; - return text.split(",").map((item) => item.trim()).filter(Boolean); -} - -function textEnv(value) { - const text = String(value ?? "").trim(); - return text || null; -} - function normalizeOptionalHttpUrl(value) { const text = String(value ?? "").trim(); if (!text) return null; diff --git a/scripts/ci-plan.test.mjs b/scripts/ci-plan.test.mjs index 44b1d504..e04823f5 100644 --- a/scripts/ci-plan.test.mjs +++ b/scripts/ci-plan.test.mjs @@ -749,7 +749,7 @@ test("v02 planner reads env reuse declarations and recipe from deploy config", a assert.equal(recipe.launcherInputPaths.includes("custom/env-tool.mjs"), true); }); -test("planner sanitizes k8s native download no_proxy to internal targets", async () => { +test("planner keeps YAML download proxy authority under Tekton env", async () => { const repo = await createFixtureRepo(); const previousEnv = { HWLAB_TEKTON_PIPELINERUN: process.env.HWLAB_TEKTON_PIPELINERUN, @@ -784,11 +784,12 @@ test("planner sanitizes k8s native download no_proxy to internal targets", async services: ["hwlab-cloud-api"] }); const noProxy = plan.services[0].envReuseRecipe.downloadStack.noProxy; + assert.equal(plan.services[0].envReuseRecipe.downloadStack.httpProxy, "http://127.0.0.1:10808"); + assert.equal(plan.services[0].envReuseRecipe.downloadStack.httpsProxy, "http://127.0.0.1:10808"); assert.deepEqual(noProxy, [ "127.0.0.1", "localhost", - "10.43.0.0/16", - "git-mirror-http.devops-infra.svc.cluster.local", + "::1", "hyueapi.com", ".hyueapi.com" ]); diff --git a/scripts/src/ci-plan-lib.mjs b/scripts/src/ci-plan-lib.mjs index 673795c0..507b938e 100644 --- a/scripts/src/ci-plan-lib.mjs +++ b/scripts/src/ci-plan-lib.mjs @@ -467,7 +467,7 @@ function envReuseRecipeForService(recipe, model) { } function normalizeDownloadStack(value, lane) { - const configured = effectiveDownloadStackConfig(value, process.env); + const configured = value && typeof value === "object" ? value : null; if (!configured) throw new Error(`deploy.lanes.${lane}.envRecipe.downloadStack is required`); const httpProxy = normalizeOptionalHttpUrl(configured.httpProxy, `deploy.lanes.${lane}.envRecipe.downloadStack.httpProxy`); const httpsProxy = normalizeOptionalHttpUrl(configured.httpsProxy, `deploy.lanes.${lane}.envRecipe.downloadStack.httpsProxy`); @@ -493,46 +493,6 @@ function normalizeDownloadStack(value, lane) { }; } -function effectiveDownloadStackConfig(value, env = process.env) { - const configured = value && typeof value === "object" ? value : null; - if (!configured || !usesK8sNativeDownloadProxy(env)) return configured; - const httpProxy = normalizeDeclarationString(env.HTTP_PROXY) || normalizeDeclarationString(env.http_proxy) || configured.httpProxy; - const httpsProxy = normalizeDeclarationString(env.HTTPS_PROXY) || normalizeDeclarationString(env.https_proxy) || httpProxy || configured.httpsProxy; - const noProxy = sanitizeK8sDownloadNoProxy(noProxyFromEnv(env) || configured.noProxy); - return { - ...configured, - httpProxy, - httpsProxy, - noProxy - }; -} - -function usesK8sNativeDownloadProxy(env = process.env) { - return env.HWLAB_DEV_REGISTRY_K8S_NATIVE === "1" || Boolean(normalizeDeclarationString(env.HWLAB_TEKTON_PIPELINERUN)); -} - -function noProxyFromEnv(env = process.env) { - const text = normalizeDeclarationString(env.NO_PROXY) || normalizeDeclarationString(env.no_proxy); - if (!text) return null; - return text.split(",").map((item) => item.trim()).filter(Boolean); -} - -function sanitizeK8sDownloadNoProxy(values) { - return uniquePreserveOrder(normalizeStringList(values, []).filter(isK8sDownloadNoProxyEntry)); -} - -function isK8sDownloadNoProxyEntry(value) { - const item = String(value ?? "").trim().toLowerCase(); - if (!item || item === "*") return false; - if (["localhost", "::1", "[::1]", "hyueapi.com", ".hyueapi.com"].includes(item)) return true; - if (item.endsWith(".hyueapi.com")) return true; - if (item === ".svc" || item === ".svc.cluster.local" || item === ".cluster.local") return true; - if (item.endsWith(".svc") || item.endsWith(".svc.cluster.local") || item.endsWith(".cluster.local")) return true; - if (/^(127|10)\./u.test(item) || /^192\.168\./u.test(item) || /^172\.(1[6-9]|2\d|3[01])\./u.test(item)) return true; - if (/^(127|10)\.[0-9./:-]+$/u.test(item) || /^192\.168\.[0-9./:-]+$/u.test(item) || /^172\.(1[6-9]|2\d|3[01])\.[0-9./:-]+$/u.test(item)) return true; - return false; -} - function normalizeOptionalHttpUrl(value, label) { const text = normalizeDeclarationString(value); if (!text) return null;