fix: reuse web sentinel publish run
This commit is contained in:
@@ -2092,7 +2092,7 @@ function sentinelSourceMirrorSshSetupShellLines(state: SentinelCicdState): strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
function runSentinelPublishJob(state: SentinelCicdState, publishGitops: boolean, timeoutSeconds: number): SentinelRemoteJobResult {
|
function runSentinelPublishJob(state: SentinelCicdState, publishGitops: boolean, timeoutSeconds: number): SentinelRemoteJobResult {
|
||||||
const pipelineRunName = `${stringAt(state.cicd, "builder.jobPrefix")}-${Date.now().toString(36)}`.replace(/[^a-z0-9-]/giu, "-").toLowerCase().slice(0, 63);
|
const pipelineRunName = sentinelPipelineRunName(state);
|
||||||
const manifest = sentinelPublishPipelineRunManifest(state, pipelineRunName, publishGitops);
|
const manifest = sentinelPublishPipelineRunManifest(state, pipelineRunName, publishGitops);
|
||||||
const namespace = stringAt(state.cicd, "builder.namespace");
|
const namespace = stringAt(state.cicd, "builder.namespace");
|
||||||
sentinelProgressEvent("sentinel.publish.progress", { phase: "create-pipelinerun", status: "submitting", pipelineRun: pipelineRunName, publishGitops, sourceCommit: state.sourceHead.commit, node: state.spec.nodeId, lane: state.spec.lane });
|
sentinelProgressEvent("sentinel.publish.progress", { phase: "create-pipelinerun", status: "submitting", pipelineRun: pipelineRunName, publishGitops, sourceCommit: state.sourceHead.commit, node: state.spec.nodeId, lane: state.spec.lane });
|
||||||
@@ -2626,12 +2626,19 @@ function createTektonPipelineRunScript(namespace: string, manifest: Record<strin
|
|||||||
"set -eu",
|
"set -eu",
|
||||||
`pipeline_run=${shellQuote(pipelineRunName)}`,
|
`pipeline_run=${shellQuote(pipelineRunName)}`,
|
||||||
`namespace=${shellQuote(namespace)}`,
|
`namespace=${shellQuote(namespace)}`,
|
||||||
"kubectl -n \"$namespace\" delete pipelinerun \"$pipeline_run\" --ignore-not-found=true --wait=false >/dev/null 2>&1 || true",
|
|
||||||
"kubectl -n \"$namespace\" delete taskrun -l tekton.dev/pipelineRun=\"$pipeline_run\" --ignore-not-found=true --wait=false >/dev/null 2>&1 || true",
|
|
||||||
"kubectl -n \"$namespace\" delete pod -l tekton.dev/pipelineRun=\"$pipeline_run\" --ignore-not-found=true --wait=false >/dev/null 2>&1 || true",
|
|
||||||
"tmp=$(mktemp)",
|
"tmp=$(mktemp)",
|
||||||
`cat >"$tmp" <<'YAML'\n${yaml}YAML`,
|
`cat >"$tmp" <<'YAML'\n${yaml}YAML`,
|
||||||
"kubectl apply -f \"$tmp\"",
|
"if kubectl -n \"$namespace\" get pipelinerun \"$pipeline_run\" >/dev/null 2>&1; then",
|
||||||
|
" printf '%s\\n' \"sentinel publish PipelineRun already exists; reusing $pipeline_run\"",
|
||||||
|
" exit 0",
|
||||||
|
"fi",
|
||||||
|
"if ! kubectl create -f \"$tmp\"; then",
|
||||||
|
" if kubectl -n \"$namespace\" get pipelinerun \"$pipeline_run\" >/dev/null 2>&1; then",
|
||||||
|
" printf '%s\\n' \"sentinel publish PipelineRun appeared concurrently; reusing $pipeline_run\"",
|
||||||
|
" exit 0",
|
||||||
|
" fi",
|
||||||
|
" exit 1",
|
||||||
|
"fi",
|
||||||
].join("\n");
|
].join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user