-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/cdk8s-argo-workflows-tde-904
- Loading branch information
Showing
7 changed files
with
412 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Chart, ChartProps, Size } from 'cdk8s'; | ||
import * as kplus from 'cdk8s-plus-27'; | ||
import { Construct } from 'constructs'; | ||
|
||
import { applyDefaultLabels } from '../util/labels.js'; | ||
|
||
export class Cloudflared extends Chart { | ||
constructor( | ||
scope: Construct, | ||
id: string, | ||
props: { tunnelId: string; tunnelSecret: string; accountId: string; tunnelName: string } & ChartProps, | ||
) { | ||
super(scope, id, applyDefaultLabels(props, 'cloudflared', '2023.8.2', 'tunnel', 'workflows')); | ||
|
||
// TODO should we create a new namespace every time | ||
new kplus.Namespace(this, 'namespace', { | ||
metadata: { name: props.namespace }, | ||
}); | ||
|
||
const cm = new kplus.ConfigMap(this, 'config', { | ||
data: { | ||
'config.yaml': [ | ||
`tunnel: ${props.tunnelName}`, // Tunnel name must match the credentials | ||
'credentials-file: /etc/cloudflared/creds/credentials.json', // defined by "kplus.Secret" below | ||
`metrics: "[::]:2000"`, | ||
'no-autoupdate: true', | ||
'protocol: http2', // quic is blocked in the LINZ network | ||
].join('\n'), | ||
}, | ||
}); | ||
|
||
// Secret credentials for the tunnel | ||
const secret = new kplus.Secret(this, 'secret'); | ||
secret.addStringData( | ||
'credentials.json', | ||
JSON.stringify({ | ||
AccountTag: props.accountId, | ||
TunnelID: props.tunnelId, | ||
TunnelSecret: props.tunnelSecret, | ||
}), | ||
); | ||
|
||
new kplus.Deployment(this, 'tunnel', { | ||
// Ensure two tunnels are active | ||
replicas: 2, | ||
containers: [ | ||
{ | ||
name: 'cloudflared', | ||
image: props.accountId + '.dkr.ecr.ap-southeast-2.amazonaws.com/eks:cloudflared-2023.8.2', | ||
args: ['tunnel', '--loglevel', 'trace', '--config', '/etc/cloudflared/config/config.yaml', 'run'], | ||
volumeMounts: [ | ||
{ volume: kplus.Volume.fromConfigMap(this, 'mount-config', cm), path: '/etc/cloudflared/config' }, | ||
{ volume: kplus.Volume.fromSecret(this, 'mount-secret', secret), path: '/etc/cloudflared/creds' }, | ||
], | ||
resources: { memory: { request: Size.mebibytes(128) } }, | ||
// Cloudflared runs as root | ||
securityContext: { ensureNonRoot: false }, | ||
}, | ||
], | ||
securityContext: { ensureNonRoot: false }, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { SSM } from '@aws-sdk/client-ssm'; | ||
|
||
const ssm = new SSM(); | ||
|
||
/** | ||
* Attempt to load a collection of SSM parameters throwing if any parameter cannot be found | ||
* | ||
* @example | ||
* ```typescript | ||
* const result = fetchSsmParameters({ clientId: '/eks/client-id' }) | ||
* result.clientId // Value of '/eks/client-id' | ||
* ``` | ||
* | ||
* @throws if a parameter is missing from the store | ||
*/ | ||
export async function fetchSsmParameters<T extends Record<string, string>>(query: T): Promise<T> { | ||
console.log('FetchSSM', Object.values(query)); | ||
const ret = await ssm.getParameters({ Names: Object.values(query) }); | ||
|
||
const output: Record<string, string> = {}; | ||
const missing: string[] = []; | ||
for (const [key, parameterName] of Object.entries(query)) { | ||
const val = ret.Parameters?.find((f) => f.Name === parameterName); | ||
if (val == null || val.Value == null) { | ||
missing.push(parameterName); | ||
continue; | ||
} | ||
output[key] = val.Value; | ||
} | ||
|
||
if (missing.length > 0) { | ||
throw new Error('Missing SSM Parameters: ' + missing.join(', ')); | ||
} | ||
return output as T; | ||
} |
Oops, something went wrong.