Skip to content

Commit 35dc1df

Browse files
committed
Yugabyte in GCP
Co-authored-by: Michael Barroco <michael@orbitalize.com>
1 parent 43fce09 commit 35dc1df

File tree

35 files changed

+1029
-73
lines changed

35 files changed

+1029
-73
lines changed

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

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

68-
variable "cluster_name" {
68+
variable "datastore_type" {
6969
type = string
7070
description = <<-EOT
71-
Name of the kubernetes cluster that will host this DSS instance (should generally describe the DSS instance being hosted)
71+
Type of datastore used
7272
73-
Example: `dss-che-1`
73+
Supported technologies: cockroachdb, yugabyte
7474
EOT
75+
76+
validation {
77+
condition = contains(["cockroachdb", "yugabyte"], var.datastore_type)
78+
error_message = "Supported technologies: cockroachdb, yugabyte"
79+
}
80+
81+
default = "cockroachdb"
7582
}
7683

84+
7785
variable "node_count" {
7886
type = number
7987
description = <<-EOT
@@ -84,12 +92,21 @@ variable "node_count" {
8492
EOT
8593

8694
validation {
87-
condition = contains([1, 3], var.node_count)
88-
error_message = "Currently, only 1 node or 3 nodes deployments are supported."
95+
condition = (var.datastore_type == "cockroach" && contains([1, 3], var.node_count)) || (var.datastore_type == "yugabyte" && var.node_count > 0)
96+
error_message = "Currently, only 1 node or 3 nodes deployments are supported for CockroachDB. If you use Yugabyte, you need to have at least one node."
8997
}
9098
}
9199

92100

101+
variable "cluster_name" {
102+
type = string
103+
description = <<-EOT
104+
Name of the kubernetes cluster that will host this DSS instance (should generally describe the DSS instance being hosted)
105+
106+
Example: `dss-che-1`
107+
EOT
108+
}
109+
93110
variable "kubernetes_version" {
94111
type = string
95112
description = <<-EOT

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

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ locals {
22
# Tanka defines itself the variable below. For helm, since we are using the official helm CRDB chart,
33
# the following variable has to be provided here.
44
helm_crdb_statefulset_name = "dss-cockroachdb"
5+
6+
# This pre command is used bellow in yugabyte deployements to make the local ip pointing to the public hostname we want to use, until https://github.com/yugabyte/yugabyte-db/issues/27367 is fixed
7+
yugabyte_precommand_prefix = "sed -E \"/\\.svc\\.cluster\\.local/ s/^([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)([[:space:]]+)/\\1 $(echo \"$${HOSTNAMENO}."
8+
yugabyte_precommand_sufix = ".${var.crdb_hostname_suffix}\" | sed 's/[\\/&]/\\\\&/g')\\2/\" /etc/hosts > /tmp/newhosts && /bin/cp /tmp/newhosts /etc/hosts && \\"
59
}
610

711
resource "local_file" "helm_chart_values" {
812
filename = "${local.workspace_location}/helm_values.yml"
9-
content = yamlencode({
13+
content = var.datastore_type == "cockroachdb" ? yamlencode({
1014
cockroachdb = {
1115
image = {
1216
tag = var.crdb_image_tag
@@ -66,8 +70,134 @@ resource "local_file" "helm_chart_values" {
6670
}
6771
}
6872

73+
global = {
74+
cloudProvider = var.kubernetes_cloud_provider_name
75+
}
76+
}) : yamlencode({
77+
cockroachdb = {
78+
enabled = false
79+
}
80+
yugabyte = {
81+
enabled = true
82+
83+
resource = var.yugabyte_light_resources ? {
84+
master = {
85+
requests = {
86+
cpu = "0.1"
87+
memory = "0.5G"
88+
}
89+
}
90+
tserver = {
91+
requests = {
92+
cpu = "0.1"
93+
memory = "0.5G"
94+
}
95+
}
96+
} : {}
97+
enableLoadBalancer = false
98+
99+
replicas = {
100+
master = var.node_count
101+
tserver = var.node_count
102+
totalMasters = length(var.yugabyte_external_nodes) + var.node_count
103+
}
104+
105+
master = {
106+
extraEnv = [{
107+
name = "HOSTNAMENO"
108+
valueFrom = {
109+
fieldRef = {
110+
fieldPath = "metadata.labels['apps.kubernetes.io/pod-index']"
111+
}
112+
}
113+
}]
114+
serverBroadcastAddress : "$${HOSTNAMENO}.master.${var.crdb_hostname_suffix}"
115+
rpcBindAddress : "$${HOSTNAMENO}.master.${var.crdb_hostname_suffix}"
116+
advanced = {
117+
preCommands : "${local.yugabyte_precommand_prefix}master${local.yugabyte_precommand_sufix}"
118+
}
119+
}
120+
121+
tserver = {
122+
extraEnv = [{
123+
name = "HOSTNAMENO"
124+
valueFrom = {
125+
fieldRef = {
126+
fieldPath = "metadata.labels['apps.kubernetes.io/pod-index']"
127+
}
128+
}
129+
}]
130+
serverBroadcastAddress : "$${HOSTNAMENO}.tserver.${var.crdb_hostname_suffix}"
131+
rpcBindAddress : "$${HOSTNAMENO}.tserver.${var.crdb_hostname_suffix}"
132+
advanced = {
133+
preCommands : "${local.yugabyte_precommand_prefix}tserver${local.yugabyte_precommand_sufix}"
134+
}
135+
}
136+
137+
gflags = {
138+
master = {
139+
placement_cloud : var.yugabyte_cloud
140+
placement_region : var.yugabyte_region
141+
placement_zone : var.yugabyte_zone
142+
use_private_ip : "zone"
143+
}
144+
tserver = {
145+
placement_cloud : var.yugabyte_cloud
146+
placement_region : var.yugabyte_region
147+
placement_zone : var.yugabyte_zone
148+
use_private_ip : "zone"
149+
}
150+
}
151+
152+
masterAddresses = join(",", concat([
153+
for i in range(var.node_count) : format("%s.master.${var.crdb_hostname_suffix}", i)
154+
], var.yugabyte_external_nodes))
155+
}
156+
157+
loadBalancers = {
158+
cockroachdbNodes = []
159+
160+
yugabyteMasterNodes = [
161+
for ip in var.yugabyte_internal_masters_nodes[*].ip :
162+
{
163+
ip = ip
164+
subnet = var.workload_subnet
165+
}
166+
]
167+
168+
yugabyteTserverNodes = [
169+
for ip in var.yugabyte_internal_tservers_nodes[*].ip :
170+
{
171+
ip = ip
172+
subnet = var.workload_subnet
173+
}
174+
]
175+
176+
dssGateway = {
177+
ip = var.ip_gateway
178+
subnet = var.workload_subnet
179+
certName = var.gateway_cert_name
180+
sslPolicy = var.ssl_policy
181+
}
182+
}
183+
184+
dss = {
185+
image = var.image
186+
187+
conf = {
188+
pubKeys = [
189+
"/test-certs/auth2.pem"
190+
]
191+
jwksEndpoint = var.authorization.jwks != null ? var.authorization.jwks.endpoint : ""
192+
jwksKeyIds = var.authorization.jwks != null ? [var.authorization.jwks.key_id] : []
193+
hostname = var.app_hostname
194+
enableScd = var.enable_scd
195+
}
196+
}
197+
69198
global = {
70199
cloudProvider = var.kubernetes_cloud_provider_name
71200
}
72201
})
202+
73203
}

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

Lines changed: 13 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,25 @@ 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+
node_count = var.node_count
29+
})
30+
filename = "${local.workspace_location}/dss-certs.sh"
31+
}
32+
2033
resource "local_file" "get_credentials" {
2134
content = templatefile("${path.module}/templates/get-credentials.sh.tmp", {
2235
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} --nodes-count ${node_count} "$@"

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,39 @@ 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+
42+
variable "node_count" {
43+
type = number
44+
description = <<-EOT
45+
Number of Kubernetes nodes which should correspond to the desired CockroachDB nodes.
46+
Currently, only single node or three nodes deployments are supported.
47+
48+
Example: `3`
49+
EOT
50+
51+
validation {
52+
condition = (var.datastore_type == "cockroach" && contains([1, 3], var.node_count)) || (var.datastore_type == "yugabyte" && var.node_count > 0)
53+
error_message = "Currently, only 1 node or 3 nodes deployments are supported for CockroachDB. If you use Yugabyte, you need to have at least one node."
54+
}
55+
}
56+
57+
2558
variable "image" {
2659
type = string
2760
description = <<-EOT
@@ -225,3 +258,62 @@ variable "kubernetes_namespace" {
225258
}
226259
}
227260

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

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"

0 commit comments

Comments
 (0)