Skip to content

Commit 2899c9e

Browse files
committed
Merge branch 'chore/setup' into staging
2 parents 03f01be + 8fdcfaf commit 2899c9e

File tree

6 files changed

+34
-26
lines changed

6 files changed

+34
-26
lines changed

test/helpers/kubectl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function createNamespace(namespace: string): Promise<void> {
3737

3838
export async function deleteNamespace(namespace: string): Promise<void> {
3939
console.log(`Deleting namespace ${namespace}...`);
40-
await exec(`./kubectl delete namespace ${namespace}`);
40+
await exec(`./kubectl delete namespace ${namespace} --ignore-not-found`);
4141
console.log(`Deleted namespace ${namespace}`);
4242
}
4343

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: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@ 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-
await createKindCluster(clusterName);
12+
}
13+
14+
export async function createCluster(): Promise<void> {
15+
// available tags may be viewed at https://hub.docker.com/r/kindest/node/tags
16+
const kindImageTag = 'latest';
17+
console.log(`Creating cluster "${clusterName}" with Kind image tag ${kindImageTag}...`);
18+
19+
let kindImageArgument = '';
20+
if (kindImageTag !== 'latest') {
21+
// not specifying the "--image" argument tells Kind to pick the latest image
22+
// which does not necessarily have the "latest" tag
23+
kindImageArgument = `--image="kindest/node:${kindImageTag}"`;
24+
}
25+
await exec(`./kind create cluster --name="${clusterName}" ${kindImageArgument}`);
26+
console.log(`Created cluster ${clusterName}!`);
1327
}
1428

1529
export async function deleteCluster(): Promise<void> {
@@ -61,17 +75,3 @@ async function download(osDistro: string): Promise<void> {
6175
console.log('KinD downloaded!');
6276
}
6377
}
64-
65-
// available tags may be viewed at https://hub.docker.com/r/kindest/node/tags
66-
async function createKindCluster(clusterName, kindImageTag = 'latest'): Promise<void> {
67-
console.log(`Creating cluster "${clusterName}" with Kind image tag ${kindImageTag}...`);
68-
69-
let kindImageArgument = '';
70-
if (kindImageTag !== 'latest') {
71-
// not specifying the "--image" argument tells Kind to pick the latest image
72-
// which does not necessarily have the "latest" tag
73-
kindImageArgument = `--image="kindest/node:${kindImageTag}"`;
74-
}
75-
await exec(`./kind create cluster --name="${clusterName}" ${kindImageArgument}`);
76-
console.log(`Created cluster ${clusterName}!`);
77-
}

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)