Skip to content

Commit ef4e766

Browse files
committed
[installer] Add EKS installer test
1 parent 26d3025 commit ef4e766

File tree

24 files changed

+999
-159
lines changed

24 files changed

+999
-159
lines changed

.werft/eks-installer-tests.yaml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# debug using `werft run github -f -s .werft/installer-tests.ts -j .werft/eks-installer-tests.yaml -a debug=true`
2+
pod:
3+
serviceAccount: werft
4+
affinity:
5+
nodeAffinity:
6+
requiredDuringSchedulingIgnoredDuringExecution:
7+
nodeSelectorTerms:
8+
- matchExpressions:
9+
- key: dev/workload
10+
operator: In
11+
values:
12+
- "builds"
13+
securityContext:
14+
runAsUser: 0
15+
volumes:
16+
- name: sh-playground-sa-perm
17+
secret:
18+
secretName: sh-playground-sa-perm
19+
- name: sh-playground-dns-perm
20+
secret:
21+
secretName: sh-playground-dns-perm
22+
- name: sh-aks-perm
23+
secret:
24+
secretName: aks-credentials
25+
containers:
26+
- name: nightly-test
27+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:cw-werft-cred.0
28+
workingDir: /workspace
29+
imagePullPolicy: Always
30+
volumeMounts:
31+
- name: sh-playground-sa-perm
32+
mountPath: /mnt/secrets/sh-playground-sa-perm
33+
- name: sh-playground-dns-perm # this sa is used for the DNS management
34+
mountPath: /mnt/secrets/sh-playground-dns-perm
35+
env:
36+
- name: AWS_ACCESS_KEY_ID
37+
valueFrom:
38+
secretKeyRef:
39+
name: aws-credentials
40+
key: aws-access-key
41+
- name: AWS_SECRET_ACCESS_KEY
42+
valueFrom:
43+
secretKeyRef:
44+
name: aws-credentials
45+
key: aws-secret-key
46+
- name: AWS_REGION
47+
valueFrom:
48+
secretKeyRef:
49+
name: aws-credentials
50+
key: aws-region
51+
- name: WERFT_HOST
52+
value: "werft.werft.svc.cluster.local:7777"
53+
- name: GOOGLE_APPLICATION_CREDENTIALS
54+
value: "/mnt/secrets/sh-playground-sa-perm/sh-sa.json"
55+
- name: WERFT_K8S_NAMESPACE
56+
value: "werft"
57+
- name: WERFT_K8S_LABEL
58+
value: "component=werft"
59+
- name: TF_VAR_sa_creds
60+
value: "/mnt/secrets/sh-playground-sa-perm/sh-sa.json"
61+
- name: TF_VAR_dns_sa_creds
62+
value: "/mnt/secrets/sh-playground-dns-perm/sh-dns-sa.json"
63+
- name: NODENAME
64+
valueFrom:
65+
fieldRef:
66+
fieldPath: spec.nodeName
67+
command:
68+
- bash
69+
- -c
70+
- |
71+
sleep 1
72+
set -Eeuo pipefail
73+
74+
sudo chown -R gitpod:gitpod /workspace
75+
sudo apt update && apt install gettext-base
76+
77+
export TF_VAR_TEST_ID="$(echo $RANDOM | md5sum | head -c 5; echo)"
78+
79+
(cd .werft && yarn install && mv node_modules ..) | werft log slice prep
80+
printf '{{ toJson . }}' > context.json
81+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
82+
unzip awscliv2.zip
83+
sudo ./aws/install
84+
85+
npx ts-node .werft/installer-tests.ts "STANDARD_EKS_TEST"
86+
# The bit below makes this a cron job
87+
# plugins:
88+
# cron: "15 3 * * *"

.werft/installer-tests.ts

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
3535
"STANDARD_GKE_CLUSTER",
3636
"CERT_MANAGER",
3737
"GCP_MANAGED_DNS",
38+
"CLUSTER_ISSUER",
3839
"GENERATE_KOTS_CONFIG",
3940
"INSTALL_GITPOD",
4041
"CHECK_INSTALLATION",
@@ -49,6 +50,7 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
4950
PHASES: [
5051
"STANDARD_GKE_CLUSTER",
5152
"CERT_MANAGER",
53+
"CLUSTER_ISSUER",
5254
"GCP_MANAGED_DNS",
5355
"GENERATE_KOTS_CONFIG",
5456
"INSTALL_GITPOD",
@@ -66,11 +68,12 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
6668
PHASES: [
6769
"STANDARD_K3S_CLUSTER_ON_GCP",
6870
"CERT_MANAGER",
71+
"CLUSTER_ISSUER",
6972
"GENERATE_KOTS_CONFIG",
7073
"INSTALL_GITPOD",
74+
"RESULTS",
7175
"CHECK_INSTALLATION",
7276
"RUN_INTEGRATION_TESTS",
73-
"RESULTS",
7477
"DESTROY",
7578
],
7679
},
@@ -80,6 +83,7 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
8083
PHASES: [
8184
"STANDARD_K3S_CLUSTER_ON_GCP",
8285
"CERT_MANAGER",
86+
"CLUSTER_ISSUER",
8387
"GENERATE_KOTS_CONFIG",
8488
"INSTALL_GITPOD",
8589
"CHECK_INSTALLATION",
@@ -92,8 +96,8 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
9296
PHASES: [
9397
"STANDARD_AKS_CLUSTER",
9498
"CERT_MANAGER",
95-
"AZURE_ISSUER",
96-
"AZURE_EXTERNALDNS",
99+
"CLUSTER_ISSUER",
100+
"EXTERNALDNS",
97101
"ADD_NS_RECORD",
98102
"GENERATE_KOTS_CONFIG",
99103
"INSTALL_GITPOD",
@@ -103,6 +107,23 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
103107
"DESTROY",
104108
],
105109
},
110+
STANDARD_EKS_TEST: {
111+
CLOUD: "aws",
112+
DESCRIPTION: "Create an EKS cluster",
113+
PHASES: [
114+
"STANDARD_EKS_CLUSTER",
115+
"CERT_MANAGER",
116+
"EXTERNALDNS",
117+
"CLUSTER_ISSUER",
118+
"ADD_NS_RECORD",
119+
"GENERATE_KOTS_CONFIG",
120+
"RESULTS",
121+
"INSTALL_GITPOD",
122+
"CHECK_INSTALLATION",
123+
"RUN_INTEGRATION_TESTS",
124+
"DESTROY",
125+
],
126+
},
106127
};
107128

108129
const config: TestConfig = TEST_CONFIGURATIONS[testConfig];
@@ -128,6 +149,11 @@ const INFRA_PHASES: { [name: string]: InfraConfig } = {
128149
makeTarget: "aks-standard-cluster",
129150
description: "Creating an aks cluster(azure)",
130151
},
152+
STANDARD_EKS_CLUSTER: {
153+
phase: "create-std-eks-cluster",
154+
makeTarget: "eks-standard-cluster",
155+
description: "Creating a EKS cluster with 1 nodepool each for workspace and server",
156+
},
131157
CERT_MANAGER: {
132158
phase: "setup-cert-manager",
133159
makeTarget: "cert-manager",
@@ -146,19 +172,19 @@ const INFRA_PHASES: { [name: string]: InfraConfig } = {
146172
)} db=${randomize("db", cloud)}`,
147173
description: `Generate KOTS Config file`,
148174
},
149-
AZURE_ISSUER: {
150-
phase: "setup-azure-cluster-issuer",
151-
makeTarget: "azure-issuer",
152-
description: "Deploys ClusterIssuer for azure",
175+
CLUSTER_ISSUER: {
176+
phase: "setup-cluster-issuer",
177+
makeTarget: `cluster-issuer cloud=${cloud}`,
178+
description: `Deploys ClusterIssuer for ${cloud}`,
153179
},
154-
AZURE_EXTERNALDNS: {
155-
phase: "azure-external-dns",
156-
makeTarget: "azure-external-dns",
157-
description: "Deploys external-dns with azure provider",
180+
EXTERNALDNS: {
181+
phase: "external-dns",
182+
makeTarget: `external-dns cloud=${cloud}`,
183+
description: `Deploys external-dns with ${cloud} provider`,
158184
},
159185
ADD_NS_RECORD: {
160186
phase: "add-ns-record",
161-
makeTarget: "add-ns-record",
187+
makeTarget: `add-ns-record cloud=${cloud}`,
162188
description: "Adds NS record for subdomain under gitpod-self-hosted.com",
163189
},
164190
INSTALL_GITPOD_IGNORE_PREFLIGHTS: {
@@ -189,7 +215,7 @@ const INFRA_PHASES: { [name: string]: InfraConfig } = {
189215
},
190216
DESTROY: {
191217
phase: "destroy",
192-
makeTarget: "cleanup",
218+
makeTarget: `cleanup cloud=${cloud}`,
193219
description: "Destroy the created infrastucture",
194220
},
195221
RESULTS: {
@@ -224,23 +250,24 @@ export async function installerTests(config: TestConfig) {
224250
}
225251

226252
function callMakeTargets(phase: string, description: string, makeTarget: string) {
227-
werft.phase(phase, `${description}`);
228-
werft.log(phase, `calling ${makeTarget}`);
253+
werft.phase(phase, description);
229254

230255
const response = exec(`make -C ${makefilePath} ${makeTarget}`, {
231-
slice: "call-make-target",
256+
slice: phase,
232257
dontCheckRc: true,
233258
});
234259

235260
if (response.code) {
236261
console.error(`Error: ${response.stderr}`);
237262
werft.fail(phase, "Operation failed");
238-
} else {
239-
werft.log(phase, response.stdout.toString());
240-
werft.done(phase);
263+
return response.code;
241264
}
242265

266+
werft.log(phase, response.stdout.toString());
267+
werft.done(phase);
268+
243269
return response.code;
270+
244271
}
245272

246273
function randomize(resource: string, platform: string): string {
@@ -254,7 +281,10 @@ function cleanup() {
254281
const phase = "destroy-infrastructure";
255282
werft.phase(phase, "Destroying all the created resources");
256283

257-
const response = exec(`make -C ${makefilePath} cleanup`, { slice: "run-terrafrom-destroy", dontCheckRc: true });
284+
const response = exec(`make -C ${makefilePath} cleanup cloud=${cloud}`, {
285+
slice: "run-terrafrom-destroy",
286+
dontCheckRc: true,
287+
});
258288

259289
// if the destroy command fail, we check if any resources are pending to be removed
260290
// if nothing is yet to be cleaned, we return with success

install/infra/terraform/aks/output.tf

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,32 @@ output "external_dns_secrets" {
3636
}
3737

3838
output "external_dns_settings" {
39-
value = {
40-
provider = "azure"
41-
"azure.resourceGroup" = azurerm_resource_group.gitpod.name
42-
"azure.subscriptionId" = data.azurerm_client_config.current.subscription_id
43-
"azure.tenantId" = data.azurerm_client_config.current.tenant_id
44-
"azure.useManagedIdentityExtension" = true
45-
"azure.userAssignedIdentityID" = azurerm_kubernetes_cluster.k8s.kubelet_identity.0.client_id
46-
}
39+
value = [
40+
{
41+
"name": "provider",
42+
"value": "azure"
43+
},
44+
{
45+
"name": "azure.resourceGroup",
46+
"value": azurerm_resource_group.gitpod.name,
47+
},
48+
{
49+
"name": "azure.subscriptionId",
50+
"value": data.azurerm_client_config.current.subscription_id,
51+
},
52+
{
53+
"name": "azure.tenantId",
54+
"value": data.azurerm_client_config.current.tenant_id,
55+
},
56+
{
57+
"name": "azure.useManagedIdentityExtension",
58+
"value": true
59+
},
60+
{
61+
"name": "azure.userAssignedIdentityID",
62+
"value": azurerm_kubernetes_cluster.k8s.kubelet_identity.0.client_id
63+
},
64+
]
4765
}
4866

4967
output "k8s_connection" {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
resource "aws_db_subnet_group" "gitpod_subnets" {
2+
name = "db-sg-${var.cluster_name}"
3+
subnet_ids = [module.vpc.public_subnets[2], module.vpc.public_subnets[3]]
4+
}
5+
6+
resource "aws_security_group" "rdssg" {
7+
name = "dh-sg-${var.cluster_name}"
8+
vpc_id = module.vpc.vpc_id
9+
10+
ingress {
11+
from_port = 0
12+
to_port = 3306
13+
protocol = "tcp"
14+
cidr_blocks = ["0.0.0.0/0"]
15+
}
16+
17+
egress {
18+
from_port = 0
19+
to_port = 0
20+
protocol = "-1"
21+
cidr_blocks = ["0.0.0.0/0"]
22+
}
23+
}
24+
25+
resource "aws_db_instance" "gitpod" {
26+
allocated_storage = 10
27+
max_allocated_storage = 100
28+
engine = "mysql"
29+
engine_version = "5.7"
30+
instance_class = "db.t3.micro"
31+
vpc_security_group_ids = [ aws_security_group.rdssg.id ]
32+
identifier = "db-${var.cluster_name}"
33+
name = "gitpod"
34+
username = "gitpod"
35+
password = "gitpod-qwat"
36+
parameter_group_name = "default.mysql5.7"
37+
db_subnet_group_name = aws_db_subnet_group.gitpod_subnets.name
38+
skip_final_snapshot = true
39+
publicly_accessible = true
40+
}

0 commit comments

Comments
 (0)