fix: limit v02 runtime readiness scope
This commit is contained in:
@@ -2440,13 +2440,41 @@ async function runtimeItems() {
|
||||
}
|
||||
|
||||
function runtimeSourceCommit(item) {
|
||||
return item.metadata?.labels?.["hwlab.pikastech.local/source-commit"] ||
|
||||
item.metadata?.annotations?.["hwlab.pikastech.local/source-commit"] ||
|
||||
item.spec?.template?.metadata?.labels?.["hwlab.pikastech.local/source-commit"] ||
|
||||
return item.spec?.template?.metadata?.labels?.["hwlab.pikastech.local/source-commit"] ||
|
||||
item.spec?.template?.metadata?.annotations?.["hwlab.pikastech.local/source-commit"] ||
|
||||
item.metadata?.labels?.["hwlab.pikastech.local/source-commit"] ||
|
||||
item.metadata?.annotations?.["hwlab.pikastech.local/source-commit"] ||
|
||||
null;
|
||||
}
|
||||
|
||||
function serviceIdForRuntimeItem(item) {
|
||||
return item.metadata?.labels?.["hwlab.pikastech.local/service-id"] ||
|
||||
item.spec?.template?.metadata?.labels?.["hwlab.pikastech.local/service-id"] ||
|
||||
item.metadata?.labels?.["app.kubernetes.io/name"] ||
|
||||
item.metadata?.name ||
|
||||
null;
|
||||
}
|
||||
|
||||
function readObservedServiceIds() {
|
||||
try {
|
||||
const plan = JSON.parse(fs.readFileSync("/workspace/source/affected-services.json", "utf8"));
|
||||
const rolloutServices = Array.isArray(plan.rolloutServices) ? plan.rolloutServices.filter(Boolean) : [];
|
||||
if (rolloutServices.length === 0) return null;
|
||||
const ids = new Set(rolloutServices);
|
||||
if (ids.has("hwlab-cloud-api")) ids.add("hwlab-deepseek-proxy");
|
||||
return ids;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const observedServiceIds = readObservedServiceIds();
|
||||
|
||||
function observedRuntimeItems(items) {
|
||||
if (!observedServiceIds) return items;
|
||||
return items.filter((item) => observedServiceIds.has(serviceIdForRuntimeItem(item)));
|
||||
}
|
||||
|
||||
function readyWorkload(item) {
|
||||
const specReplicas = item.spec?.replicas ?? 1;
|
||||
if (specReplicas === 0) return { ready: true, skipped: true };
|
||||
@@ -2468,15 +2496,16 @@ async function waitForArgoRefresh() {
|
||||
process.exitCode = 1;
|
||||
return { observed: false, skipped: true };
|
||||
}
|
||||
const pending = runtime.items
|
||||
const observed = observedRuntimeItems(runtime.items);
|
||||
const pending = observed
|
||||
.map((item) => ({ kind: item.kind, name: item.metadata?.name, sourceCommit: runtimeSourceCommit(item) }))
|
||||
.filter((item) => item.sourceCommit !== revision);
|
||||
if (runtime.items.length > 0 && pending.length === 0) {
|
||||
emit({ stage: "argo-refresh", status: "succeeded", durationMs: Date.now() - startedAt, workloadCount: runtime.items.length });
|
||||
if (observed.length > 0 && pending.length === 0) {
|
||||
emit({ stage: "argo-refresh", status: "succeeded", durationMs: Date.now() - startedAt, workloadCount: runtime.items.length, observedCount: observed.length });
|
||||
return { observed: true, skipped: false };
|
||||
}
|
||||
if (Date.now() - startedAt >= timeoutMs) {
|
||||
emit({ stage: "argo-refresh", status: "timeout", reason: "source-commit-refresh-timeout", durationMs: Date.now() - startedAt, workloadCount: runtime.items.length, pending: pending.slice(0, 8) });
|
||||
emit({ stage: "argo-refresh", status: "timeout", reason: "source-commit-refresh-timeout", durationMs: Date.now() - startedAt, workloadCount: runtime.items.length, observedCount: observed.length, pending: pending.slice(0, 8) });
|
||||
process.exitCode = 1;
|
||||
return { observed: false, skipped: false };
|
||||
}
|
||||
@@ -2493,13 +2522,14 @@ async function waitForWorkloads() {
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
const blocked = runtime.items.map((item) => ({ kind: item.kind, name: item.metadata?.name, ...readyWorkload(item) })).filter((item) => !item.ready);
|
||||
if (runtime.items.length > 0 && blocked.length === 0) {
|
||||
emit({ stage: "workload-ready", status: "succeeded", durationMs: Date.now() - startedAt, workloadCount: runtime.items.length });
|
||||
const observed = observedRuntimeItems(runtime.items);
|
||||
const blocked = observed.map((item) => ({ kind: item.kind, name: item.metadata?.name, ...readyWorkload(item) })).filter((item) => !item.ready);
|
||||
if (observed.length > 0 && blocked.length === 0) {
|
||||
emit({ stage: "workload-ready", status: "succeeded", durationMs: Date.now() - startedAt, workloadCount: runtime.items.length, observedCount: observed.length });
|
||||
return;
|
||||
}
|
||||
if (Date.now() - startedAt >= timeoutMs) {
|
||||
emit({ stage: "workload-ready", status: "timeout", durationMs: Date.now() - startedAt, workloadCount: runtime.items.length, blocked: blocked.slice(0, 8) });
|
||||
emit({ stage: "workload-ready", status: "timeout", durationMs: Date.now() - startedAt, workloadCount: runtime.items.length, observedCount: observed.length, blocked: blocked.slice(0, 8) });
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
@@ -2523,8 +2553,10 @@ function runtimeReadyTask({ profile = "dev" } = {}) {
|
||||
return {
|
||||
name: "runtime-ready",
|
||||
runAfter: ["gitops-promote"],
|
||||
workspaces: [{ name: "source", workspace: "source" }],
|
||||
taskSpec: {
|
||||
params: [{ name: "revision" }, { name: "runtime-namespace" }, { name: "gitops-target" }],
|
||||
workspaces: [{ name: "source" }],
|
||||
steps: [{
|
||||
name: "runtime-ready",
|
||||
image: ciToolsRunnerImage,
|
||||
@@ -3529,20 +3561,7 @@ function g14FrpcManifest({ profile = "dev", source = null } = {}) {
|
||||
};
|
||||
const sourceCommitLabel = source?.full ? { "hwlab.pikastech.local/source-commit": source.full } : {};
|
||||
const renderedLabels = { ...labels, ...sourceCommitLabel };
|
||||
return {
|
||||
apiVersion: "v1",
|
||||
kind: "List",
|
||||
items: [
|
||||
{
|
||||
apiVersion: "v1",
|
||||
kind: "ConfigMap",
|
||||
metadata: {
|
||||
name: configName,
|
||||
namespace,
|
||||
labels: renderedLabels
|
||||
},
|
||||
data: {
|
||||
"frpc.toml": `serverAddr = "74.48.78.17"
|
||||
const configText = `serverAddr = "74.48.78.17"
|
||||
serverPort = 7000
|
||||
loginFailExit = true
|
||||
|
||||
@@ -3559,7 +3578,24 @@ type = "tcp"
|
||||
localIP = "hwlab-edge-proxy.${namespace}.svc.cluster.local"
|
||||
localPort = 6667
|
||||
remotePort = ${edgeRemotePort}
|
||||
`
|
||||
`;
|
||||
const configSha256 = createHash("sha256").update(configText).digest("hex");
|
||||
const templateLabels = { ...labels, "hwlab.pikastech.local/config-sha256": configSha256 };
|
||||
const templateAnnotations = { "hwlab.pikastech.local/config-sha256": configSha256 };
|
||||
return {
|
||||
apiVersion: "v1",
|
||||
kind: "List",
|
||||
items: [
|
||||
{
|
||||
apiVersion: "v1",
|
||||
kind: "ConfigMap",
|
||||
metadata: {
|
||||
name: configName,
|
||||
namespace,
|
||||
labels: renderedLabels
|
||||
},
|
||||
data: {
|
||||
"frpc.toml": configText
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -3574,7 +3610,7 @@ remotePort = ${edgeRemotePort}
|
||||
replicas: 1,
|
||||
selector: { matchLabels: { "app.kubernetes.io/name": deploymentName } },
|
||||
template: {
|
||||
metadata: { labels: renderedLabels, annotations: sourceCommitLabel },
|
||||
metadata: { labels: templateLabels, annotations: templateAnnotations },
|
||||
spec: {
|
||||
containers: [{
|
||||
name: "frpc",
|
||||
@@ -3607,9 +3643,14 @@ function deepSeekProxyManifest({ profile = "dev", source, registryPrefix = defau
|
||||
"hwlab.pikastech.local/service-id": "hwlab-deepseek-proxy",
|
||||
"hwlab.pikastech.local/source-commit": source.full
|
||||
};
|
||||
const templateLabels = {
|
||||
...labels,
|
||||
"hwlab.pikastech.local/source-commit": bridgeCommit,
|
||||
"hwlab.pikastech.local/bridge-source-commit": bridgeCommit
|
||||
};
|
||||
const templateAnnotations = {
|
||||
"hwlab.pikastech.local/bridge-service-id": bridgeServiceId,
|
||||
"hwlab.pikastech.local/source-commit": source.full,
|
||||
"hwlab.pikastech.local/source-commit": bridgeCommit,
|
||||
"hwlab.pikastech.local/bridge-source-commit": bridgeCommit,
|
||||
"hwlab.pikastech.local/bridge-image-tag": bridgeImageTag,
|
||||
"hwlab.pikastech.local/bridge-image": bridgeImage
|
||||
@@ -3634,7 +3675,7 @@ function deepSeekProxyManifest({ profile = "dev", source, registryPrefix = defau
|
||||
replicas: 1,
|
||||
selector: { matchLabels: { "app.kubernetes.io/name": "hwlab-deepseek-proxy" } },
|
||||
template: {
|
||||
metadata: { labels, annotations: templateAnnotations },
|
||||
metadata: { labels: templateLabels, annotations: templateAnnotations },
|
||||
spec: {
|
||||
initContainers: [{
|
||||
name: "moonbridge-config",
|
||||
@@ -3988,7 +4029,16 @@ function v02PostgresManifest({ migrationSql, source }) {
|
||||
"hwlab.pikastech.local/profile": "v02",
|
||||
"hwlab.pikastech.local/source-commit": source.full
|
||||
};
|
||||
const templateAnnotations = { "hwlab.pikastech.local/source-commit": source.full };
|
||||
const migrationSha256 = createHash("sha256").update(migrationSql).digest("hex");
|
||||
const templateLabels = {
|
||||
"app.kubernetes.io/name": name,
|
||||
"app.kubernetes.io/part-of": "hwlab",
|
||||
"hwlab.pikastech.local/environment": "v02",
|
||||
"hwlab.pikastech.local/gitops-target": "v02",
|
||||
"hwlab.pikastech.local/profile": "v02",
|
||||
"hwlab.pikastech.local/migration-sha256": migrationSha256
|
||||
};
|
||||
const templateAnnotations = { "hwlab.pikastech.local/migration-sha256": migrationSha256 };
|
||||
return {
|
||||
apiVersion: "v1",
|
||||
kind: "List",
|
||||
@@ -4014,7 +4064,7 @@ function v02PostgresManifest({ migrationSql, source }) {
|
||||
replicas: 1,
|
||||
selector: { matchLabels: { "app.kubernetes.io/name": name } },
|
||||
template: {
|
||||
metadata: { labels, annotations: templateAnnotations },
|
||||
metadata: { labels: templateLabels, annotations: templateAnnotations },
|
||||
spec: {
|
||||
containers: [{
|
||||
name: "postgres",
|
||||
|
||||
Reference in New Issue
Block a user