Skip to content

Commit

Permalink
test(add-subnets): replace cluster after adding more subnets to use
Browse files Browse the repository at this point in the history
Note: this test works, but it is currently disabled until
pulumi#107 is resolved.
  • Loading branch information
metral committed May 10, 2019
1 parent 8a2e43e commit 117497f
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 0 deletions.
36 changes: 36 additions & 0 deletions nodejs/eks/tests/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,42 @@ func Test_AllTests(t *testing.T) {
},
},
}
/*
// TODO(metral): Uncomment / add back in once
// https://github.com/pulumi/pulumi-eks/issues/107 is resolved.
{
Dir: path.Join(cwd, "replace-cluster-add-subnets"),
Config: map[string]string{
"aws:region": region,
},
Dependencies: []string{
"@pulumi/eks",
},
ExpectRefreshChanges: true,
EditDirs: []integration.EditDir{
{
Dir: path.Join(cwd, "replace-cluster-add-subnets", "step1"),
Additive: true,
ExtraRuntimeValidation: func(t *testing.T, info integration.RuntimeValidationStackInfo) {
// Get the cluster kubeconfig
kubeconfigBytes, err := json.Marshal(info.Outputs["kubeconfig"])
if err != nil {
t.Error(err)
}
// Get the desired Worker node count
desiredNodeCount, err :=
utils.GetNodeCountFromStackResources(info.Deployment.Resources)
if err != nil {
t.Error(err)
}
utils.EKSSmokeTest(t, desiredNodeCount, kubeconfigBytes)
},
},
},
},
*/

longTests := []integration.ProgramTestOptions{}

Expand Down
3 changes: 3 additions & 0 deletions nodejs/eks/tests/replace-cluster-add-subnets/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: test-replace-cluster-add-subnets
description: Test - Replace an EKS cluster by going from using 2 subnets to 3 subnets
runtime: nodejs
90 changes: 90 additions & 0 deletions nodejs/eks/tests/replace-cluster-add-subnets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as eks from "@pulumi/eks";

const projectName = pulumi.getProject();
const zones = aws.getAvailabilityZones();
const tags = { "Name": `${projectName}` };

/**
* VPC
*/
const vpcCidr = "10.0.0.0/16";
const vpc = new aws.ec2.Vpc(projectName, {
cidrBlock: vpcCidr,
enableDnsSupport: true,
enableDnsHostnames: true,
tags: { ...tags },
});
export const vpcId = vpc.id;

/**
* Internet Gateway
*/
const internetGateway = new aws.ec2.InternetGateway(`${projectName}-igw`, {
vpcId: vpc.id,
tags: { ...tags },
}, { parent: vpc });

/**
* Public subnets
*/

const publicSubnetCidrList = ["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24"]; // assumes 3 AZ's in the region
const publicSubnetList = publicSubnetCidrList.map((cidr, index) => {
const name = `${projectName}-public-${index}`;
const subnet = new aws.ec2.Subnet(name, {
vpcId: vpc.id,
cidrBlock: cidr,
mapPublicIpOnLaunch: true,
availabilityZone: zones.then(z => z.names[Math.abs(index) % z.names.length]), // avoid out of bounds error
tags: { ...tags },
}, { parent: vpc });
return subnet;
});

/**
* Configure RouteTables & Associations
*/
publicSubnetList.forEach((subnet, index) => {
const name = `${projectName}-public-${index}`;

const routeTable = new aws.ec2.RouteTable(`${name}-rtb`, {
vpcId: vpc.id,
tags: { ...tags },
}, { parent: subnet });

// Set the default route to the NAT Gateway
const route = new aws.ec2.Route(`${name}-route`, {
routeTableId: routeTable.id,
destinationCidrBlock: "0.0.0.0/0",
gatewayId: internetGateway.id,
}, { parent: routeTable });

const association = new aws.ec2.RouteTableAssociation(`${name}-rtb-assoc`, {
subnetId: subnet.id,
routeTableId: routeTable.id,
}, { parent: routeTable });
});

/**
* EKS
*/
const subnetIds = publicSubnetList.map(s => s.id);
subnetIds.pop(); // comment out after initial deployment to repo https://github.com/pulumi/pulumi-eks/issues/69
const cluster = new eks.Cluster(projectName, {
vpcId: vpc.id,
subnetIds: subnetIds,
instanceType: "t2.medium",
desiredCapacity: 2,
minSize: 1,
maxSize: 2,
storageClasses: "gp2",
deployDashboard: false,
});

// Export the cluster name
export const clusterName = cluster.core.cluster.name;

// Export the cluster kubeconfig
export const kubeconfig = cluster.kubeconfig;
14 changes: 14 additions & 0 deletions nodejs/eks/tests/replace-cluster-add-subnets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "test-replace-cluster-add-subnets",
"devDependencies": {
"typescript": "^3.0.0",
"@types/node": "latest"
},
"dependencies": {
"@pulumi/pulumi": "latest",
"@pulumi/awsx": "latest"
},
"peerDependencies": {
"@pulumi/eks": "latest"
}
}
89 changes: 89 additions & 0 deletions nodejs/eks/tests/replace-cluster-add-subnets/step1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as eks from "@pulumi/eks";

const projectName = pulumi.getProject();
const zones = aws.getAvailabilityZones();
const tags = { "Name": `${projectName}` };

/**
* VPC
*/
const vpcCidr = "10.0.0.0/16";
const vpc = new aws.ec2.Vpc(projectName, {
cidrBlock: vpcCidr,
enableDnsSupport: true,
enableDnsHostnames: true,
tags: { ...tags },
});
export const vpcId = vpc.id;

/**
* Internet Gateway
*/
const internetGateway = new aws.ec2.InternetGateway(`${projectName}-igw`, {
vpcId: vpc.id,
tags: { ...tags },
}, { parent: vpc });

/**
* Public subnets
*/

const publicSubnetCidrList = ["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24"]; // assumes 3 AZ's in the region
const publicSubnetList = publicSubnetCidrList.map((cidr, index) => {
const name = `${projectName}-public-${index}`;
const subnet = new aws.ec2.Subnet(name, {
vpcId: vpc.id,
cidrBlock: cidr,
mapPublicIpOnLaunch: true,
availabilityZone: zones.then(z => z.names[Math.abs(index) % z.names.length]), // avoid out of bounds error
tags: { ...tags },
}, { parent: vpc });
return subnet;
});

/**
* Configure RouteTables & Associations
*/
publicSubnetList.forEach((subnet, index) => {
const name = `${projectName}-public-${index}`;

const routeTable = new aws.ec2.RouteTable(`${name}-rtb`, {
vpcId: vpc.id,
tags: { ...tags },
}, { parent: subnet });

// Set the default route to the NAT Gateway
const route = new aws.ec2.Route(`${name}-route`, {
routeTableId: routeTable.id,
destinationCidrBlock: "0.0.0.0/0",
gatewayId: internetGateway.id,
}, { parent: routeTable });

const association = new aws.ec2.RouteTableAssociation(`${name}-rtb-assoc`, {
subnetId: subnet.id,
routeTableId: routeTable.id,
}, { parent: routeTable });
});

/**
* EKS
*/
const subnetIds = publicSubnetList.map(s => s.id);
const cluster = new eks.Cluster(projectName, {
vpcId: vpc.id,
subnetIds: subnetIds,
instanceType: "t2.medium",
desiredCapacity: 2,
minSize: 1,
maxSize: 2,
storageClasses: "gp2",
deployDashboard: false,
});

// Export the cluster name
export const clusterName = cluster.core.cluster.name;

// Export the cluster kubeconfig
export const kubeconfig = cluster.kubeconfig;
22 changes: 22 additions & 0 deletions nodejs/eks/tests/replace-cluster-add-subnets/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"outDir": "bin",
"target": "es6",
"lib": [
"es6"
],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true
},
"files": [
"index.ts"
]
}

0 comments on commit 117497f

Please sign in to comment.