Skip to content

Commit 8fdcfaf

Browse files
committed
chore: platform-specific setup now has its own function
- KinD needs to download KinD - EKS needs the amazon CLI and env variables set
1 parent b74fd81 commit 8fdcfaf

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

test/setup/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export async function deployMonitor(): Promise<string> {
133133
console.log(`platform chosen is ${testPlatform}, createCluster===${createCluster}`);
134134

135135
await kubectl.downloadKubectl();
136+
await platforms[testPlatform].setupTester();
136137
if (createCluster) {
137138
await platforms[testPlatform].create();
138139
await platforms[testPlatform].config();

test/setup/platforms/eks.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { exec } from 'child-process-promise';
22
import * as kubectl from '../../helpers/kubectl';
33

4+
export async function setupTester(): Promise<void> {
5+
// update the `aws` CLI, the one in CircleCI's default image is outdated and doens't support eks
6+
await exec('pip install awscli --ignore-installed six');
7+
8+
// TODO: assert all the vars are present before starting the setup?
9+
// TODO: wipe out the data during teardown?
10+
await exec(`aws configure set aws_access_key_id ${process.env['AWS_ACCESS_KEY_ID']}`);
11+
await exec(`aws configure set aws_secret_access_key ${process.env['AWS_SECRET_ACCESS_KEY']}`);
12+
await exec(`aws configure set region ${process.env['AWS_REGION']}`);
13+
}
14+
415
export async function createCluster(): Promise<void> {
516
throw new Error('Not implemented');
617
}
@@ -17,15 +28,6 @@ export async function exportKubeConfig(): Promise<void> {
1728
export async function loadImageInCluster(imageNameAndTag: string): Promise<string> {
1829
console.log(`Loading image ${imageNameAndTag} in ECR...`);
1930

20-
// update the `aws` CLI, the one in CircleCI's default image is outdated and doens't support eks
21-
await exec('pip install awscli --ignore-installed six');
22-
23-
// TODO: assert all the vars are present before starting the setup?
24-
// TODO: wipe out the data during teardown?
25-
await exec(`aws configure set aws_access_key_id ${process.env['AWS_ACCESS_KEY_ID']}`);
26-
await exec(`aws configure set aws_secret_access_key ${process.env['AWS_SECRET_ACCESS_KEY']}`);
27-
await exec(`aws configure set region ${process.env['AWS_REGION']}`);
28-
2931
const ecrLogin = await exec('aws ecr get-login --region us-east-2 --no-include-email');
3032

3133
// aws ecr get-login returns something that looks like:

test/setup/platforms/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ interface IPlatformSetup {
1212
config: () => Promise<void>;
1313
// clean up whatever we littered an existing cluster with
1414
clean: () => Promise<void>;
15+
// set up host requirements specific to this platform
16+
setupTester: () => Promise<void>;
1517
}
1618

1719
const kindSetup: IPlatformSetup = {
@@ -20,6 +22,7 @@ const kindSetup: IPlatformSetup = {
2022
delete: kind.deleteCluster,
2123
config: kind.exportKubeConfig,
2224
clean: kind.clean,
25+
setupTester: kind.setupTester,
2326
};
2427

2528
const eksSetup: IPlatformSetup = {
@@ -28,6 +31,7 @@ const eksSetup: IPlatformSetup = {
2831
delete: eks.deleteCluster,
2932
config: eks.exportKubeConfig,
3033
clean: eks.clean,
34+
setupTester: eks.setupTester,
3135
};
3236

3337
export default {

test/setup/platforms/kind.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import * as needle from 'needle';
66

77
const clusterName = 'kind';
88

9-
export async function createCluster(): Promise<void> {
9+
export async function setupTester(): Promise<void> {
1010
const osDistro = platform();
1111
await download(osDistro);
12+
}
1213

14+
export async function createCluster(): Promise<void> {
1315
// available tags may be viewed at https://hub.docker.com/r/kindest/node/tags
1416
const kindImageTag = 'latest';
1517
console.log(`Creating cluster "${clusterName}" with Kind image tag ${kindImageTag}...`);

test/system/kind.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ tap.test('Kubernetes-Monitor with KinD', async (t) => {
4848
await kubectl.downloadKubectl();
4949

5050
// KinD
51+
await kind.setupTester();
5152
await kind.createCluster();
5253
await kind.exportKubeConfig();
5354

0 commit comments

Comments
 (0)