Skip to content

Commit 4dc3e39

Browse files
hakuna-matatahHarish Kuna
andauthored
IGW routes for KIT CP LB; Custom tags for KIT CP and DP;update karp (#62)
Co-authored-by: Harish Kuna <[email protected]>
1 parent f805967 commit 4dc3e39

File tree

3 files changed

+50
-46
lines changed

3 files changed

+50
-46
lines changed

testbed/addons/karpenter/construct.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class Karpenter extends cdk.Construct {
6262
const chart = props.cluster.addHelmChart('karpenter', {
6363
chart: 'karpenter',
6464
release: 'karpenter',
65-
version: 'v0.3.1',
65+
version: 'v0.4.1',
6666
repository: 'https://awslabs.github.io/karpenter/charts',
6767
namespace: namespace,
6868
createNamespace: false,
@@ -77,21 +77,5 @@ export class Karpenter extends cdk.Construct {
7777
}
7878
})
7979
chart.node.addDependency(ns)
80-
81-
// Default Provisioner
82-
props.cluster.addManifest("default-provisioner", {
83-
apiVersion: 'karpenter.sh/v1alpha3',
84-
kind: 'Provisioner',
85-
metadata: {
86-
name: 'default',
87-
},
88-
spec: {
89-
cluster: {
90-
name: props.cluster.clusterName,
91-
endpoint: props.cluster.clusterEndpoint,
92-
},
93-
ttlSecondsAfterEmpty: 30,
94-
}
95-
}).node.addDependency(chart)
9680
}
9781
}

testbed/addons/kit/construct.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,6 @@ export class Kit extends cdk.Construct {
5252
],
5353
}))
5454

55-
// Node Role
56-
const nodeRole = new iam.Role(this, 'kit-node-role', {
57-
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com'),
58-
managedPolicies: [
59-
iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSWorkerNodePolicy'),
60-
iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEC2ContainerRegistryReadOnly'),
61-
iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKS_CNI_Policy'),
62-
iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonSSMManagedInstanceCore')
63-
]
64-
})
65-
66-
props.cluster.awsAuth.addRoleMapping(nodeRole, {
67-
username: 'system:node:{{EC2PrivateDNSName}}',
68-
groups: ['system:bootstrappers', 'system:nodes']
69-
})
70-
71-
new iam.CfnInstanceProfile(this, 'kit-instance-profile', {
72-
roles: [nodeRole.roleName],
73-
instanceProfileName: 'KitNodeInstanceProfile'
74-
})
75-
7655
// Install kit
7756
const chart = props.cluster.addHelmChart('kit', {
7857
chart: 'kit-operator',
@@ -92,5 +71,27 @@ export class Kit extends cdk.Construct {
9271
}
9372
})
9473
chart.node.addDependency(ns)
74+
75+
//Karp Provisioner for kit
76+
props.cluster.addManifest("default-provisioner", {
77+
apiVersion: 'karpenter.sh/v1alpha5',
78+
kind: 'Provisioner',
79+
metadata: {
80+
name: 'default',
81+
},
82+
spec: {
83+
provider: {
84+
cluster: {
85+
name: props.cluster.clusterName,
86+
endpoint: props.cluster.clusterEndpoint,
87+
},
88+
subnetSelector: {
89+
"kit/hostcluster": `${props.cluster.clusterName}-controlplane`
90+
}
91+
},
92+
ttlSecondsAfterEmpty: 30,
93+
}
94+
})
95+
9596
}
9697
}

testbed/stack.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface TestbedProps extends cdk.StackProps {
1111
}
1212

1313
export class Testbed extends cdk.Stack {
14-
constructor(scope: cdk.Construct, id: string="testbed", props: TestbedProps) {
14+
constructor(scope: cdk.Construct, id: string = "testbed", props: TestbedProps) {
1515
super(scope, id, props)
1616

1717
const vpc = new ec2.Vpc(this, id, {
@@ -30,6 +30,15 @@ export class Testbed extends cdk.Stack {
3030
},
3131
],
3232
});
33+
34+
//Tag pub subnets for KIT CP
35+
const selection = vpc.selectSubnets({
36+
subnetType: ec2.SubnetType.PUBLIC
37+
});
38+
selection.subnets.forEach(subnet => {
39+
Tags.of(subnet).add('kit/hostcluster', `${id}-controlplane`)
40+
})
41+
3342
//ToDo: revisit once this is resolved - https://github.com/aws/aws-cdk/issues/5927
3443
// index<=8 will give us 9 /16 cidrs additionally to make a mega VPC.
3544
for (let index = 0; index <= 8; index++) {
@@ -38,26 +47,37 @@ export class Testbed extends cdk.Stack {
3847
cidrBlock: `10.${index + 1}.0.0/16`
3948
});
4049
let privateSubnet = new ec2.PrivateSubnet(this, `${id}-private-subnet-${index}`, {
41-
availabilityZone: cdk.Stack.of(this).availabilityZones[index%cdk.Stack.of(this).availabilityZones.length],
50+
availabilityZone: cdk.Stack.of(this).availabilityZones[index % cdk.Stack.of(this).availabilityZones.length],
4251
vpcId: vpc.vpcId,
4352
cidrBlock: `10.${index + 1}.0.0/16`
4453
})
4554
privateSubnet.node.addDependency(additionalCidr);
55+
//Tag pub subnets for KIT DP
56+
Tags.of(privateSubnet).add('kit/hostcluster', `${id}-dataplane`)
57+
let natSubnet = new ec2.PublicSubnet(this, `${id}-nat-subnet-${index}`, {
58+
availabilityZone: cdk.Stack.of(this).availabilityZones[index % cdk.Stack.of(this).availabilityZones.length],
59+
vpcId: vpc.vpcId,
60+
cidrBlock: `10.0.64.${index * 16}/28`
61+
})
62+
//add igw route for nat subnets
63+
let routeTableId = natSubnet.routeTable.routeTableId
64+
new ec2.CfnRoute(this, 'publicIGWRoute' + index, {
65+
routeTableId,
66+
gatewayId: vpc.internetGatewayId,
67+
destinationCidrBlock: "0.0.0.0/0"
68+
})
4669

4770
ec2.NatProvider.gateway().configureNat({
4871
natSubnets: [
49-
new ec2.PublicSubnet(this, `${id}-nat-subnet-${index}`, {
50-
availabilityZone: cdk.Stack.of(this).availabilityZones[index%cdk.Stack.of(this).availabilityZones.length],
51-
vpcId: vpc.vpcId,
52-
cidrBlock: `10.0.64.${index*16}/28`
53-
})
72+
natSubnet
5473
],
5574
privateSubnets: [
5675
privateSubnet
5776
],
5877
vpc: vpc
5978
})
6079
}
80+
6181
const cluster = new eks.Cluster(this, 'cluster', {
6282
clusterName: id,
6383
vpc: vpc,
@@ -87,7 +107,6 @@ export class Testbed extends cdk.Stack {
87107
]
88108
}),
89109
})
90-
91110
// service account used by tekton workflows.
92111
cluster.addServiceAccount('test-executor', { name: 'test-executor' })
93112
.role.addManagedPolicy({ managedPolicyArn: 'arn:aws:iam::aws:policy/AdministratorAccess' })

0 commit comments

Comments
 (0)