Skip to content

Commit 8613d7e

Browse files
committed
Yugabyte in GCP
1 parent 43fce09 commit 8613d7e

File tree

33 files changed

+955
-31
lines changed

33 files changed

+955
-31
lines changed

deploy/infrastructure/dependencies/terraform-aws-kubernetes/variables.gen.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ variable "crdb_hostname_suffix" {
6565
EOT
6666
}
6767

68+
variable "datastore_type" {
69+
type = string
70+
description = <<-EOT
71+
Type of datastore used
72+
73+
Supported technologies: cockroachdb, yugabyte
74+
EOT
75+
76+
validation {
77+
condition = contains(["cockroachdb", "yugabyte"], var.datastore_type)
78+
error_message = "Supported technologies: cockroachdb, yugabyte"
79+
}
80+
81+
default = "cockroachdb"
82+
}
83+
84+
6885
variable "cluster_name" {
6986
type = string
7087
description = <<-EOT

deploy/infrastructure/dependencies/terraform-commons-dss/helm.tf

Lines changed: 129 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ locals {
66

77
resource "local_file" "helm_chart_values" {
88
filename = "${local.workspace_location}/helm_values.yml"
9-
content = yamlencode({
9+
content = var.datastore_type == "cockroachdb" ? yamlencode({
1010
cockroachdb = {
1111
image = {
1212
tag = var.crdb_image_tag
@@ -69,5 +69,132 @@ resource "local_file" "helm_chart_values" {
6969
global = {
7070
cloudProvider = var.kubernetes_cloud_provider_name
7171
}
72-
})
72+
}) : yamlencode({
73+
cockroachdb = {
74+
enabled = false
75+
image = {
76+
tag = "dummy"
77+
}
78+
fullnameOverride = "dummy"
79+
conf = {
80+
cluster-name = "dummy"
81+
locality = "dummy"
82+
}
83+
statefulset = {}
84+
}
85+
yugabyte = {
86+
enabled = true
87+
88+
resource = var.yugabyte_light_resources ? {
89+
master = {
90+
requests = {
91+
cpu = "0.1"
92+
memory = "0.5G"
93+
}
94+
}
95+
tserver = {
96+
requests = {
97+
cpu = "0.1"
98+
memory = "0.5G"
99+
}
100+
}
101+
} : {}
102+
enableLoadBalancer = false
103+
104+
master = {
105+
extraEnv = [{
106+
name = "HOSTNAMENO"
107+
valueFrom = {
108+
fieldRef = {
109+
fieldPath = "metadata.labels['apps.kubernetes.io/pod-index']"
110+
}
111+
}
112+
}]
113+
serverBroadcastAddress: "$${HOSTNAMENO}.master.${var.crdb_hostname_suffix}"
114+
rpcBindAddress: "$${HOSTNAMENO}.master.${var.crdb_hostname_suffix}"
115+
advanced = {
116+
preCommands: "sed -E \"/\\.svc\\.cluster\\.local/ s/^([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)([[:space:]]+)/\\1 $(echo \"$${HOSTNAMENO}.master.${var.crdb_hostname_suffix}\" | sed 's/[\\/&]/\\\\&/g')\\2/\" /etc/hosts > /tmp/newhosts && /bin/cp /tmp/newhosts /etc/hosts && \\"
117+
}
118+
}
119+
120+
tserver = {
121+
extraEnv = [{
122+
name = "HOSTNAMENO"
123+
valueFrom = {
124+
fieldRef = {
125+
fieldPath = "metadata.labels['apps.kubernetes.io/pod-index']"
126+
}
127+
}
128+
}]
129+
serverBroadcastAddress: "$${HOSTNAMENO}.tserver.${var.crdb_hostname_suffix}"
130+
rpcBindAddress: "$${HOSTNAMENO}.tserver.${var.crdb_hostname_suffix}"
131+
advanced = {
132+
preCommands: "sed -E \"/\\.svc\\.cluster\\.local/ s/^([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)([[:space:]]+)/\\1 $(echo \"$${HOSTNAMENO}.tserver.${var.crdb_hostname_suffix}\" | sed 's/[\\/&]/\\\\&/g')\\2/\" /etc/hosts > /tmp/newhosts && /bin/cp /tmp/newhosts /etc/hosts && \\"
133+
}
134+
}
135+
136+
gflags = {
137+
master = {
138+
placement_cloud: var.yugabyte_cloud
139+
placement_region: var.yugabyte_region
140+
placement_zone: var.yugabyte_zone
141+
use_private_ip: "zone"
142+
}
143+
tserver = {
144+
placement_cloud: var.yugabyte_cloud
145+
placement_region: var.yugabyte_region
146+
placement_zone: var.yugabyte_zone
147+
use_private_ip: "zone"
148+
}
149+
}
150+
151+
masterAddresses = join(",", ["0.master.${var.crdb_hostname_suffix},1.master.${var.crdb_hostname_suffix},2.master.${var.crdb_hostname_suffix}", join(",", var.yugabyte_external_nodes)])
152+
}
153+
154+
loadBalancers = {
155+
cockroachdbNodes = []
156+
157+
yugabyteMasterNodes = [
158+
for ip in var.yugabyte_internal_masters_nodes[*].ip :
159+
{
160+
ip = ip
161+
subnet = var.workload_subnet
162+
}
163+
]
164+
165+
yugabyteTserverNodes = [
166+
for ip in var.yugabyte_internal_tservers_nodes[*].ip :
167+
{
168+
ip = ip
169+
subnet = var.workload_subnet
170+
}
171+
]
172+
173+
dssGateway = {
174+
ip = var.ip_gateway
175+
subnet = var.workload_subnet
176+
certName = var.gateway_cert_name
177+
sslPolicy = var.ssl_policy
178+
}
179+
}
180+
181+
dss = {
182+
image = var.image
183+
184+
conf = {
185+
pubKeys = [
186+
"/test-certs/auth2.pem"
187+
]
188+
jwksEndpoint = var.authorization.jwks != null ? var.authorization.jwks.endpoint : ""
189+
jwksKeyIds = var.authorization.jwks != null ? [var.authorization.jwks.key_id] : []
190+
hostname = var.app_hostname
191+
enableScd = var.enable_scd
192+
}
193+
}
194+
195+
global = {
196+
cloudProvider = var.kubernetes_cloud_provider_name
197+
}
198+
})
199+
73200
}

deploy/infrastructure/dependencies/terraform-commons-dss/scripts.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
resource "local_file" "make_certs" {
3+
count = var.datastore_type == "cockroachdb" ? 1 : 0
34
content = templatefile("${path.module}/templates/make-certs.sh.tmp", {
45
cluster_context = var.kubernetes_context_name
56
namespace = var.kubernetes_namespace
@@ -10,13 +11,24 @@ resource "local_file" "make_certs" {
1011
}
1112

1213
resource "local_file" "apply_certs" {
14+
count = var.datastore_type == "cockroachdb" ? 1 : 0
1315
content = templatefile("${path.module}/templates/apply-certs.sh.tmp", {
1416
cluster_context = var.kubernetes_context_name
1517
namespace = var.kubernetes_namespace
1618
})
1719
filename = "${local.workspace_location}/apply-certs.sh"
1820
}
1921

22+
resource "local_file" "dss_certs" {
23+
count = var.datastore_type == "yugabyte" ? 1 : 0
24+
content = templatefile("${path.module}/templates/dss-certs.sh.tmp", {
25+
cluster_context = var.kubernetes_context_name
26+
namespace = var.kubernetes_namespace
27+
crdb_hostname_suffix = var.crdb_hostname_suffix
28+
})
29+
filename = "${local.workspace_location}/dss-certs.sh"
30+
}
31+
2032
resource "local_file" "get_credentials" {
2133
content = templatefile("${path.module}/templates/get-credentials.sh.tmp", {
2234
get_credentials_cmd = var.kubernetes_get_credentials_cmd
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
# This file was automatically generated by terraform-commons-dss.
4+
# Do not edit it directly.
5+
6+
set -eo pipefail
7+
8+
OS=$(uname)
9+
if [[ "$OS" == "Darwin" ]]; then
10+
# OSX uses BSD readlink
11+
BASEDIR="$(dirname "$0")"
12+
else
13+
BASEDIR=$(readlink -e "$(dirname "$0")")
14+
fi
15+
cd "$BASEDIR/../../../deploy/operations/certificates-management/" || exit 1
16+
17+
./dss-certs.py --name ${cluster_context} --organization default_orga --cluster-context ${cluster_context} --nodes-public-address "<ID>.<TYPE>.${crdb_hostname_suffix}" --namespace ${namespace} "$@"

deploy/infrastructure/dependencies/terraform-commons-dss/variables.gen.tf

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ variable "crdb_hostname_suffix" {
2222
EOT
2323
}
2424

25+
variable "datastore_type" {
26+
type = string
27+
description = <<-EOT
28+
Type of datastore used
29+
30+
Supported technologies: cockroachdb, yugabyte
31+
EOT
32+
33+
validation {
34+
condition = contains(["cockroachdb", "yugabyte"], var.datastore_type)
35+
error_message = "Supported technologies: cockroachdb, yugabyte"
36+
}
37+
38+
default = "cockroachdb"
39+
}
40+
41+
2542
variable "image" {
2643
type = string
2744
description = <<-EOT
@@ -225,3 +242,62 @@ variable "kubernetes_namespace" {
225242
}
226243
}
227244

245+
variable "yugabyte_cloud" {
246+
type = string
247+
description = <<-EOT
248+
Cloud of yugabyte instances, used for partionning.
249+
250+
Should be set to dss unless you're doing advanced partitionning.
251+
EOT
252+
253+
default = "dss"
254+
}
255+
256+
257+
variable "yugabyte_region" {
258+
type = string
259+
description = <<-EOT
260+
Region of yugabyte instances, used for partionning.
261+
262+
Should be different from others USS in a cluster.
263+
EOT
264+
265+
default = "uss-1"
266+
}
267+
268+
269+
variable "yugabyte_zone" {
270+
type = string
271+
description = <<-EOT
272+
Zone of yugabyte instances, used for partionning.
273+
274+
Should be set to zone unless you're doing advanced partitionning.
275+
EOT
276+
277+
default = "zone"
278+
}
279+
280+
281+
variable "yugabyte_light_resources" {
282+
type = bool
283+
description = <<-EOT
284+
Enable light resources reservation for yugabyte instances.
285+
286+
Useful for a dev cluster when you don't want to overload your kubernetes cluster.
287+
EOT
288+
289+
default = false
290+
}
291+
292+
293+
variable "yugabyte_external_nodes" {
294+
type = list(string)
295+
description = <<-EOT
296+
Fully-qualified domain name of existing yugabyte master nodes outside of the cluster if you are joining an existing pool.
297+
Example: ["0.master.db.dss.example.com", "1.master.db.dss.example.com", "2.master.db.dss.example.com"]
298+
EOT
299+
default = []
300+
}
301+
302+
303+

deploy/infrastructure/dependencies/terraform-commons-dss/variables_internal.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ variable "crdb_internal_nodes" {
2929
description = "List of the IP addresses and related dns for the Cockroach DB nodes"
3030
}
3131

32+
variable "yugabyte_internal_masters_nodes" {
33+
type = list(object({
34+
dns = string
35+
ip = string
36+
}))
37+
description = "List of the IP addresses and related dns for the Yugabyte DB master nodes"
38+
}
39+
40+
variable "yugabyte_internal_tservers_nodes" {
41+
type = list(object({
42+
dns = string
43+
ip = string
44+
}))
45+
description = "List of the IP addresses and related dns for the Yugabyte DB tserver nodes"
46+
}
47+
3248
variable "ip_gateway" {
3349
type = string
3450
description = "IP of the gateway used by the DSS service"

deploy/infrastructure/dependencies/terraform-google-kubernetes/cluster.tf

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,33 @@ resource "google_compute_global_address" "ip_gateway" {
5252

5353
# Static IP addresses for CRDB instances
5454
resource "google_compute_address" "ip_crdb" {
55-
count = var.node_count
55+
count = var.datastore_type == "cockroachdb" ? var.node_count : 0
5656
name = format("%s-ip-crdb%v", var.cluster_name, count.index)
5757
region = local.region
5858

5959
# Current google terraform provider doesn't allow tags or labels. Description is used to preserve mapping between ips and hostnames.
6060
description = format("%s.%s", count.index, var.crdb_hostname_suffix)
6161
}
6262

63+
# Static IP addresses for yugabyte instances
64+
resource "google_compute_address" "ip_yugabyte_masters" {
65+
count = var.datastore_type == "yugabyte" ? var.node_count : 0
66+
name = format("%s-ip-yugabyte-master%v", var.cluster_name, count.index)
67+
region = local.region
68+
69+
# Current google terraform provider doesn't allow tags or labels. Description is used to preserve mapping between ips and hostnames.
70+
description = format("%s.master.%s", count.index, var.crdb_hostname_suffix)
71+
}
72+
73+
resource "google_compute_address" "ip_yugabyte_tservers" {
74+
count = var.datastore_type == "yugabyte" ? var.node_count : 0
75+
name = format("%s-ip-yugabyte-tserver%v", var.cluster_name, count.index)
76+
region = local.region
77+
78+
# Current google terraform provider doesn't allow tags or labels. Description is used to preserve mapping between ips and hostnames.
79+
description = format("%s.tserver.%s", count.index, var.crdb_hostname_suffix)
80+
}
81+
6382
locals {
6483
kubectl_cluster_context_name = format("gke_%s_%s_%s", google_container_cluster.kubernetes_cluster.project, google_container_cluster.kubernetes_cluster.location, google_container_cluster.kubernetes_cluster.name)
6584
}

deploy/infrastructure/dependencies/terraform-google-kubernetes/dns.tf

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,31 @@ resource "google_dns_record_set" "gateway" {
1616
}
1717

1818
resource "google_dns_record_set" "crdb" {
19-
count = var.google_dns_managed_zone_name == "" ? 0 : var.node_count
19+
count = var.google_dns_managed_zone_name == "" || var.datastore_type != "cockroachdb" ? 0 : var.node_count
2020
name = "${google_compute_address.ip_crdb[count.index].description}." # description contains the expected hostname
2121
type = "A"
2222
ttl = 300
2323

2424
managed_zone = data.google_dns_managed_zone.default[0].name
2525
rrdatas = [google_compute_address.ip_crdb[count.index].address]
26-
}
26+
}
27+
28+
resource "google_dns_record_set" "yugabyte_masters" {
29+
count = var.google_dns_managed_zone_name == "" || var.datastore_type != "yugabyte" ? 0 : var.node_count
30+
name = "${google_compute_address.ip_yugabyte_masters[count.index].description}." # description contains the expected hostname
31+
type = "A"
32+
ttl = 300
33+
34+
managed_zone = data.google_dns_managed_zone.default[0].name
35+
rrdatas = [google_compute_address.ip_yugabyte_masters[count.index].address]
36+
}
37+
38+
resource "google_dns_record_set" "yugabyte_tserver" {
39+
count = var.google_dns_managed_zone_name == "" || var.datastore_type != "yugabyte" ? 0 : var.node_count
40+
name = "${google_compute_address.ip_yugabyte_tservers[count.index].description}." # description contains the expected hostname
41+
type = "A"
42+
ttl = 300
43+
44+
managed_zone = data.google_dns_managed_zone.default[0].name
45+
rrdatas = [google_compute_address.ip_yugabyte_tservers[count.index].address]
46+
}

0 commit comments

Comments
 (0)