78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import type { ControlPlaneTargetSpec } from "./hwlab-node-control-plane-model";
|
|
|
|
export function argoDesiredManifest(target: ControlPlaneTargetSpec): Record<string, unknown>[] {
|
|
const internalHttp = target.argo.install.internalHttp;
|
|
const reconciliation = target.argo.install.reconciliation;
|
|
return [
|
|
...(internalHttp === null ? [] : [{
|
|
apiVersion: "v1",
|
|
kind: "ConfigMap",
|
|
metadata: {
|
|
name: internalHttp.configMapName,
|
|
namespace: target.argo.namespace,
|
|
labels: {
|
|
"app.kubernetes.io/name": internalHttp.configMapName,
|
|
"app.kubernetes.io/part-of": "argocd",
|
|
},
|
|
},
|
|
data: { [internalHttp.configKey]: "true" },
|
|
}]),
|
|
...(reconciliation === null ? [] : [{
|
|
apiVersion: "v1",
|
|
kind: "ConfigMap",
|
|
metadata: {
|
|
name: reconciliation.configMapName,
|
|
namespace: target.argo.namespace,
|
|
labels: {
|
|
"app.kubernetes.io/name": reconciliation.configMapName,
|
|
"app.kubernetes.io/part-of": "argocd",
|
|
},
|
|
},
|
|
data: {
|
|
"timeout.reconciliation": `${reconciliation.timeoutSeconds}s`,
|
|
"timeout.reconciliation.jitter": `${reconciliation.jitterSeconds}s`,
|
|
},
|
|
}]),
|
|
...(target.source.sourceAuthority.mode === "giteaSnapshot" ? [] : [
|
|
argoProjectSkeleton(target),
|
|
argoApplicationSkeleton(target),
|
|
]),
|
|
];
|
|
}
|
|
|
|
export function argoInternalHttpIdentity(target: ControlPlaneTargetSpec): string {
|
|
const internalHttp = target.argo.install.internalHttp;
|
|
if (internalHttp === null) return "disabled";
|
|
const value = JSON.stringify({ configMapName: internalHttp.configMapName, configKey: internalHttp.configKey, value: "true" });
|
|
return `sha256:${createHash("sha256").update(value).digest("hex")}`;
|
|
}
|
|
|
|
export function argoProjectSkeleton(target: ControlPlaneTargetSpec): Record<string, unknown> {
|
|
return {
|
|
apiVersion: "argoproj.io/v1alpha1",
|
|
kind: "AppProject",
|
|
metadata: { name: target.argo.projectName, namespace: target.argo.namespace },
|
|
spec: {
|
|
sourceRepos: [target.gitMirror.readUrl],
|
|
destinations: [{ server: "https://kubernetes.default.svc", namespace: target.runtimeNamespace }],
|
|
clusterResourceWhitelist: [{ group: "*", kind: "*" }],
|
|
namespaceResourceWhitelist: [{ group: "*", kind: "*" }],
|
|
},
|
|
};
|
|
}
|
|
|
|
export function argoApplicationSkeleton(target: ControlPlaneTargetSpec): Record<string, unknown> {
|
|
return {
|
|
apiVersion: "argoproj.io/v1alpha1",
|
|
kind: "Application",
|
|
metadata: { name: target.argo.applicationName, namespace: target.argo.namespace },
|
|
spec: {
|
|
project: target.argo.projectName,
|
|
source: { repoURL: target.gitMirror.readUrl, targetRevision: target.gitops.branch, path: target.gitops.path },
|
|
destination: { server: "https://kubernetes.default.svc", namespace: target.runtimeNamespace },
|
|
syncPolicy: { automated: { prune: true, selfHeal: true } },
|
|
},
|
|
};
|
|
}
|