fix: keep env reuse proxy yaml-controlled (#2115)

This commit is contained in:
Lyon
2026-06-25 12:18:10 +08:00
committed by GitHub
parent 270cc8f7cd
commit 661a547f53
3 changed files with 5 additions and 73 deletions
-29
View File
@@ -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;
+4 -3
View File
@@ -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"
]);
+1 -41
View File
@@ -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;