fix: refresh v02 control plane before trigger

This commit is contained in:
Codex
2026-05-31 04:27:10 +00:00
parent 003b0ae7fc
commit 69f72a49cb
2 changed files with 53 additions and 1 deletions
+52
View File
@@ -751,6 +751,36 @@ function applyV02ControlPlaneFiles(sourceCommit: string, dryRun: boolean, timeou
], timeoutSeconds * 1000);
}
function refreshV02ControlPlaneBeforeTrigger(sourceCommit: string, timeoutSeconds: number): Record<string, unknown> {
const renderCheck = runV02RenderCheck(sourceCommit);
if (!isCommandSuccess(renderCheck)) {
return {
ok: false,
phase: "source-render-check",
sourceCommit,
renderDir: v02RenderDir(sourceCommit),
renderCheck,
degradedReason: "control-plane-render-check-failed",
};
}
const apply = applyV02ControlPlaneFiles(sourceCommit, false, timeoutSeconds);
const cleanupObsoleteCronJobs = isCommandSuccess(apply) ? deleteV02ObsoleteCronJobs(false) : null;
return {
ok: isCommandSuccess(apply) && (cleanupObsoleteCronJobs === null || isCommandSuccess(cleanupObsoleteCronJobs)),
phase: "control-plane-refresh",
sourceCommit,
renderDir: v02RenderDir(sourceCommit),
renderCheck: commandData(renderCheck),
apply,
cleanupObsoleteCronJobs,
degradedReason: !isCommandSuccess(apply)
? "control-plane-apply-failed"
: cleanupObsoleteCronJobs !== null && !isCommandSuccess(cleanupObsoleteCronJobs)
? "obsolete-cronjob-cleanup-failed"
: undefined,
};
}
function getV02ObsoleteCronJobs(): CommandJsonResult {
return g14K3s([
"kubectl",
@@ -959,6 +989,11 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
pipelineRun: v02PipelineRunName(sourceCommit),
before,
gitMirrorPreSync,
controlPlaneRefresh: {
mode: "skipped-dry-run",
wouldRefreshBeforeCreate: true,
resources: ["tekton-v02/rbac.yaml", "tekton-v02/pipeline.yaml", "argocd/project.yaml", "argocd/application-v02.yaml"],
},
manifest: v02PipelineRunManifest(sourceCommit),
next: { triggerCurrent: "bun scripts/cli.ts hwlab g14 control-plane trigger-current --lane v02 --confirm" },
};
@@ -975,6 +1010,21 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
degradedReason: "refuse-active-or-successful-pipelinerun",
};
}
const controlPlaneRefresh = refreshV02ControlPlaneBeforeTrigger(sourceCommit, options.timeoutSeconds);
if (controlPlaneRefresh.ok !== true) {
return {
ok: false,
command: "hwlab g14 control-plane trigger-current --lane v02",
lane: "v02",
mode: "confirmed-trigger",
phase: "control-plane-refresh",
sourceCommit,
pipelineRun: v02PipelineRunName(sourceCommit),
before,
controlPlaneRefresh,
degradedReason: record(controlPlaneRefresh).degradedReason ?? "control-plane-refresh-failed",
};
}
const gitMirrorPreSync = preSyncV02GitMirror(sourceCommit, options);
if (gitMirrorPreSync.ok !== true) {
return {
@@ -986,6 +1036,7 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
sourceCommit,
pipelineRun: v02PipelineRunName(sourceCommit),
before,
controlPlaneRefresh,
gitMirrorPreSync,
degradedReason: "git-mirror-pre-sync-failed",
};
@@ -1002,6 +1053,7 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
sourceCommit,
pipelineRun: v02PipelineRunName(sourceCommit),
before,
controlPlaneRefresh,
gitMirrorPreSync,
deletePipelineRun,
createPipelineRun,