From 6fcfbfa8956a91fca00edcf568fd6443ccd344c5 Mon Sep 17 00:00:00 2001 From: Paul Fouquet Date: Thu, 12 Oct 2023 11:49:05 +1300 Subject: [PATCH] feat(cdk8s): argo semaphore --- .gitignore | 3 ++- cdk8s.yaml | 2 ++ config/app.ts | 14 +++++----- config/charts/argo.semaphores.ts | 27 +++++-------------- config/util/build.ts | 45 +++++++++++++++++++++++++++++++ config/{labels => util}/labels.ts | 5 ++-- 6 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 cdk8s.yaml create mode 100644 config/util/build.ts rename config/{labels => util}/labels.ts (97%) diff --git a/.gitignore b/.gitignore index 40b878db..04c01ba7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +dist/ \ No newline at end of file diff --git a/cdk8s.yaml b/cdk8s.yaml new file mode 100644 index 00000000..118b07c9 --- /dev/null +++ b/cdk8s.yaml @@ -0,0 +1,2 @@ +app: npx tsx config/app.ts +language: typescript \ No newline at end of file diff --git a/config/app.ts b/config/app.ts index 3ff10806..25ad9aff 100644 --- a/config/app.ts +++ b/config/app.ts @@ -1,14 +1,16 @@ import { App } from 'cdk8s'; +import { ArgoSemaphore } from './charts/argo.semaphores'; const app = new App(); async function main(): Promise { -// const ns = new NamespaceChart(app, 'namespace', { namespace: 'argo' }); + // const ns = new NamespaceChart(app, 'namespace', { namespace: 'argo' }); -// const fluentBit = new FluentBit(app, 'fluentBit', {}); -// fluentBit.addDependency(ns); -// app.synth(); -// } + // FIXME: metadata name is not correct, like 'semaphore-semaphores-c8f222a7' + new ArgoSemaphore(app, 'semaphore', {}); -main(); \ No newline at end of file + app.synth(); +} + +main(); diff --git a/config/charts/argo.semaphores.ts b/config/charts/argo.semaphores.ts index 0a7983cb..3d3798a4 100644 --- a/config/charts/argo.semaphores.ts +++ b/config/charts/argo.semaphores.ts @@ -1,33 +1,20 @@ import { Chart, ChartProps } from 'cdk8s'; +import * as kplus from 'cdk8s-plus-27'; import { Construct } from 'constructs'; -import { applyDefaultLabels } from '../labels/labels'; +import { applyDefaultLabels } from '../util/labels'; export class ArgoSemaphore extends Chart { constructor(scope: Construct, id: string, props: ChartProps) { super(scope, id, applyDefaultLabels(props, 'argo', 'v1', 'semaphores', 'workflows')); - const cm = new kplus.ConfigMap(this, 'semaphores', { + new kplus.ConfigMap(this, 'semaphores', { data: { - 'config.yaml': [ - `tunnel: ${props.tunnelName}`, // Tunnel name must match the credentials - 'credentials-file: /etc/cloudflared/creds/credentials.json', // defined by "secret" - `metrics: "[::]:2000"`, - 'no-autoupdate: true', - 'protocol: http2', // quic is blocked in the LINZ network - ].join('\n'), + standardising: '2', // Limit of how many standardising workflow instances can run at the same time + bulk: '4', // Limit of how many bulk workflow instances can run at the same time + bulkcopy: '8', // Limit of how many publish-copy workflow instances can run at the same time + basemaps_import: '10', // Limit of how many basemaps import workflow instances can run at the same time }, }); - - // apiVersion: v1 - // kind: ConfigMap - // metadata: - // name: semaphores - // namespace: argo - // data: - // standardising: '2' # Limit of how many standardising workflow instances can run at the same time - // bulk: '4' # Limit of how many bulk workflow instances can run at the same time - // bulkcopy: '8' # Limit of how many publish-copy workflow instances can run at the same time - // basemaps_import: '10' # Limit of how many basemaps import workflow instances can run at the same time } } diff --git a/config/util/build.ts b/config/util/build.ts new file mode 100644 index 00000000..01306c96 --- /dev/null +++ b/config/util/build.ts @@ -0,0 +1,45 @@ +import { execFileSync } from 'node:child_process'; + +interface GitBuildInfo { + /** + * Last git version tag + * + * @example + * "v6.45.0" + */ + version: string; + /** + * Current git commit hash + * + * @example + * "e460a1bf611b9464f4c2c3feb48e4823277f14a4" + */ + hash: string; + /** + * Github actions run id and attempt if it exists, otherwise "" + * + * @example + * "6228679664-1" + */ + buildId: string; +} + +let buildInfo: GitBuildInfo | undefined; + +/** + * Attempt to guess build information from the currently checked out version of the source code + * + * @returns Basic Git/Github build information + */ +export function getGitBuildInfo(): GitBuildInfo { + if (buildInfo == null) { + buildInfo = { + version: execFileSync('git', ['describe', '--tags', '--always', '--match', 'v*']).toString().trim(), + hash: execFileSync('git', ['rev-parse', 'HEAD']).toString().trim(), + buildId: process.env['GITHUB_RUN_ID'] + ? `${process.env['GITHUB_RUN_ID']}-${process.env['GITHUB_RUN_ATTEMPT']}` + : '', + }; + } + return buildInfo; +} diff --git a/config/labels/labels.ts b/config/util/labels.ts similarity index 97% rename from config/labels/labels.ts rename to config/util/labels.ts index d3225fb7..0f02012b 100644 --- a/config/labels/labels.ts +++ b/config/util/labels.ts @@ -1,5 +1,4 @@ -mport { getGitBuildInfo } from "./build"; - +import { getGitBuildInfo } from './build'; /** * Generate a collection of standard labels for all components @@ -51,4 +50,4 @@ export function applyDefaultLabels } ...defaultLabels(name, version, component, partOf), }, }; -} \ No newline at end of file +}