Skip to content

Commit 75ee91c

Browse files
authored
Merge pull request #17 from doitintl/integration
Integration
2 parents d373b82 + d8b25fd commit 75ee91c

13 files changed

+537
-104
lines changed

bin/cdk-main.ts

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,29 @@ const low_cost_EMEA_stack_config: cdk.StackProps = {
9393
//Note: 'lower-envs-vpc' is both the VPC name and the CloudFormation Stack Name
9494

9595
const lower_envs_vpc = new Opinionated_VPC(cdk_state, 'lower-envs-vpc', low_co2_AMER_stack_config);
96-
//Note: About the below lower_envs_vpc.apply_*_config() functions
97-
// The order in which you call these functions matters, because some functions set
98-
// values in a way that's intended to be overridable. This is why it's
99-
// recommended to follow the below order of application (global -> my_org -> env)
100-
lower_envs_vpc.apply_global_baseline_vpc_config();
101-
lower_envs_vpc.apply_my_orgs_baseline_vpc_config();
102-
lower_envs_vpc.apply_lower_envs_vpc_config();
103-
lower_envs_vpc.deploy_vpc_construct_into_this_objects_stack();
96+
lower_envs_vpc.stage_deployment_of_opinionated_vpc_for_lower_envs();
97+
// ^-- This applys global_baseline_vpc_config, then my_orgs_baseline_vpc_config, then lower_envs_vpc_config
98+
// Then stages deployment of vpc construct into lower_envs_vpc.stack
99+
// Actual Deployment happens when user runs `cdk deploy lower-envs-vpc`
100+
101+
// const higher_envs_vpc = new Opinionated_VPC(cdk_state, 'higher-envs-vpc', low_cost_AMER_stack_config);
102+
// higher_envs_vpc.stage_deployment_of_opinionated_vpc_for_higher_envs();
103+
/* ^-- This is commented out by default for 2 reasons:
104+
1. Every uncommented staged deployment makes `cdk list` take longer to finish
105+
(Things run faster if you wait to uncomment deployable stacks until needed.)
106+
2. It won't work until cdk bootstrap is run in the configured stack's region.
107+
(us-east-2 is associated with low_cost_AMER_stack_config)
108+
109+
Commands to bootstrap:
110+
Note: It's recommended to copy paste each command one at a time, & read output between runs.
111+
```bash
112+
export AWS_REGION=us-east-2
113+
export AWS_ACCOUNT=$(aws sts get-caller-identity | jq .Account | tr -d '"')
114+
echo $AWS_REGION
115+
echo $AWS_ACCOUNT
116+
cdk bootstrap aws://$AWS_ACCOUNT/$AWS_REGION
117+
```
118+
*/
104119
///////////////////////////////////////////////////////////////////////////////////////////
105120

106121

@@ -113,32 +128,46 @@ dev1_eks.apply_global_baseline_eks_config();
113128
dev1_eks.apply_my_orgs_baseline_eks_config();
114129
dev1_eks.apply_lower_envs_eks_config();
115130
dev1_eks.apply_dev_eks_config();
116-
dev1_eks.deploy_eks_construct_into_this_objects_stack();
117-
dev1_eks.deploy_global_baseline_eks_dependencies();
118-
dev1_eks.deploy_my_orgs_baseline_eks_dependencies();
119-
dev1_eks.deploy_lower_envs_eks_dependencies();
120-
dev1_eks.deploy_dev_eks_dependencies();
121-
dev1_eks.deploy_global_baseline_eks_workload_dependencies();
122-
dev1_eks.deploy_my_orgs_baseline_eks_workload_dependencies();
123-
dev1_eks.deploy_lower_envs_eks_workload_dependencies();
124-
dev1_eks.deploy_dev_eks_workload_dependencies();
125-
dev1_eks.deploy_global_baseline_eks_workloads();
126-
dev1_eks.deploy_my_orgs_baseline_eks_workloads();
127-
dev1_eks.deploy_lower_envs_eks_workloads();
128-
dev1_eks.deploy_dev_eks_workloads();
131+
dev1_eks.stage_deployment_of_eks_construct_into_this_objects_stack();
132+
dev1_eks.stage_deployment_of_global_baseline_eks_dependencies();
133+
dev1_eks.stage_deployment_of_my_orgs_baseline_eks_dependencies();
134+
dev1_eks.stage_deployment_of_lower_envs_eks_dependencies();
135+
dev1_eks.stage_deployment_of_dev_eks_dependencies();
136+
dev1_eks.stage_deployment_of_global_baseline_eks_workload_dependencies();
137+
dev1_eks.stage_deployment_of_my_orgs_baseline_eks_workload_dependencies();
138+
dev1_eks.stage_deployment_of_lower_envs_eks_workload_dependencies();
139+
dev1_eks.stage_deployment_of_dev_eks_workload_dependencies();
140+
dev1_eks.stage_deployment_of_global_baseline_eks_workloads();
141+
dev1_eks.stage_deployment_of_my_orgs_baseline_eks_workloads();
142+
dev1_eks.stage_deployment_of_lower_envs_eks_workloads();
143+
dev1_eks.stage_deployment_of_dev_eks_workloads();
129144
//^-- deployment time of ~18.6mins (~15-20mins)
130145

131146
//Example 2: Equivalent to Example 1, just with convenience methods as short hand
132147
//(This format balances usability and debugability)
133148
const dev2_eks = new Easy_EKS(cdk_state, 'dev2-eks', low_co2_AMER_stack_config);
134149
dev2_eks.apply_dev_baseline_config(); //<-- convenience method #1
135-
dev2_eks.deploy_eks_construct_into_this_objects_stack(); //<-- creates eks cluster
136-
dev2_eks.deploy_dev_baseline_dependencies(); //<-- convenience method #2
137-
dev2_eks.deploy_dev_baseline_workload_dependencies(); //<-- convenience method #3
138-
dev2_eks.deploy_dev_baseline_workloads(); //<-- convenience method #4
150+
dev2_eks.stage_deployment_of_eks_construct_into_this_objects_stack();
151+
dev2_eks.stage_deployment_of_dev_baseline_dependencies(); //<-- convenience method #2
152+
dev2_eks.stage_deployment_of_dev_baseline_workload_dependencies(); //<-- convenience method #3
153+
dev2_eks.stage_deployment_of_dev_baseline_workloads(); //<-- convenience method #4
139154

140155
//Example 3: Equivalent to Examples 1 & 2, just shorter
141156
//(This format optimizes usability, but can make debugability slightly harder)
142157
const dev3_eks = new Easy_EKS(cdk_state, 'dev3-eks', low_co2_AMER_stack_config);
143-
dev3_eks.deploy_opinionated_dev(); //<-- convenience method #5
158+
dev3_eks.stage_deployment_of_opinionated_eks_cluster_for_dev_envs(); //<-- convenience method #5
159+
160+
///////////////////////////////////////////////////////////////////////////////////////////
161+
// const test1_eks = new Easy_EKS(cdk_state, 'test1-eks', low_co2_AMER_stack_config);
162+
// test1_eks.stage_deployment_of_opinionated_eks_cluster_for_test_envs();
163+
// ^-- This is commented out, because:
164+
// Every uncommented staged deployment makes `cdk list` take longer to finish
165+
// (Things run faster if you wait to uncomment deployable stacks until you need them.)
166+
///////////////////////////////////////////////////////////////////////////////////////////
167+
// const stage1_eks = new Easy_EKS(cdk_state, 'stage1-eks', low_cost_AMER_stack_config);
168+
// stage1_eks.stage_deployment_of_opinionated_eks_cluster_for_stage_envs();
169+
// const prod1_eks = new Easy_EKS(cdk_state, 'prod1-eks', low_cost_AMER_stack_config);
170+
// prod1_eks.stage_deployment_of_opinionated_eks_cluster_for_prod_envs();
171+
// ^-- These are commented out, because:
172+
// In addition to the above reason, they also depend on higher-envs-vpc being deployed
144173
///////////////////////////////////////////////////////////////////////////////////////////

config/eks/dev_eks_config.ts

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as eks from 'aws-cdk-lib/aws-eks'
44
import * as iam from 'aws-cdk-lib/aws-iam';
55
import request from 'sync-request-curl'; //npm install sync-request-curl (cdk requires sync functions, async not allowed)
66
//Intended Use:
7-
//EasyEKS Admins: edit this file with config to apply to all dev cluster's in your org.
7+
//EasyEKS Admins: edit this file with config to apply to all dev / sandbox cluster's in your org.
88

99
export function apply_config(config: Easy_EKS_Config_Data, stack: cdk.Stack){ //config: is of type Easy_EKS_Config_Data
1010
config.addTag("Environment", "Dev");
@@ -23,7 +23,75 @@ export function deploy_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Sta
2323
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424

2525
export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
26-
26+
// This is an example of a workload that uses a PersistentVolumeClaim with a storage class that is encrypted
27+
// with AWS KMS key.
28+
// IMPORTANT: if the cdk insfrastructure is destroyed it will leave the volume orphans, and they will
29+
// need to be manually deleted.
30+
let name="test-claim-gp3";
31+
let size="10Gi";
32+
const volume_claim_gp3 = {
33+
"apiVersion": "v1",
34+
"kind": "PersistentVolumeClaim",
35+
"metadata": {
36+
"name": `${name}`,
37+
"namespace": "default"
38+
},
39+
"spec": {
40+
"accessModes": [
41+
"ReadWriteOnce"
42+
],
43+
"storageClassName": "kms-encrypted-gp3",
44+
"resources": {
45+
"requests": {
46+
"storage": `${size}`
47+
}
48+
}
49+
}
50+
}
51+
const pod_using_volume_claim = {
52+
"apiVersion": "v1",
53+
"kind": "Pod",
54+
"metadata": {
55+
"name": "app"
56+
},
57+
"spec": {
58+
"containers": [
59+
{
60+
"name": "app",
61+
"image": "ubuntu:latest",
62+
"command": [
63+
"/bin/sh"
64+
],
65+
"args": [
66+
"-c",
67+
"while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"
68+
],
69+
"volumeMounts": [
70+
{
71+
"name": "persistent-storage",
72+
"mountPath": "/data"
73+
}
74+
]
75+
}
76+
],
77+
"volumes": [
78+
{
79+
"name": "persistent-storage",
80+
"persistentVolumeClaim": {
81+
"claimName": `${name}`
82+
}
83+
}
84+
]
85+
}
86+
}
87+
const pvc_demo_construct = new eks.KubernetesManifest(stack, "persistentVolumeClaimManifest",
88+
{
89+
cluster: cluster,
90+
manifest: [volume_claim_gp3, pod_using_volume_claim],
91+
overwrite: true,
92+
prune: true,
93+
});
94+
pvc_demo_construct.node.addDependency(cluster.awsAuth);
2795
}//end deploy_workload_dependencies()
2896

2997
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

config/eks/global_baseline_eks_config.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,14 @@ import request from 'sync-request-curl'; //npm install sync-request-curl (cdk re
99

1010
//export function apply_config(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){ //config: is of type Easy_EKS_Config_Data
1111
export function apply_config(config: Easy_EKS_Config_Data, stack: cdk.Stack){ //config: is of type Easy_EKS_Config_Data
12-
config.addTag("AWS Tag Allowed Characters", "letters numbers + - = . _ : / @ WebSiteLinks");
13-
config.addTag("AWS Tag Forbidden Characters", "Hashtag Comma SingleQuote DoubleQuote Parenthesis QuestionMark Asterisk Ampersand https://docs.aws.amazon.com/codeguru/latest/bugbust-ug/limits-tags.html");
1412
config.addTag("IaC Tooling used for Provisioning and Management of this EKS Cluster", "cdk: a CLI tool that stands for AWS Cloud Development Kit.");
1513
config.addTag("Upstream Methodology Docs", "https://github.com/doitintl/easyeks");
16-
//^-- NOTE: hashtag(#) comma(,) singlequote(') doublequote(\") parenthesis() and more are not valid tag values
17-
// https://docs.aws.amazon.com/codeguru/latest/bugbust-ug/limits-tags.html
18-
/*Note it's possible when updating tags, that you could see
19-
An error like AWS::EKS::Nodegroup "Update is not supported for the following properties"
20-
If that happens temporarily edit the following line in Easy_EKS.ts
21-
this.cluster.addNodegroupCapacity(`default_MNG`, default_MNG);
22-
to
23-
this.cluster.addNodegroupCapacity(`default_MNG-1`, default_MNG);
24-
redeploy and it'll go through
25-
then rename it back
26-
Note:
27-
After setting default_MNG-1, you may see ...is in UPDATE_ROLLBACK_FAILED state and can not be updated
28-
If so, go to CloudFormation -> stack -> Stack actions -> continue update rollback for stack - Advanced troubleshooting
29-
--> resources to skip - optional (check the box) --> Continue update rollback.
30-
(wait 10 sec, then retry cdk deploy stack)
31-
*/
32-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
33-
14+
//^-- NOTE: AWS tag restrictions vary by service, but generally only letters, numbers, spaces, and the following characters are allowed: + - = . _ : / @
15+
// Tags are validated by the validateTag() function in lib/Utilities.ts before deployment
16+
// More details:
17+
// - https://docs.aws.amazon.com/eks/latest/userguide/eks-using-tags.html#tag-restrictions
18+
// - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-restrictions
19+
3420
}//end apply_config()
3521

3622
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

config/eks/my_orgs_baseline_eks_config.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,35 @@ export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack
268268
},
269269
}`, //end aws-ebs-csi-driver configurationValues override
270270
});
271+
// adding gp3 storage class
272+
const storage_class_gp3_manifest = {
273+
"apiVersion": "storage.k8s.io/v1",
274+
"kind": "StorageClass",
275+
"metadata": {
276+
"name": "kms-encrypted-gp3",
277+
"annotations": {
278+
"storageclass.kubernetes.io/is-default-class": "true"
279+
}
280+
},
281+
"provisioner": "ebs.csi.aws.com",
282+
"volumeBindingMode": "WaitForFirstConsumer",
283+
"allowVolumeExpansion": true,
284+
"reclaimPolicy": "Delete",
285+
"parameters": {
286+
"type": "gp3",
287+
"encrypted": "true",
288+
//"kmsKeyId": `${config.kmsKey.keyArn}` //commentig it out as while we test the logic to add permissions to customer's KMS key
289+
}
290+
}
291+
const storage_class_gp3_construct = new eks.KubernetesManifest(stack, "StorageClassManifest",
292+
{
293+
cluster: cluster,
294+
manifest: [storage_class_gp3_manifest],
295+
overwrite: true,
296+
prune: true,
297+
}
298+
);
299+
storage_class_gp3_construct.node.addDependency(cluster.awsAuth);
271300
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
272301

273302
// v-- most won't need this, disabling by default

config/eks/prod_eks_config.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Easy_EKS_Config_Data } from '../../lib/Easy_EKS_Config_Data';
2+
import * as cdk from 'aws-cdk-lib';
3+
import * as eks from 'aws-cdk-lib/aws-eks'
4+
import * as iam from 'aws-cdk-lib/aws-iam';
5+
import request from 'sync-request-curl'; //npm install sync-request-curl (cdk requires sync functions, async not allowed)
6+
//Intended Use:
7+
//EasyEKS Admins: edit this file with config to apply to all Prod / Production cluster's in your org.
8+
9+
export function apply_config(config: Easy_EKS_Config_Data, stack: cdk.Stack){ //config: is of type Easy_EKS_Config_Data
10+
config.addTag("Environment", "Prod");
11+
}//end apply_config()
12+
13+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16+
17+
export function deploy_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
18+
19+
}//end deploy_dependencies()
20+
21+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
22+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
23+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24+
25+
export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
26+
27+
}//end deploy_workload_dependencies()
28+
29+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
31+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32+
33+
export function deploy_workloads(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
34+
35+
}//end deploy_workloads()

config/eks/stage_eks_config.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Easy_EKS_Config_Data } from '../../lib/Easy_EKS_Config_Data';
2+
import * as cdk from 'aws-cdk-lib';
3+
import * as eks from 'aws-cdk-lib/aws-eks'
4+
import * as iam from 'aws-cdk-lib/aws-iam';
5+
import request from 'sync-request-curl'; //npm install sync-request-curl (cdk requires sync functions, async not allowed)
6+
//Intended Use:
7+
//EasyEKS Admins: edit this file with config to apply to all Stage / Staging / Pre-Production / UAT (User Acceptance Testing) cluster's in your org.
8+
9+
export function apply_config(config: Easy_EKS_Config_Data, stack: cdk.Stack){ //config: is of type Easy_EKS_Config_Data
10+
config.addTag("Environment", "Stage");
11+
}//end apply_config()
12+
13+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16+
17+
export function deploy_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
18+
19+
}//end deploy_dependencies()
20+
21+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
22+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
23+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24+
25+
export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
26+
27+
}//end deploy_workload_dependencies()
28+
29+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
31+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32+
33+
export function deploy_workloads(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
34+
35+
}//end deploy_workloads()

0 commit comments

Comments
 (0)