Skip to content

Commit

Permalink
feat(cdk8s): retrieve eks cluster information
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfouquet committed Oct 17, 2023
1 parent c469211 commit a28ec4d
Show file tree
Hide file tree
Showing 11 changed files with 2,042 additions and 352 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
dist/
build/
14 changes: 6 additions & 8 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ ConfigMap that list the synchronization limits for parallel execution of the wor

### Karpenter



## Development

<https://cdk8s.io/>
Expand All @@ -32,7 +30,8 @@ It is possible to generate a specific Helm construct for the component if their
To generate the Helm Construct for a specific Chart, follow the instructions [here](https://github.com/cdk8s-team/cdk8s/blob/master/docs/cli/import.md#values-schema):

- add the Helm to `helm`
``` shell

```shell

```

Expand All @@ -43,29 +42,28 @@ However, some of the component Helm charts do not have a `values.schema.json`. F
- aws-for-fluent-bit (<https://github.com/aws/eks-charts/issues/1011>)
- Karpenter


## Usage (for test)

Ensure all dependencies are installed

``` shell
```shell
npm install
```

Login to AWS

Generate the kubernetes configuration yaml into `dist/`

``` shell
```shell
npx cdk8s synth
```

Apply the generated yaml files

``` shell
```shell
kubectl apply -f dist/
```

## Deployment

The deployment of the K8s config is managed by GithubActions in [main](../.github/workflows/main.yml).
The deployment of the K8s config is managed by GithubActions in [main](../.github/workflows/main.yml).
9 changes: 7 additions & 2 deletions config/app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { App } from 'cdk8s';

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

const app = new App();

async function main(): Promise<void> {
new ArgoSemaphore(app, 'semaphore', {});

app.synth();
//const clusterStackName = 'EksWorkflowProd';
//const clusterStack = await getStackFromName(clusterStackName);

//console.log(clusterStack.RoleARN);

//app.synth();
}

main();
2 changes: 1 addition & 1 deletion config/charts/argo.semaphores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Chart, ChartProps } from 'cdk8s';
import * as kplus from 'cdk8s-plus-27';
import { Construct } from 'constructs';

import { applyDefaultLabels } from '../util/labels';
import { applyDefaultLabels } from '../util/labels.js';

export class ArgoSemaphore extends Chart {
constructor(scope: Construct, id: string, props: ChartProps) {
Expand Down
21 changes: 20 additions & 1 deletion config/charts/karpenter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { CloudFormation } from '@aws-sdk/client-cloudformation';
import { Chart, ChartProps, Helm } from 'cdk8s';
import { Construct } from 'constructs';

import { applyDefaultLabels } from '../util/labels.js';

export class Karpenter extends Chart {
constructor(scope: Construct, id: string, props: ChartProps) {
constructor(scope: Construct, id: string, props: { roleArn: string } & ChartProps) {
// TODO: What is the component name? 'karpenter' or 'autoscaling'?
super(scope, id, applyDefaultLabels(props, 'karpenter', '', 'karpenter', 'workflows'));

// Get EKS cluster information

new Helm(this, 'karpenter', {
chart: 'karpenter',
repo: 'oci://public.ecr.aws/karpenter/karpenter',
Expand All @@ -31,3 +34,19 @@ export class Karpenter extends Chart {
});
}
}

export async function getStackFromName(stackName: string): Promise<void> {
const cfn = new CloudFormation();
const clusterStack = await cfn.describeStacks({ StackName: stackName });
if (clusterStack.Stacks) {
console.log(clusterStack.Stacks[0]);
}
}

// TODO: remove tests
async function main(): Promise<void> {
const clusterStackName = 'EksWorkflowProd';
await getStackFromName(clusterStackName);
}

main();
17 changes: 17 additions & 0 deletions config/util/cloud.formation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CloudFormation } from '@aws-sdk/client-cloudformation';

export async function getStackFromName(stackName: string): Promise<void> {
const cfn = new CloudFormation();
const clusterStack = await cfn.describeStacks({ StackName: stackName });
if (clusterStack.Stacks) {
console.log(clusterStack.Stacks[0]);
}
}

// TODO: remove tests
async function main(): Promise<void> {
const clusterStackName = 'EksWorkflowProd';
await getStackFromName(clusterStackName);
}

main();
17 changes: 17 additions & 0 deletions config/util/eks.cluster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { EKS } from '@aws-sdk/client-eks';

export async function getClusterFromName(clusterName: string): Promise<void> {
const eks = new EKS();
const eksCluster = await eks.describeCluster({ name: clusterName });
if (eksCluster.cluster) {
console.log(eksCluster.cluster);
}
}

// TODO: remove tests
async function main(): Promise<void> {
const eksClusterName = 'Workflow';
await getClusterFromName(eksClusterName);
}

main();
2 changes: 1 addition & 1 deletion config/util/labels.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGitBuildInfo } from './build';
import { getGitBuildInfo } from './build.js';

/**
* Generate a collection of standard labels for all components
Expand Down
Loading

0 comments on commit a28ec4d

Please sign in to comment.