feat: add JD01 YAML-first deployment support
This commit is contained in:
@@ -117,7 +117,14 @@ export function nodeRuntimeGitMirrorStatus(scoped: ReturnType<typeof parseNodeSc
|
||||
"PY",
|
||||
")",
|
||||
"summary_json=$(kubectl -n \"$namespace\" exec deploy/\"$read_deploy\" -- sh -lc '/etc/git-mirror/status.sh' 2>/tmp/hwlab-node-gitmirror-status.err || true)",
|
||||
"if ! printf '%s' \"$summary_json\" | node -e 'let s=\"\"; process.stdin.on(\"data\", c => s += c); process.stdin.on(\"end\", () => { try { const o = JSON.parse(s || \"{}\"); process.exit(o && o.localSource ? 0 : 1); } catch { process.exit(1); } });'; then",
|
||||
"if ! SUMMARY_JSON=\"$summary_json\" python3 - <<'PY'; then",
|
||||
"import json, os, sys",
|
||||
"try:",
|
||||
" value = json.loads(os.environ.get('SUMMARY_JSON') or '{}')",
|
||||
"except Exception:",
|
||||
" value = {}",
|
||||
"sys.exit(0 if isinstance(value, dict) and value.get('localSource') else 1)",
|
||||
"PY",
|
||||
" summary_json=$(kubectl -n \"$namespace\" exec deploy/\"$read_deploy\" -- sh -lc \"source_repository=\\$1 source_branch=\\$2 gitops_branch=\\$3 node <<'NODE'",
|
||||
"const { execFileSync } = require('node:child_process');",
|
||||
"const { readFileSync, existsSync } = require('node:fs');",
|
||||
@@ -161,29 +168,37 @@ export function nodeRuntimeGitMirrorStatus(scoped: ReturnType<typeof parseNodeSc
|
||||
"cache_pvc_exists=$(exists_res \"$namespace\" pvc \"$cache_pvc\")",
|
||||
"cache_host_path_exists=false",
|
||||
"if [ -n \"$cache_host_path\" ] && kubectl -n \"$namespace\" exec deploy/\"$read_deploy\" -- sh -lc 'test -d /cache' >/dev/null 2>&1; then cache_host_path_exists=true; fi",
|
||||
"SUMMARY_JSON=\"$summary_json\" GITHUB_TRANSPORT_JSON=\"$github_transport_json\" read_deployment_ready=\"$read_deployment_ready\" write_deployment_ready=\"$write_deployment_ready\" read_service_exists=\"$read_service_exists\" write_service_exists=\"$write_service_exists\" read_endpoints_ready=\"$read_endpoints_ready\" write_endpoints_ready=\"$write_endpoints_ready\" cache_pvc_exists=\"$cache_pvc_exists\" cache_host_path=\"$cache_host_path\" cache_host_path_exists=\"$cache_host_path_exists\" node <<'NODE'",
|
||||
"const summary = (() => { try { return JSON.parse(process.env.SUMMARY_JSON || '{}'); } catch { return {}; } })();",
|
||||
"const githubTransport = (() => { try { return JSON.parse(process.env.GITHUB_TRANSPORT_JSON || '{}'); } catch { return {}; } })();",
|
||||
"const env = process.env;",
|
||||
"const ok = env.read_deployment_ready === 'true' && env.write_deployment_ready === 'true' && env.read_service_exists === 'true' && env.write_service_exists === 'true' && env.read_endpoints_ready === 'true' && env.write_endpoints_ready === 'true' && (env.cache_pvc_exists === 'true' || env.cache_host_path_exists === 'true') && githubTransport.ready !== false && summary.localSource;",
|
||||
"console.log(JSON.stringify({",
|
||||
" ok: Boolean(ok),",
|
||||
" resources: {",
|
||||
" readDeploymentReady: env.read_deployment_ready === 'true',",
|
||||
" writeDeploymentReady: env.write_deployment_ready === 'true',",
|
||||
" readServiceExists: env.read_service_exists === 'true',",
|
||||
" writeServiceExists: env.write_service_exists === 'true',",
|
||||
" readEndpointsReady: env.read_endpoints_ready === 'true',",
|
||||
" writeEndpointsReady: env.write_endpoints_ready === 'true',",
|
||||
" cachePvcExists: env.cache_pvc_exists === 'true',",
|
||||
" cacheHostPathConfigured: Boolean(env.cache_host_path),",
|
||||
" cacheHostPathExists: env.cache_host_path_exists === 'true'",
|
||||
" },",
|
||||
" githubTransport,",
|
||||
" summary,",
|
||||
" valuesPrinted: false",
|
||||
"}));",
|
||||
"NODE",
|
||||
"SUMMARY_JSON=\"$summary_json\" GITHUB_TRANSPORT_JSON=\"$github_transport_json\" read_deployment_ready=\"$read_deployment_ready\" write_deployment_ready=\"$write_deployment_ready\" read_service_exists=\"$read_service_exists\" write_service_exists=\"$write_service_exists\" read_endpoints_ready=\"$read_endpoints_ready\" write_endpoints_ready=\"$write_endpoints_ready\" cache_pvc_exists=\"$cache_pvc_exists\" cache_host_path=\"$cache_host_path\" cache_host_path_exists=\"$cache_host_path_exists\" python3 - <<'PY'",
|
||||
"import json, os",
|
||||
"def load_env_json(name):",
|
||||
" try:",
|
||||
" value = json.loads(os.environ.get(name) or '{}')",
|
||||
" return value if isinstance(value, dict) else {}",
|
||||
" except Exception:",
|
||||
" return {}",
|
||||
"def truth(name):",
|
||||
" return os.environ.get(name) == 'true'",
|
||||
"summary = load_env_json('SUMMARY_JSON')",
|
||||
"github_transport = load_env_json('GITHUB_TRANSPORT_JSON')",
|
||||
"ok = truth('read_deployment_ready') and truth('write_deployment_ready') and truth('read_service_exists') and truth('write_service_exists') and truth('read_endpoints_ready') and truth('write_endpoints_ready') and (truth('cache_pvc_exists') or truth('cache_host_path_exists')) and github_transport.get('ready') is not False and bool(summary.get('localSource'))",
|
||||
"print(json.dumps({",
|
||||
" 'ok': bool(ok),",
|
||||
" 'resources': {",
|
||||
" 'readDeploymentReady': truth('read_deployment_ready'),",
|
||||
" 'writeDeploymentReady': truth('write_deployment_ready'),",
|
||||
" 'readServiceExists': truth('read_service_exists'),",
|
||||
" 'writeServiceExists': truth('write_service_exists'),",
|
||||
" 'readEndpointsReady': truth('read_endpoints_ready'),",
|
||||
" 'writeEndpointsReady': truth('write_endpoints_ready'),",
|
||||
" 'cachePvcExists': truth('cache_pvc_exists'),",
|
||||
" 'cacheHostPathConfigured': bool(os.environ.get('cache_host_path')),",
|
||||
" 'cacheHostPathExists': truth('cache_host_path_exists'),",
|
||||
" },",
|
||||
" 'githubTransport': github_transport,",
|
||||
" 'summary': summary,",
|
||||
" 'valuesPrinted': False,",
|
||||
"}))",
|
||||
"PY",
|
||||
].join("\n");
|
||||
const result = runNodeK3sScript(spec, script, scoped.timeoutSeconds);
|
||||
const parsed = record(parseJsonObject(statusText(result)));
|
||||
@@ -240,7 +255,9 @@ export function nodeRuntimeGitMirrorRun(scoped: ReturnType<typeof parseNodeScope
|
||||
for (let attempt = 1; attempt <= retryMaxAttempts; attempt += 1) {
|
||||
const retryLabel = `${attempt}/${retryMaxAttempts}`;
|
||||
const jobName = nodeRuntimeGitMirrorJobName(mirror, scoped.action);
|
||||
const manifest = nodeRuntimeGitMirrorJobManifest(mirror, scoped.action, jobName);
|
||||
const manifest = nodeRuntimeGitMirrorJobManifest(mirror, scoped.action, jobName, {
|
||||
discardStaleGitops: scoped.discardStaleGitops === true,
|
||||
});
|
||||
const manifestB64 = Buffer.from(JSON.stringify(manifest), "utf8").toString("base64");
|
||||
const waitTimeoutSeconds = Math.max(5, Math.min(45, Math.max(5, scoped.timeoutSeconds - 10)));
|
||||
const script = [
|
||||
@@ -429,7 +446,7 @@ export function nodeRuntimeGitMirrorRetryableFailure(
|
||||
: waitTimeoutFailure
|
||||
? "Git mirror job wait exceeded the controlled short-connection budget. Standard git-mirror retries with exponential backoff and stops when retry budget is exhausted."
|
||||
: proxyConnectFailure || sshProxyBannerFailure
|
||||
? "Git mirror job hit a retryable YAML-first SSH-over-proxy failure. Standard git-mirror keeps using the configured node-global proxy and stops when retry budget is exhausted."
|
||||
? "Git mirror job hit a retryable YAML-first SSH-over-proxy failure. Standard git-mirror keeps using the configured proxy and stops when retry budget is exhausted."
|
||||
: `Git mirror job hit a retryable upstream GitHub ${mirror.githubTransport.mode} transport/fetch failure. Standard git-mirror stops without host workspace fallback.`,
|
||||
refSources: nodeRuntimeGitMirrorRefSources(scoped, mirror),
|
||||
githubTransport: nodeRuntimeGitMirrorGithubTransportSummary(mirror),
|
||||
@@ -489,7 +506,15 @@ export function nodeRuntimeEnsureGitMirrorSourceCurrent(scoped: ReturnType<typeo
|
||||
degradedReason: flush.ok === true ? undefined : "node-runtime-git-mirror-pre-flush-failed",
|
||||
};
|
||||
}
|
||||
const sync = nodeRuntimeGitMirrorRun({ ...scoped, domain: "git-mirror", action: "sync", confirm: true, dryRun: false, wait: true });
|
||||
const sync = nodeRuntimeGitMirrorRun({
|
||||
...scoped,
|
||||
domain: "git-mirror",
|
||||
action: "sync",
|
||||
confirm: true,
|
||||
dryRun: false,
|
||||
wait: true,
|
||||
discardStaleGitops: scoped.discardStaleGitops === true || scoped.rerun === true,
|
||||
});
|
||||
const after = record(sync.status);
|
||||
const afterSummary = Object.keys(after).length > 0 ? compactNodeRuntimeGitMirrorStatus(after) : {};
|
||||
const sourceOk = sync.ok === true && afterSummary.localSource === sourceCommit && afterSummary.githubSource === sourceCommit;
|
||||
@@ -633,7 +658,6 @@ export function nodeRuntimeGitMirrorNeedsFlush(status: Record<string, unknown>):
|
||||
const githubGitops = typeof summary.githubGitops === "string" ? summary.githubGitops : null;
|
||||
return summary.pendingFlush === true
|
||||
|| summary.flushNeeded === true
|
||||
|| summary.githubInSync === false
|
||||
|| (localGitops !== null && githubGitops !== null && localGitops !== githubGitops);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user