fix: compact branch follower list status
This commit is contained in:
@@ -572,10 +572,11 @@ async function buildStatus(registry: BranchFollowerRegistry, options: ParsedOpti
|
|||||||
const shouldLive = wantsLive && options.inCluster;
|
const shouldLive = wantsLive && options.inCluster;
|
||||||
const selected = selectFollowers(registry, options, { includeDisabled: true });
|
const selected = selectFollowers(registry, options, { includeDisabled: true });
|
||||||
const followers = [];
|
const followers = [];
|
||||||
|
const detailedFollowers = options.followerId !== null || options.full;
|
||||||
for (const follower of selected) {
|
for (const follower of selected) {
|
||||||
const stored = k8s.stateByFollower[follower.id] ?? {};
|
const stored = k8s.stateByFollower[follower.id] ?? {};
|
||||||
const live = shouldLive && follower.enabled ? await readAdapterStatus(registry, follower, options) : null;
|
const live = shouldLive && follower.enabled ? await readAdapterStatus(registry, follower, options) : null;
|
||||||
followers.push(mergeFollowerStatus(registry, follower, stored, live, shouldLive));
|
followers.push(mergeFollowerStatus(registry, follower, stored, live, shouldLive, detailedFollowers));
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
ok: k8s.ok && followers.every((item) => item.ok !== false),
|
ok: k8s.ok && followers.every((item) => item.ok !== false),
|
||||||
@@ -1808,6 +1809,7 @@ function mergeFollowerStatus(
|
|||||||
stored: Record<string, unknown>,
|
stored: Record<string, unknown>,
|
||||||
live: AdapterSummary | null,
|
live: AdapterSummary | null,
|
||||||
liveRequested: boolean,
|
liveRequested: boolean,
|
||||||
|
detailed: boolean,
|
||||||
): Record<string, unknown> {
|
): Record<string, unknown> {
|
||||||
const storedSource = asOptionalRecord(stored.source);
|
const storedSource = asOptionalRecord(stored.source);
|
||||||
const storedTarget = asOptionalRecord(stored.target);
|
const storedTarget = asOptionalRecord(stored.target);
|
||||||
@@ -1816,7 +1818,7 @@ function mergeFollowerStatus(
|
|||||||
const targetSha = live?.targetSha ?? stringOrNull(storedTarget?.targetSha);
|
const targetSha = live?.targetSha ?? stringOrNull(storedTarget?.targetSha);
|
||||||
const lastTriggeredSha = live?.lastTriggeredSha ?? stringOrNull(stored.lastTriggeredSha);
|
const lastTriggeredSha = live?.lastTriggeredSha ?? stringOrNull(stored.lastTriggeredSha);
|
||||||
const lastSucceededSha = live?.lastSucceededSha ?? stringOrNull(stored.lastSucceededSha);
|
const lastSucceededSha = live?.lastSucceededSha ?? stringOrNull(stored.lastSucceededSha);
|
||||||
return {
|
const summary: Record<string, unknown> = {
|
||||||
ok: live === null ? true : live.ok,
|
ok: live === null ? true : live.ok,
|
||||||
id: follower.id,
|
id: follower.id,
|
||||||
enabled: follower.enabled,
|
enabled: follower.enabled,
|
||||||
@@ -1826,7 +1828,6 @@ function mergeFollowerStatus(
|
|||||||
repository: follower.source.repository,
|
repository: follower.source.repository,
|
||||||
branch: follower.source.branch,
|
branch: follower.source.branch,
|
||||||
observedSha,
|
observedSha,
|
||||||
snapshotPrefix: follower.source.snapshotPrefix,
|
|
||||||
},
|
},
|
||||||
target: {
|
target: {
|
||||||
node: follower.target.node,
|
node: follower.target.node,
|
||||||
@@ -1839,12 +1840,21 @@ function mergeFollowerStatus(
|
|||||||
lastSucceededSha,
|
lastSucceededSha,
|
||||||
pipelineRun: live?.pipelineRun ?? stringOrNull(stored.pipelineRun),
|
pipelineRun: live?.pipelineRun ?? stringOrNull(stored.pipelineRun),
|
||||||
inFlightJob: live?.inFlightJob ?? stringOrNull(stored.inFlightJob),
|
inFlightJob: live?.inFlightJob ?? stringOrNull(stored.inFlightJob),
|
||||||
budgetSource: follower.budgets,
|
|
||||||
updatedAt: stringOrNull(stored.updatedAt),
|
updatedAt: stringOrNull(stored.updatedAt),
|
||||||
stateConfigMap: registry.controller.stateConfigMapName,
|
|
||||||
live: liveRequested,
|
live: liveRequested,
|
||||||
message: live?.message ?? stringOrNull(stored.decision) ?? "no controller state yet",
|
message: live?.message ?? stringOrNull(stored.decision) ?? "no controller state yet",
|
||||||
timings: live === null ? storedFollowerTimingsForStatus(follower, asOptionalRecord(stored.timings), phase, observedSha) : buildFollowerTimings(follower, live, undefined, asOptionalRecord(stored.timings), phase),
|
timings: live === null ? storedFollowerTimingsForStatus(follower, asOptionalRecord(stored.timings), phase, observedSha) : buildFollowerTimings(follower, live, undefined, asOptionalRecord(stored.timings), phase),
|
||||||
|
drilldown: `bun scripts/cli.ts cicd branch-follower status --follower ${follower.id} --live`,
|
||||||
|
};
|
||||||
|
if (!detailed) return summary;
|
||||||
|
return {
|
||||||
|
...summary,
|
||||||
|
source: {
|
||||||
|
...asOptionalRecord(summary.source),
|
||||||
|
snapshotPrefix: follower.source.snapshotPrefix,
|
||||||
|
},
|
||||||
|
budgetSource: follower.budgets,
|
||||||
|
stateConfigMap: registry.controller.stateConfigMapName,
|
||||||
warnings: Array.isArray(stored.warnings) ? stored.warnings.slice(0, 6) : [],
|
warnings: Array.isArray(stored.warnings) ? stored.warnings.slice(0, 6) : [],
|
||||||
next: followerNextCommands(follower),
|
next: followerNextCommands(follower),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user