Skip to content

Commit 11e92f2

Browse files
committed
adding AKS tf module
1 parent ed97560 commit 11e92f2

File tree

20 files changed

+924
-30
lines changed

20 files changed

+924
-30
lines changed

.werft/aks-installer-tests.yaml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# debug using `werft run github -f -s .werft/installer-tests.ts -j .werft/aks-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-aks-perm
34+
mountPath: /mnt/secrets/sh-aks-perm
35+
- name: sh-playground-dns-perm # this sa is used for the DNS management
36+
mountPath: /mnt/secrets/sh-playground-dns-perm
37+
env:
38+
- name: ARM_SUBSCRIPTION_ID
39+
valueFrom:
40+
secretKeyRef:
41+
name: aks-credentials
42+
key: subscriptionid
43+
- name: ARM_TENANT_ID
44+
valueFrom:
45+
secretKeyRef:
46+
name: aks-credentials
47+
key: tenantid
48+
- name: ARM_CLIENT_ID
49+
valueFrom:
50+
secretKeyRef:
51+
name: aks-credentials
52+
key: clientid
53+
- name: ARM_CLIENT_SECRET
54+
valueFrom:
55+
secretKeyRef:
56+
name: aks-credentials
57+
key: clientsecret
58+
- name: WERFT_HOST
59+
value: "werft.werft.svc.cluster.local:7777"
60+
- name: GOOGLE_APPLICATION_CREDENTIALS
61+
value: "/mnt/secrets/sh-playground-sa-perm/sh-sa.json"
62+
- name: WERFT_K8S_NAMESPACE
63+
value: "werft"
64+
- name: WERFT_K8S_LABEL
65+
value: "component=werft"
66+
- name: TF_VAR_sa_creds
67+
value: "/mnt/secrets/sh-playground-sa-perm/sh-sa.json"
68+
- name: TF_VAR_dns_sa_creds
69+
value: "/mnt/secrets/sh-playground-dns-perm/sh-dns-sa.json"
70+
- name: NODENAME
71+
valueFrom:
72+
fieldRef:
73+
fieldPath: spec.nodeName
74+
command:
75+
- bash
76+
- -c
77+
- |
78+
sleep 1
79+
set -Eeuo pipefail
80+
81+
sudo chown -R gitpod:gitpod /workspace
82+
sudo apt update && apt install gettext-base
83+
84+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
85+
86+
export TF_VAR_TEST_ID=$(echo $RANDOM | md5sum | head -c 5; echo)
87+
88+
(cd .werft && yarn install && mv node_modules ..) | werft log slice prep
89+
printf '{{ toJson . }}' > context.json
90+
91+
npx ts-node .werft/installer-tests.ts "STANDARD_AKS_TEST"
92+
# The bit below makes this a cron job
93+
# plugins:
94+
# cron: "15 3 * * *"

.werft/installer-tests.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const INFRA_PHASES: { [name: string]: InfraConfig } = {
3434
makeTarget: "k3s-standard-cluster",
3535
description: "Creating a k3s cluster on GCP with 1 node",
3636
},
37+
STANDARD_AKS_CLUSTER: {
38+
phase: "create-std-aks-cluster",
39+
makeTarget: "aks-standard-cluster",
40+
description: "Creating an aks cluster(azure)",
41+
},
3742
CERT_MANAGER: {
3843
phase: "setup-cert-manager",
3944
makeTarget: "cert-manager",
@@ -49,6 +54,21 @@ const INFRA_PHASES: { [name: string]: InfraConfig } = {
4954
makeTarget: "generate-kots-config",
5055
description: `Generate KOTS Config file`,
5156
},
57+
AZURE_ISSUER: {
58+
phase: "setup-azure-cluster-issuer",
59+
makeTarget: "azure-issuer",
60+
description: "Deploys ClusterIssuer for azure",
61+
},
62+
AZURE_EXTERNALDNS: {
63+
phase: "azure-external-dns",
64+
makeTarget: "azure-external-dns",
65+
description: "Deploys external-dns with azure provider",
66+
},
67+
ADD_NS_RECORD: {
68+
phase: "add-ns-record",
69+
makeTarget: "add-ns-record",
70+
description: "Adds NS record for subdomain under gitpod-self-hosted.com",
71+
},
5272
INSTALL_GITPOD_IGNORE_PREFLIGHTS: {
5373
phase: "install-gitpod-without-preflights",
5474
makeTarget: `kots-install channel=${channel} version=${version} preflights=false`, // this is a bit of a hack, for now we pass params like this
@@ -123,6 +143,22 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
123143
"DESTROY",
124144
],
125145
},
146+
STANDARD_AKS_TEST: {
147+
DESCRIPTION: "Deploy Gitpod on AKS, with managed DNS, and run integration tests",
148+
PHASES: [
149+
"STANDARD_AKS_CLUSTER",
150+
"CERT_MANAGER",
151+
"AZURE_ISSUER",
152+
"AZURE_EXTERNALDNS",
153+
"ADD_NS_RECORD",
154+
"GENERATE_KOTS_CONFIG",
155+
"INSTALL_GITPOD",
156+
"RESULTS",
157+
"CHECK_INSTALLATION",
158+
"RUN_INTEGRATION_TESTS",
159+
"DESTROY",
160+
],
161+
},
126162
STANDARD_K3S_TEST: {
127163
DESCRIPTION:
128164
"Deploy Gitpod on a K3s cluster, created on a GCP instance," +

install/infra/terraform/aks/README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Azure
2+
3+
Azure provider for Gitpod testing
4+
5+
<!-- toc -->
6+
7+
- [Terraform Documentation](#terraform-documentation)
8+
* [Requirements](#requirements)
9+
* [Providers](#providers)
10+
* [Modules](#modules)
11+
* [Resources](#resources)
12+
* [Inputs](#inputs)
13+
* [Outputs](#outputs)
14+
15+
<!-- tocstop -->
16+
17+
# Terraform Documentation
18+
19+
<!-- BEGIN_TF_DOCS -->
20+
## Requirements
21+
22+
| Name | Version |
23+
|------|---------|
24+
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | >= 3.0.0, < 4.0.0 |
25+
26+
## Providers
27+
28+
| Name | Version |
29+
|------|---------|
30+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | >= 3.0.0, < 4.0.0 |
31+
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
32+
33+
## Modules
34+
35+
No modules.
36+
37+
## Resources
38+
39+
| Name | Type |
40+
|------|------|
41+
| [azurerm_container_registry.registry](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry) | resource |
42+
| [azurerm_dns_zone.dns](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dns_zone) | resource |
43+
| [azurerm_kubernetes_cluster.k8s](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster) | resource |
44+
| [azurerm_kubernetes_cluster_node_pool.pools](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster_node_pool) | resource |
45+
| [azurerm_log_analytics_solution.monitoring](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_solution) | resource |
46+
| [azurerm_log_analytics_workspace.monitoring](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_workspace) | resource |
47+
| [azurerm_mysql_database.db](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_database) | resource |
48+
| [azurerm_mysql_firewall_rule.db](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_firewall_rule) | resource |
49+
| [azurerm_mysql_server.db](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_server) | resource |
50+
| [azurerm_network_security_rule.k8s](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule) | resource |
51+
| [azurerm_resource_group.gitpod](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
52+
| [azurerm_role_assignment.k8s](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
53+
| [azurerm_role_assignment.registry](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
54+
| [azurerm_storage_account.storage](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) | resource |
55+
| [azurerm_subnet.network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) | resource |
56+
| [azurerm_virtual_network.network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) | resource |
57+
| [random_integer.db](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) | resource |
58+
| [random_integer.registry](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) | resource |
59+
| [random_integer.storage](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) | resource |
60+
| [random_password.db](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
61+
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) | data source |
62+
| [azurerm_kubernetes_service_versions.k8s](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/kubernetes_service_versions) | data source |
63+
| [azurerm_resources.k8s](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resources) | data source |
64+
65+
## Inputs
66+
67+
| Name | Description | Type | Default | Required |
68+
|------|-------------|------|---------|:--------:|
69+
| <a name="input_dns_enabled"></a> [dns\_enabled](#input\_dns\_enabled) | Common variables | `any` | n/a | yes |
70+
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | n/a | `any` | n/a | yes |
71+
| <a name="input_enable_airgapped"></a> [enable\_airgapped](#input\_enable\_airgapped) | n/a | `any` | n/a | yes |
72+
| <a name="input_enable_external_database"></a> [enable\_external\_database](#input\_enable\_external\_database) | n/a | `any` | n/a | yes |
73+
| <a name="input_enable_external_registry"></a> [enable\_external\_registry](#input\_enable\_external\_registry) | n/a | `any` | n/a | yes |
74+
| <a name="input_enable_external_storage"></a> [enable\_external\_storage](#input\_enable\_external\_storage) | n/a | `any` | n/a | yes |
75+
| <a name="input_labels"></a> [labels](#input\_labels) | n/a | `any` | n/a | yes |
76+
| <a name="input_location"></a> [location](#input\_location) | Azure-specific variables | `any` | n/a | yes |
77+
| <a name="input_name_format"></a> [name\_format](#input\_name\_format) | n/a | `any` | n/a | yes |
78+
| <a name="input_name_format_global"></a> [name\_format\_global](#input\_name\_format\_global) | n/a | `any` | n/a | yes |
79+
| <a name="input_workspace_name"></a> [workspace\_name](#input\_workspace\_name) | n/a | `any` | n/a | yes |
80+
81+
## Outputs
82+
83+
| Name | Description |
84+
|------|-------------|
85+
| <a name="output_cert_manager_issuer"></a> [cert\_manager\_issuer](#output\_cert\_manager\_issuer) | n/a |
86+
| <a name="output_cert_manager_secret"></a> [cert\_manager\_secret](#output\_cert\_manager\_secret) | n/a |
87+
| <a name="output_cluster_name"></a> [cluster\_name](#output\_cluster\_name) | n/a |
88+
| <a name="output_database"></a> [database](#output\_database) | n/a |
89+
| <a name="output_domain_nameservers"></a> [domain\_nameservers](#output\_domain\_nameservers) | n/a |
90+
| <a name="output_external_dns_secrets"></a> [external\_dns\_secrets](#output\_external\_dns\_secrets) | n/a |
91+
| <a name="output_external_dns_settings"></a> [external\_dns\_settings](#output\_external\_dns\_settings) | n/a |
92+
| <a name="output_k8s_connection"></a> [k8s\_connection](#output\_k8s\_connection) | n/a |
93+
| <a name="output_kubeconfig"></a> [kubeconfig](#output\_kubeconfig) | n/a |
94+
| <a name="output_region"></a> [region](#output\_region) | n/a |
95+
| <a name="output_registry"></a> [registry](#output\_registry) | n/a |
96+
| <a name="output_storage"></a> [storage](#output\_storage) | n/a |
97+
<!-- END_TF_DOCS -->
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
resource "random_integer" "db" {
2+
count = var.enable_external_database ? 1 : 0
3+
4+
min = 10000
5+
max = 99999
6+
}
7+
8+
resource "random_password" "db" {
9+
count = var.enable_external_database ? 1 : 0
10+
11+
length = 32
12+
}
13+
14+
resource "azurerm_mysql_server" "db" {
15+
count = var.enable_external_database ? 1 : 0
16+
17+
name = "gitpod-${random_integer.db[count.index].result}"
18+
location = azurerm_resource_group.gitpod.location
19+
resource_group_name = azurerm_resource_group.gitpod.name
20+
21+
sku_name = local.db
22+
storage_mb = 20480
23+
ssl_enforcement_enabled = false
24+
ssl_minimal_tls_version_enforced = "TLSEnforcementDisabled"
25+
version = "5.7"
26+
27+
auto_grow_enabled = true
28+
administrator_login = "gitpod"
29+
administrator_login_password = random_password.db[count.index].result
30+
}
31+
32+
resource "azurerm_mysql_firewall_rule" "db" {
33+
count = var.enable_external_database ? 1 : 0
34+
35+
name = "Azure_Resource"
36+
resource_group_name = azurerm_resource_group.gitpod.name
37+
server_name = azurerm_mysql_server.db[count.index].name
38+
start_ip_address = "0.0.0.0"
39+
end_ip_address = "0.0.0.0"
40+
}
41+
42+
resource "azurerm_mysql_database" "db" {
43+
count = var.enable_external_database ? 1 : 0
44+
45+
name = "gitpod"
46+
resource_group_name = azurerm_resource_group.gitpod.name
47+
server_name = azurerm_mysql_server.db[count.index].name
48+
charset = "utf8"
49+
collation = "utf8_unicode_ci"
50+
}

0 commit comments

Comments
 (0)