fix: read D518 git mirror refs without status script
This commit is contained in:
@@ -66,6 +66,9 @@ export function nodeRuntimeGitMirrorStatus(scoped: ReturnType<typeof parseNodeSc
|
|||||||
`write_svc=${shellQuote(mirror.serviceWriteName)}`,
|
`write_svc=${shellQuote(mirror.serviceWriteName)}`,
|
||||||
`cache_pvc=${shellQuote(mirror.cachePvcName)}`,
|
`cache_pvc=${shellQuote(mirror.cachePvcName)}`,
|
||||||
`cache_host_path=${shellQuote(mirror.cacheHostPath ?? "")}`,
|
`cache_host_path=${shellQuote(mirror.cacheHostPath ?? "")}`,
|
||||||
|
`source_repository=${shellQuote(mirror.sourceRepository)}`,
|
||||||
|
`source_branch=${shellQuote(mirror.sourceBranch)}`,
|
||||||
|
`gitops_branch=${shellQuote(mirror.gitopsBranch)}`,
|
||||||
`github_transport_mode=${shellQuote(mirror.githubTransport.mode)}`,
|
`github_transport_mode=${shellQuote(mirror.githubTransport.mode)}`,
|
||||||
`github_ssh_secret=${shellQuote(mirror.githubTransport.mode === "ssh" ? mirror.secretName : "")}`,
|
`github_ssh_secret=${shellQuote(mirror.githubTransport.mode === "ssh" ? mirror.secretName : "")}`,
|
||||||
`github_ssh_private_key=${shellQuote(mirror.githubTransport.mode === "ssh" ? mirror.githubTransport.privateKeySecretKey : "")}`,
|
`github_ssh_private_key=${shellQuote(mirror.githubTransport.mode === "ssh" ? mirror.githubTransport.privateKeySecretKey : "")}`,
|
||||||
@@ -114,6 +117,40 @@ export function nodeRuntimeGitMirrorStatus(scoped: ReturnType<typeof parseNodeSc
|
|||||||
"PY",
|
"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)",
|
"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",
|
||||||
|
" 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');",
|
||||||
|
"const repository = process.env.source_repository;",
|
||||||
|
"const sourceBranch = process.env.source_branch;",
|
||||||
|
"const gitopsBranch = process.env.gitops_branch;",
|
||||||
|
"const repoPath = '/cache/' + repository + '.git';",
|
||||||
|
"function readJson(path) { try { return existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : null; } catch { return null; } }",
|
||||||
|
"function rev(ref) { try { return execFileSync('git', ['--git-dir=' + repoPath, 'rev-parse', '--verify', ref + '^{commit}'], { encoding: 'utf8' }).trim(); } catch { return null; } }",
|
||||||
|
"const localSource = rev('refs/heads/' + sourceBranch);",
|
||||||
|
"const githubSource = rev('refs/mirror-stage/heads/' + sourceBranch);",
|
||||||
|
"const localGitops = rev('refs/heads/' + gitopsBranch);",
|
||||||
|
"const githubGitops = rev('refs/mirror-stage/heads/' + gitopsBranch);",
|
||||||
|
"const pendingFlush = Boolean(localGitops && (!githubGitops || localGitops !== githubGitops));",
|
||||||
|
"console.log(JSON.stringify({",
|
||||||
|
" localSource, githubSource, localGitops, githubGitops,",
|
||||||
|
" refSources: {",
|
||||||
|
" localSource: 'refs/heads/' + sourceBranch,",
|
||||||
|
" githubSource: 'refs/mirror-stage/heads/' + sourceBranch,",
|
||||||
|
" localGitops: 'refs/heads/' + gitopsBranch,",
|
||||||
|
" githubGitops: 'refs/mirror-stage/heads/' + gitopsBranch,",
|
||||||
|
" githubFieldsAreMirrorStageCache: true",
|
||||||
|
" },",
|
||||||
|
" pendingFlush,",
|
||||||
|
" flushNeeded: pendingFlush,",
|
||||||
|
" githubInSync: Boolean(localSource && githubSource && localSource === githubSource && localGitops && githubGitops && localGitops === githubGitops),",
|
||||||
|
" statusSource: 'cache-ref-fallback',",
|
||||||
|
" lastSync: readJson('/cache/HWLAB.last-sync.json'),",
|
||||||
|
" lastFlush: readJson('/cache/HWLAB.last-flush.json')",
|
||||||
|
"}));",
|
||||||
|
"NODE",
|
||||||
|
"\" sh \"$source_repository\" \"$source_branch\" \"$gitops_branch\" 2>>/tmp/hwlab-node-gitmirror-status.err || true)",
|
||||||
|
"fi",
|
||||||
"if [ -z \"$summary_json\" ]; then summary_json='{}'; fi",
|
"if [ -z \"$summary_json\" ]; then summary_json='{}'; fi",
|
||||||
"read_deployment_ready=$(deploy_ready \"$namespace\" \"$read_deploy\")",
|
"read_deployment_ready=$(deploy_ready \"$namespace\" \"$read_deploy\")",
|
||||||
"write_deployment_ready=$(deploy_ready \"$namespace\" \"$write_deploy\")",
|
"write_deployment_ready=$(deploy_ready \"$namespace\" \"$write_deploy\")",
|
||||||
|
|||||||
Reference in New Issue
Block a user