fix: tighten branch follower gate runtime inputs
This commit is contained in:
@@ -56,14 +56,14 @@ function gateJobManifest(registry: BranchFollowerRegistry, follower: FollowerSpe
|
||||
const gitopsBranch = agentrun?.gitops.branch ?? "";
|
||||
const healthUrl = agentrun?.runtime.internalBaseUrl ?? "";
|
||||
const workloads = (follower.nativeStatus.runtime?.workloads ?? []).map((item) => ({ kind: item.kind, name: item.name, sourceCommit: item.sourceCommit }));
|
||||
const gatePolicy = gatePolicyEnv(follower);
|
||||
const gateScript = [
|
||||
"set -eu",
|
||||
"tmpdir=$(mktemp -d)",
|
||||
"cleanup() { rm -rf \"$tmpdir\"; }",
|
||||
"trap cleanup EXIT INT TERM",
|
||||
nativeCicdScriptLoadShell(["branch-follower-gate.mjs"]),
|
||||
"/etc/unidesk-cicd-branch-follower/sync-source.sh \"$REPOSITORY\" \"$SOURCE_BRANCH\" \"$SNAPSHOT_PREFIX\" \"$REPO_PATH\" >/tmp/bf-gate-source-sync.json 2>/tmp/bf-gate-source-sync.err || true",
|
||||
"node \"$tmpdir/branch-follower-gate.mjs\"",
|
||||
nativeCicdScriptLoadShell(["branch-follower-gate.sh", "branch-follower-gate.mjs", "reuse-config-summary.mjs"]),
|
||||
"\"$tmpdir/branch-follower-gate.sh\"",
|
||||
].join("\n");
|
||||
return {
|
||||
apiVersion: "batch/v1",
|
||||
@@ -104,6 +104,8 @@ function gateJobManifest(registry: BranchFollowerRegistry, follower: FollowerSpe
|
||||
{ name: "RUNTIME_NAMESPACE", value: follower.nativeStatus.runtime?.namespace ?? "" },
|
||||
{ name: "WORKLOADS_B64", value: Buffer.from(JSON.stringify(workloads), "utf8").toString("base64") },
|
||||
{ name: "HEALTH_URL", value: healthUrl },
|
||||
{ name: "SLOW_TASK_SECONDS", value: String(gatePolicy.slowTaskSeconds) },
|
||||
{ name: "HEALTH_TIMEOUT_MS", value: String(gatePolicy.healthTimeoutMs) },
|
||||
{ name: "UNIDESK_CONTROLLER_GITHUB_SSH_PRIVATE_KEY", value: `/git-ssh/${registry.controller.source.githubSsh.privateKeySecretKey}` },
|
||||
{ name: "UNIDESK_CONTROLLER_GITHUB_PROXY_HOST", value: registry.controller.source.githubSsh.proxyHost },
|
||||
{ name: "UNIDESK_CONTROLLER_GITHUB_PROXY_PORT", value: String(registry.controller.source.githubSsh.proxyPort) },
|
||||
@@ -120,6 +122,16 @@ function gateJobManifest(registry: BranchFollowerRegistry, follower: FollowerSpe
|
||||
};
|
||||
}
|
||||
|
||||
function gatePolicyEnv(follower: FollowerSpec): { slowTaskSeconds: number; healthTimeoutMs: number } {
|
||||
if (follower.drillDown === null) {
|
||||
throw new Error(`follower ${follower.id} registry is missing drillDown policy`);
|
||||
}
|
||||
return {
|
||||
slowTaskSeconds: follower.drillDown.taskRunTimeoutSeconds,
|
||||
healthTimeoutMs: follower.drillDown.taskRunTimeoutSeconds * 1000,
|
||||
};
|
||||
}
|
||||
|
||||
function parseFirstJsonObject(text: string): Record<string, unknown> | null {
|
||||
const start = text.indexOf("{");
|
||||
if (start < 0) return null;
|
||||
|
||||
Reference in New Issue
Block a user