Skip to content

Commit c0f2a9e

Browse files
committed
new dns terraform
1 parent a96a0d9 commit c0f2a9e

File tree

7 files changed

+146
-3
lines changed

7 files changed

+146
-3
lines changed

.werft/build.ts

+36-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ const installerSlices = {
7373
INSTALLER_RENDER: "installer render",
7474
INSTALLER_POST_PROCESSING: "installer post processing",
7575
APPLY_INSTALL_MANIFESTS: "installer apply",
76-
DEPLOYMENT_WAITING: "monitor server deployment"
76+
DEPLOYMENT_WAITING: "monitor server deployment",
77+
DNS_ADD_RECORD: "add dns record"
7778
}
7879

7980
const vmSlices = {
@@ -396,6 +397,7 @@ export async function deployToDevWithInstaller(deploymentConfig: DeploymentConfi
396397

397398
// Now we want to execute further kubectl operations only in the created namespace
398399
setKubectlContextNamespace(namespace, metaEnv({ slice: installerSlices.SET_CONTEXT }));
400+
werft.done(installerSlices.SET_CONTEXT)
399401

400402
// trigger certificate issuing
401403
try {
@@ -578,6 +580,39 @@ export async function deployToDevWithInstaller(deploymentConfig: DeploymentConfi
578580
} catch (err) {
579581
werft.fail(installerSlices.DEPLOYMENT_WAITING, err);
580582
}
583+
let wsProxyLBIP = null
584+
werft.log(installerSlices.DNS_ADD_RECORD, "Getting ws-proxy loadbalancer IP");
585+
for (let i = 0; i < 60; i++) {
586+
try {
587+
let lb = exec(`kubectl -n ${deploymentConfig.namespace} get service ws-proxy -o=jsonpath='{.status.loadBalancer.ingress[0].ip}'`, { silent: true })
588+
if (lb.length > 4) {
589+
wsProxyLBIP = lb
590+
break
591+
}
592+
await sleep(1000)
593+
} catch (err) {
594+
await sleep(1000)
595+
}
596+
}
597+
if (wsProxyLBIP == null) {
598+
werft.fail(installerSlices.DNS_ADD_RECORD, new Error("Can't get ws-proxy loadbalancer IP"));
599+
}
600+
werft.log(installerSlices.DNS_ADD_RECORD, "Get ws-proxy loadbalancer IP: " + wsProxyLBIP);
601+
602+
var cmd = `set -x \
603+
&& cd /workspace/.werft/dns \
604+
&& rm -rf .terraform* \
605+
&& export GOOGLE_APPLICATION_CREDENTIALS="${GCLOUD_SERVICE_ACCOUNT_PATH}" \
606+
&& terraform init -backend-config='prefix=${deploymentConfig.namespace}' -migrate-state -upgrade \
607+
&& terraform apply -auto-approve \
608+
-var 'dns_zone_domain=gitpod-dev.com' \
609+
-var 'domain=${deploymentConfig.domain}' \
610+
-var 'ingress_ip=${getCoreDevIngressIP()}' \
611+
-var 'ws_proxy_ip=${wsProxyLBIP}'`;
612+
613+
werft.log(installerSlices.DNS_ADD_RECORD, "Terraform command for create dns record: " + cmd)
614+
exec(cmd, { ...metaEnv(), slice: installerSlices.DNS_ADD_RECORD });
615+
werft.done(installerSlices.DNS_ADD_RECORD);
581616

582617
// TODO: Fix sweeper, it does not appear to be doing clean-up
583618
werft.log('sweeper', 'installing Sweeper');

.werft/dns/main.tf

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# https://www.terraform.io/docs/providers/google/guides/provider_reference.html
2+
provider "google" {
3+
project = "gitpod-dev"
4+
region = "europe-west-3"
5+
# Relies on GOOGLE_APPLICATION_CREDENTIALS pointing to the service account file
6+
}
7+
8+
# Added for compatibility with old branches, can be deleted if compatibility is not needed
9+
provider "kubectl" {
10+
load_config_file = true
11+
}
12+
13+
locals {
14+
# As we did create the zone and IP manually beforehand: have the zone name statically determined
15+
dns_zone_name = replace(trimsuffix(var.dns_zone_domain, ".-"), ".", "-")
16+
project = "gitpod-dev"
17+
region = "europe-west-3"
18+
}
19+
20+
#
21+
# DNS records
22+
#
23+
24+
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/dns_record_set
25+
resource "google_dns_record_set" "gitpod" {
26+
count = length(var.ingress_subdomains)
27+
name = "${var.ingress_subdomains[count.index]}${var.domain}."
28+
type = "A"
29+
ttl = 300
30+
managed_zone = local.dns_zone_name
31+
rrdatas = [var.ingress_ip]
32+
project = local.project
33+
}
34+
resource "google_dns_record_set" "gitpod_ws" {
35+
name = "${var.ws_proxy_subdomain}${var.domain}."
36+
type = "A"
37+
ttl = 300
38+
managed_zone = local.dns_zone_name
39+
rrdatas = [var.ws_proxy_ip]
40+
project = local.project
41+
}
42+
43+
#
44+
# End
45+
#
46+
resource "null_resource" "done" {
47+
depends_on = [
48+
google_dns_record_set.gitpod,
49+
google_dns_record_set.gitpod_ws,
50+
]
51+
}
52+
53+
54+
output "done" {
55+
value = null_resource.done.id
56+
}

.werft/dns/variables.tf

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# e.g.: gitpod-dev.com
2+
variable "dns_zone_domain" {
3+
type = string
4+
}
5+
6+
# e.g.: my-branch.staging.gitpod-dev.com
7+
variable "domain" {
8+
type = string
9+
}
10+
11+
# e.g.: ["", "*.", "*.ws-dev."]
12+
variable "ingress_subdomains" {
13+
type = list(string)
14+
default = ["", "*."]
15+
}
16+
17+
variable "ws_proxy_subdomain" {
18+
type = string
19+
default = "*.ws-dev."
20+
}
21+
22+
variable "ingress_ip" {
23+
type = string
24+
}
25+
26+
variable "ws_proxy_ip" {
27+
type = string
28+
}

.werft/dns/versions.tf

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
backend "gcs" {
3+
bucket = "gitpod-core-dev-terraform"
4+
}
5+
required_providers {
6+
google = {
7+
source = "hashicorp/google"
8+
version = "3.63.0"
9+
}
10+
11+
# Added for compatibility with old branches, can be deleted if compatibility is not needed
12+
kubectl = {
13+
source = "gavinbunney/kubectl"
14+
version = "1.10.1"
15+
}
16+
}
17+
required_version = ">= 0.13"
18+
}

.werft/post-process.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ while [ "$i" -le "$DOCS" ]; do
206206
WS_HOST_SUFFIX_EXPR="s/\"workspaceHostSuffix\": \".$CURRENT_WS_HOST_NAME\"/\"workspaceHostSuffix\": \".$NEW_WS_HOST_NAME\"/"
207207
sed -i "$WS_HOST_SUFFIX_EXPR" /tmp/"$NAME"overrides.yaml
208208

209+
sed -i "s/x-wsproxy-host/Host/" /tmp/"$NAME"overrides.yaml
210+
209211
CURRENT_WS_SUFFIX_REGEX=$DEV_BRANCH.$STAGING_HOST_NAME
210212
# In this, we only do a find replace on a given line if we find workspaceHostSuffixRegex on the line
211213
sed -i -e "/workspaceHostSuffixRegex/s/$CURRENT_WS_SUFFIX_REGEX/$DEV_BRANCH\\\\\\\\.staging\\\\\\\\.gitpod-dev\\\\\\\\.com/g" /tmp/"$NAME"overrides.yaml
@@ -216,7 +218,10 @@ while [ "$i" -le "$DOCS" ]; do
216218
if [[ "ws-proxy" == "$NAME" ]] && [[ "$KIND" == "Service" ]]; then
217219
WORK="overrides for $NAME $KIND"
218220
echo "$WORK"
219-
yq w -i k8s.yaml -d "$i" "metadata.annotations[cloud.google.com/neg]" '{"exposed_ports": {"22":{}}}'
221+
# notice that current we use array index
222+
yq w -i k8s.yaml -d "$i" "spec.ports.(name==http-proxy).port" 80
223+
yq w -i k8s.yaml -d "$i" "spec.ports.(name==https-proxy).port" 443
224+
yq w -i k8s.yaml -d "$i" "metadata.annotations[cloud.google.com/neg]" '{"exposed_ports": {"22":{},"80":{},"443":{}}}'
220225
yq w -i k8s.yaml -d "$i" spec.type LoadBalancer
221226
fi
222227

.werft/util/certs.ts

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export async function installCertficate(werft, params: InstallCertificateParams,
134134
}
135135
if (!notReadyYet) {
136136
werft.log('certificate', `copied certificate from "${params.certNamespace}/${params.certName}" to "${params.destinationNamespace}/${params.certSecretName}"`);
137+
werft.done('certificate')
137138
} else {
138139
werft.fail('certificate', `failed to copy certificate from "${params.certNamespace}/${params.certName}" to "${params.destinationNamespace}/${params.certSecretName}"`)
139140
}

installer/pkg/config/v1/validation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (v version) ClusterValidation(rcfg interface{}) cluster.ValidationChecks {
169169
}
170170
if len(signers) == 0 {
171171
errors = append(errors, cluster.ValidationError{
172-
Message: fmt.Sprintf("Secret '%s' not contain any valild host key", secretName),
172+
Message: fmt.Sprintf("Secret '%s' does not contain a valid host key", secretName),
173173
Type: cluster.ValidationStatusError,
174174
})
175175
}

0 commit comments

Comments
 (0)