Skip to content

Commit

Permalink
feat(cdk8s): argo semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfouquet committed Oct 11, 2023
1 parent 8ab88bd commit 6fcfbfa
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
dist/
2 changes: 2 additions & 0 deletions cdk8s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app: npx tsx config/app.ts
language: typescript
14 changes: 8 additions & 6 deletions config/app.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { App } from 'cdk8s';

import { ArgoSemaphore } from './charts/argo.semaphores';

const app = new App();

async function main(): Promise<void> {
// 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();
app.synth();
}

main();
27 changes: 7 additions & 20 deletions config/charts/argo.semaphores.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
45 changes: 45 additions & 0 deletions config/util/build.ts
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 2 additions & 3 deletions config/labels/labels.ts → config/util/labels.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mport { getGitBuildInfo } from "./build";

import { getGitBuildInfo } from './build';

/**
* Generate a collection of standard labels for all components
Expand Down Expand Up @@ -51,4 +50,4 @@ export function applyDefaultLabels<T extends { labels?: Record<string, string> }
...defaultLabels(name, version, component, partOf),
},
};
}
}

0 comments on commit 6fcfbfa

Please sign in to comment.