fix hwlab d601 global proxy git mirror wiring (#565)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -239,12 +239,26 @@ interface NodeRuntimeGitMirrorTargetSpec {
|
||||
cachePvcName: string;
|
||||
cacheHostPath: string | null;
|
||||
secretName: string;
|
||||
syncConfigMapName: string;
|
||||
syncJobPrefix: string;
|
||||
flushJobPrefix: string;
|
||||
toolsImage: string;
|
||||
sourceRepository: string;
|
||||
sourceBranch: string;
|
||||
gitopsBranch: string;
|
||||
egressProxy: NodeRuntimeGitMirrorEgressProxySpec;
|
||||
}
|
||||
|
||||
interface NodeRuntimeGitMirrorEgressProxySpec {
|
||||
mode: "k8s-service-cluster-ip";
|
||||
clientName: string;
|
||||
namespace: string;
|
||||
serviceName: string;
|
||||
port: number;
|
||||
sourceRef: string;
|
||||
sourceKey: string;
|
||||
sourceType: "subscription-url";
|
||||
noProxy: string[];
|
||||
}
|
||||
|
||||
const MASTER_ADMIN_API_KEY_KEY = "api-key";
|
||||
@@ -3228,13 +3242,14 @@ function nodeRuntimeGitMirrorJobManifest(mirror: NodeRuntimeGitMirrorTargetSpec,
|
||||
volumes: [
|
||||
{ name: "cache", ...(mirror.cacheHostPath === null ? { persistentVolumeClaim: { claimName: mirror.cachePvcName } } : { hostPath: { path: mirror.cacheHostPath, type: "DirectoryOrCreate" } }) },
|
||||
{ name: "git-ssh", secret: { secretName: mirror.secretName, defaultMode: 0o400 } },
|
||||
{ name: "script", configMap: { name: "git-mirror-sync-script", defaultMode: 0o755 } },
|
||||
{ name: "script", configMap: { name: mirror.syncConfigMapName, defaultMode: 0o755 } },
|
||||
],
|
||||
containers: [{
|
||||
name: action,
|
||||
image: mirror.toolsImage,
|
||||
imagePullPolicy: "IfNotPresent",
|
||||
command: [action === "sync" ? "/script/sync.sh" : "/script/flush.sh"],
|
||||
env: nodeRuntimeGitMirrorProxyEnv(mirror),
|
||||
volumeMounts: [
|
||||
{ name: "cache", mountPath: "/cache" },
|
||||
{ name: "git-ssh", mountPath: "/git-ssh", readOnly: true },
|
||||
@@ -3247,6 +3262,22 @@ function nodeRuntimeGitMirrorJobManifest(mirror: NodeRuntimeGitMirrorTargetSpec,
|
||||
};
|
||||
}
|
||||
|
||||
function nodeRuntimeGitMirrorProxyEnv(mirror: NodeRuntimeGitMirrorTargetSpec): Record<string, string>[] {
|
||||
const proxy = mirror.egressProxy;
|
||||
const proxyUrl = `http://${proxy.serviceName}.${proxy.namespace}.svc.cluster.local:${proxy.port}`;
|
||||
const noProxy = proxy.noProxy.join(",");
|
||||
return [
|
||||
{ name: "HTTP_PROXY", value: proxyUrl },
|
||||
{ name: "HTTPS_PROXY", value: proxyUrl },
|
||||
{ name: "ALL_PROXY", value: proxyUrl },
|
||||
{ name: "http_proxy", value: proxyUrl },
|
||||
{ name: "https_proxy", value: proxyUrl },
|
||||
{ name: "all_proxy", value: proxyUrl },
|
||||
{ name: "NO_PROXY", value: noProxy },
|
||||
{ name: "no_proxy", value: noProxy },
|
||||
];
|
||||
}
|
||||
|
||||
function nodeRuntimeControlPlaneStatus(scoped: ReturnType<typeof parseNodeScopedDelegatedOptions>): Record<string, unknown> {
|
||||
const spec = scoped.spec;
|
||||
const sourceCommitOverride = optionValue(scoped.originalArgs, "--source-commit");
|
||||
@@ -5831,10 +5862,16 @@ function externalPostgresSecretStatus(spec: HwlabRuntimeLaneSpec, namespaceExist
|
||||
function nodeRuntimeGitMirrorTarget(spec: HwlabRuntimeLaneSpec): NodeRuntimeGitMirrorTargetSpec {
|
||||
const configPath = rootPath(HWLAB_NODE_CONTROL_PLANE_CONFIG_PATH);
|
||||
const parsed = record(Bun.YAML.parse(readFileSync(configPath, "utf8")) as unknown);
|
||||
const nodes = record(parsed.nodes);
|
||||
const node = record(nodes[spec.nodeId]);
|
||||
const nodeEgressProxy = nodeRuntimeGitMirrorEgressProxySpec(record(node.egressProxy), `nodes.${spec.nodeId}.egressProxy`);
|
||||
const targets = Array.isArray(parsed.targets) ? parsed.targets : [];
|
||||
const target = targets.map((item) => record(item)).find((item) => item.node === spec.nodeId && item.lane === spec.lane);
|
||||
if (target === undefined) throw new Error(`no gitMirror target for node=${spec.nodeId} lane=${spec.lane} in ${HWLAB_NODE_CONTROL_PLANE_CONFIG_PATH}`);
|
||||
const gitMirror = record(target.gitMirror);
|
||||
const gitMirrorEgressProxy = record(gitMirror.egressProxy);
|
||||
if (stringValue(gitMirrorEgressProxy.mode, "gitMirror.egressProxy.mode") !== "node-global") throw new Error(`gitMirror.egressProxy.mode must be node-global for node=${spec.nodeId} lane=${spec.lane}`);
|
||||
if (gitMirrorEgressProxy.required !== true) throw new Error(`gitMirror.egressProxy.required must be true for node=${spec.nodeId} lane=${spec.lane}`);
|
||||
const source = record(target.source);
|
||||
const gitops = record(target.gitops);
|
||||
const tekton = record(target.tekton);
|
||||
@@ -5849,12 +5886,37 @@ function nodeRuntimeGitMirrorTarget(spec: HwlabRuntimeLaneSpec): NodeRuntimeGitM
|
||||
cachePvcName: stringValue(gitMirror.cachePvcName, "gitMirror.cachePvcName"),
|
||||
cacheHostPath: optionalStringValue(gitMirror.cacheHostPath, "gitMirror.cacheHostPath"),
|
||||
secretName: stringValue(gitMirror.secretName, "gitMirror.secretName"),
|
||||
syncConfigMapName: stringValue(gitMirror.syncConfigMapName, "gitMirror.syncConfigMapName"),
|
||||
syncJobPrefix: stringValue(gitMirror.syncJobPrefix, "gitMirror.syncJobPrefix"),
|
||||
flushJobPrefix: stringValue(gitMirror.flushJobPrefix, "gitMirror.flushJobPrefix"),
|
||||
toolsImage: stringValue(toolsImage.output, "tekton.toolsImage.output"),
|
||||
sourceRepository: stringValue(source.repository, "source.repository"),
|
||||
sourceBranch: stringValue(source.branch, "source.branch"),
|
||||
gitopsBranch: stringValue(gitops.branch, "gitops.branch"),
|
||||
egressProxy: nodeEgressProxy,
|
||||
};
|
||||
}
|
||||
|
||||
function nodeRuntimeGitMirrorEgressProxySpec(raw: Record<string, unknown>, path: string): NodeRuntimeGitMirrorEgressProxySpec {
|
||||
const mode = stringValue(raw.mode, `${path}.mode`);
|
||||
if (mode !== "k8s-service-cluster-ip") throw new Error(`${path}.mode must be k8s-service-cluster-ip`);
|
||||
const port = Number(raw.port);
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`${path}.port must be a TCP port`);
|
||||
const sourceType = stringValue(raw.sourceType, `${path}.sourceType`);
|
||||
if (sourceType !== "subscription-url") throw new Error(`${path}.sourceType must be subscription-url`);
|
||||
const noProxyRaw = raw.noProxy;
|
||||
if (!Array.isArray(noProxyRaw)) throw new Error(`${path}.noProxy must be an array`);
|
||||
const noProxy = noProxyRaw.map((item, index) => stringValue(item, `${path}.noProxy[${index}]`));
|
||||
return {
|
||||
mode,
|
||||
clientName: stringValue(raw.clientName, `${path}.clientName`),
|
||||
namespace: stringValue(raw.namespace, `${path}.namespace`),
|
||||
serviceName: stringValue(raw.serviceName, `${path}.serviceName`),
|
||||
port,
|
||||
sourceRef: stringValue(raw.sourceRef, `${path}.sourceRef`),
|
||||
sourceKey: stringValue(raw.sourceKey, `${path}.sourceKey`),
|
||||
sourceType,
|
||||
noProxy,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user