fix: 归一 PaC admission 等价差异

This commit is contained in:
Codex
2026-07-13 09:06:36 +02:00
parent 84fa08572e
commit b929e4356e
3 changed files with 119 additions and 9 deletions
@@ -94,6 +94,10 @@ function missing(reason, sourceCommit = null) {
function isAdmissionDefault(path, value) {
const normalized = path.map((segment) => typeof segment === "number" ? "*" : segment).join(".");
const emptyRecord = value !== null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
if ([
"spec.workspaces.*.volumeClaimTemplate.metadata",
"spec.workspaces.*.volumeClaimTemplate.status",
].includes(normalized)) return emptyRecord;
const atTaskSpec = (suffix) => [
`tasks.*.taskSpec.${suffix}`,
`spec.tasks.*.taskSpec.${suffix}`,
@@ -110,6 +114,8 @@ function isAdmissionDefault(path, value) {
export function canonicalizePacPipelineSpec(value, path = []) {
if (Array.isArray(value)) return value.map((item, index) => canonicalizePacPipelineSpec(item, [...path, index]));
const duration = canonicalTektonPipelineTimeout(path, value);
if (duration !== null) return duration;
if (value === null || typeof value !== "object") return value;
const output = {};
for (const key of Object.keys(value).sort()) {
@@ -121,6 +127,38 @@ export function canonicalizePacPipelineSpec(value, path = []) {
return output;
}
function canonicalTektonPipelineTimeout(path, value) {
if (path.join(".") !== "spec.timeouts.pipeline" || typeof value !== "string") return null;
const matchSign = /^([+-]?)(.*)$/u.exec(value);
if (matchSign === null) return null;
const source = matchSign[2] ?? "";
const units = {
h: 3_600_000_000_000n,
m: 60_000_000_000n,
s: 1_000_000_000n,
ms: 1_000_000n,
us: 1_000n,
"µs": 1_000n,
"μs": 1_000n,
ns: 1n,
};
const segment = /([0-9]+)(ns|us|µs|μs|ms|s|m|h)/uy;
let offset = 0;
let nanoseconds = 0n;
let count = 0;
while (offset < source.length) {
segment.lastIndex = offset;
const matched = segment.exec(source);
if (matched === null) return null;
nanoseconds += BigInt(matched[1] ?? "0") * (units[matched[2] ?? ""] ?? 0n);
offset = segment.lastIndex;
count += 1;
}
if (count === 0) return null;
if (matchSign[1] === "-") nanoseconds = -nanoseconds;
return `tekton-duration-ns:${nanoseconds}`;
}
export function canonicalPacPipelineSha256(value) {
return `sha256:${createHash("sha256").update(JSON.stringify(canonicalizePacPipelineSpec(value))).digest("hex")}`;
}