diff --git a/scripts/src/agentrun.ts b/scripts/src/agentrun.ts index 30a48020..679dc298 100644 --- a/scripts/src/agentrun.ts +++ b/scripts/src/agentrun.ts @@ -69,7 +69,9 @@ async function status(config: UniDeskConfig): Promise> { `git ls-remote origin ${gitopsBranch} 2>/dev/null | awk '{print $1}' || true`, "git status --short --branch", ].join("\n")]); - const sourceCommit = matchLine(source.stdout, "sourceCommit="); + const localSourceCommit = matchLine(source.stdout, "sourceCommit="); + const originSourceCommit = matchLine(source.stdout, "originV01="); + const sourceCommit = isGitSha(originSourceCommit ?? "") ? originSourceCommit : localSourceCommit; const gitopsLatest = matchLine(source.stdout, "gitopsLatest="); const pipelineRun = sourceCommit ? pipelineRunName(sourceCommit) : null; const k3s = await capture(config, g14K3sRoute, ["script", "--", statusScript(pipelineRun)]); @@ -79,11 +81,15 @@ async function status(config: UniDeskConfig): Promise> { command: "agentrun v01 control-plane status", lane: "v0.1", sourceCommit, + sourceCommitSource: sourceCommit === originSourceCommit ? "origin/v0.1" : "local-head", + localSourceCommit, + originSourceCommit, gitopsLatest, expectedPipelineRun: pipelineRun, source: compactCapture(source), runtime: compactCapture(k3s), runtimeAlignment: { + localHeadMatchesOrigin: Boolean(localSourceCommit && originSourceCommit && localSourceCommit === originSourceCommit), argoRevision: argo.revision, argoSyncStatus: argo.syncStatus, argoHealthStatus: argo.healthStatus, @@ -101,9 +107,12 @@ async function triggerCurrent(config: UniDeskConfig, options: TriggerOptions): P "set -eu", "cd /root/agentrun-v01", "git fetch origin v0.1", - "git pull --ff-only origin v0.1", + "git merge --ff-only refs/remotes/origin/v0.1", "printf 'sourceCommit='", "git rev-parse HEAD", + "printf 'originV01='", + "git rev-parse refs/remotes/origin/v0.1", + "git status --short --branch", ].join("\n")]); const sourceCommit = matchLine(source.stdout, "sourceCommit="); const pipelineRun = sourceCommit ? pipelineRunName(sourceCommit) : null; @@ -198,7 +207,13 @@ function statusScript(pipelineRun: string | null): string { "printf 'argo\\n'", `kubectl -n ${argoNamespace} get application ${argoApplication} -o 'jsonpath={.status.sync.revision}{"\\t"}{.status.sync.status}{"\\t"}{.status.health.status}{"\\n"}' 2>/dev/null || true`, "printf 'workloads\\n'", - `kubectl -n ${runtimeNamespace} get deploy,sts,pod -o wide 2>/dev/null || true`, + `kubectl -n ${runtimeNamespace} get deploy,sts -o wide 2>/dev/null || true`, + "printf 'managerImage\\n'", + `kubectl -n ${runtimeNamespace} get deploy agentrun-mgr -o 'jsonpath={.spec.template.spec.containers[0].image}{"\\t"}{.spec.template.spec.containers[0].env[?(@.name=="AGENTRUN_SOURCE_COMMIT")].value}{"\\n"}' 2>/dev/null || true`, + "printf 'managerPods\\n'", + `kubectl -n ${runtimeNamespace} get pod -l app.kubernetes.io/name=agentrun-mgr -o 'custom-columns=NAME:.metadata.name,READY:.status.containerStatuses[*].ready,STATUS:.status.phase,RESTARTS:.status.containerStatuses[*].restartCount,CREATED:.metadata.creationTimestamp' --no-headers 2>/dev/null || true`, + "printf 'recentRunnerPods\\n'", + `kubectl -n ${runtimeNamespace} get pod -l app.kubernetes.io/component=runner --sort-by=.metadata.creationTimestamp -o 'custom-columns=NAME:.metadata.name,READY:.status.containerStatuses[*].ready,STATUS:.status.phase,RESTARTS:.status.containerStatuses[*].restartCount,CREATED:.metadata.creationTimestamp' --no-headers 2>/dev/null | tail -n 8 || true`, ].join("\n"); }