fix: keep v02 config hashes label-safe

This commit is contained in:
Codex
2026-05-31 12:37:46 +08:00
parent 794bea65e8
commit 15294ee30d
3 changed files with 21 additions and 4 deletions
+7 -2
View File
@@ -76,6 +76,11 @@ const codexApiForwarderPort = process.env.HWLAB_G14_CODEX_API_FORWARDER_PORT ||
const codexApiForwarderUpstreamBaseUrl = process.env.HWLAB_G14_CODEX_API_UPSTREAM_BASE_URL || "https://hyueapi.com";
const sourceCommitPattern = /^[a-f0-9]{7,40}$/u;
const v02EnvReuseRuntimeMode = "env-reuse-git-mirror-checkout";
function k8sLabelHash(value) {
return String(value || "").slice(0, 16);
}
const primitiveValidationTasks = Object.freeze([
{
name: "repo-reports-guard",
@@ -3580,7 +3585,7 @@ localPort = 6667
remotePort = ${edgeRemotePort}
`;
const configSha256 = createHash("sha256").update(configText).digest("hex");
const templateLabels = { ...labels, "hwlab.pikastech.local/config-sha256": configSha256 };
const templateLabels = { ...labels, "hwlab.pikastech.local/config-sha256": k8sLabelHash(configSha256) };
const templateAnnotations = { "hwlab.pikastech.local/config-sha256": configSha256 };
return {
apiVersion: "v1",
@@ -4036,7 +4041,7 @@ function v02PostgresManifest({ migrationSql, source }) {
"hwlab.pikastech.local/environment": "v02",
"hwlab.pikastech.local/gitops-target": "v02",
"hwlab.pikastech.local/profile": "v02",
"hwlab.pikastech.local/migration-sha256": migrationSha256
"hwlab.pikastech.local/migration-sha256": k8sLabelHash(migrationSha256)
};
const templateAnnotations = { "hwlab.pikastech.local/migration-sha256": migrationSha256 };
return {
+12 -2
View File
@@ -243,12 +243,22 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots
}
const frpc = JSON.parse(await readFile(path.join(outDir, "runtime-v02", "g14-frpc.yaml"), "utf8"));
const frpcDeployment = frpc.items.find((item) => item.kind === "Deployment");
assert.ok(frpcDeployment.spec.template.metadata.labels["hwlab.pikastech.local/config-sha256"]);
const frpcConfigLabel = frpcDeployment.spec.template.metadata.labels["hwlab.pikastech.local/config-sha256"];
const frpcConfigAnnotation = frpcDeployment.spec.template.metadata.annotations["hwlab.pikastech.local/config-sha256"];
assert.ok(frpcConfigLabel);
assert.equal(frpcConfigLabel.length <= 63, true);
assert.match(frpcConfigAnnotation, /^[a-f0-9]{64}$/u);
assert.equal(frpcConfigAnnotation.startsWith(frpcConfigLabel), true);
assert.equal(frpcDeployment.spec.template.metadata.labels["hwlab.pikastech.local/source-commit"], undefined);
const postgres = JSON.parse(await readFile(path.join(outDir, "runtime-v02", "postgres.yaml"), "utf8"));
const postgresStatefulSet = postgres.items.find((item) => item.kind === "StatefulSet");
assert.ok(postgresStatefulSet.spec.template.metadata.labels["hwlab.pikastech.local/migration-sha256"]);
const postgresMigrationLabel = postgresStatefulSet.spec.template.metadata.labels["hwlab.pikastech.local/migration-sha256"];
const postgresMigrationAnnotation = postgresStatefulSet.spec.template.metadata.annotations["hwlab.pikastech.local/migration-sha256"];
assert.ok(postgresMigrationLabel);
assert.equal(postgresMigrationLabel.length <= 63, true);
assert.match(postgresMigrationAnnotation, /^[a-f0-9]{64}$/u);
assert.equal(postgresMigrationAnnotation.startsWith(postgresMigrationLabel), true);
assert.equal(postgresStatefulSet.spec.template.metadata.labels["hwlab.pikastech.local/source-commit"], undefined);
await assert.rejects(() => readFile(path.join(outDir, "tekton-v02", "control-plane-reconciler.yaml"), "utf8"), { code: "ENOENT" });