Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Cockroach DB multi-region deployments in terraform and tanka configs #1131

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ a PR to that effect would be greatly appreciated.
recommend "<ORG_NAME>_<CLUSTER_NAME>", and the `=` character is not
allowed. However, any unique (among all other participating DSS
instances) value is acceptable.

1. `VAR_CRDB_REGION`:Region of your DSS instance. Regions are a high-level abstraction
of a geographic region, and are meant to correspond directly to the region terminology
used by cloud providers. Each region is broken into multiple zones. Regions are used
to achieve varying survival goals in the face of database failure. More info at
https://www.cockroachlabs.com/docs/stable/multiregion-overview.

1. `VAR_CRDB_NODE_IPn`: IP address (**numeric**) of nth CRDB node (add more
entries if you have more than 3 CRDB nodes). Example: `1.1.1.1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ locals {
# Tanka defines itself the variable below. For helm, since we are using the official helm CRDB chart,
# the following variable has to be provided here.
helm_crdb_statefulset_name = "dss-cockroachdb"
locality_args = var.crdb_region != "" ? "region=${var.crdb_region},zone=${var.crdb_locality}" : "zone=${var.crdb_locality}"
}

resource "local_file" "helm_chart_values" {
Expand All @@ -17,13 +18,13 @@ resource "local_file" "helm_chart_values" {
join = var.crdb_external_nodes
cluster-name = var.crdb_cluster_name
single-node = false # Always false. Even with 1 replica, we would expect to keep the ability to pool it with another cluster.
locality = "zone=${var.crdb_locality}"
locality = locals.locality_args
}

statefulset = {
replicas = length(var.crdb_internal_nodes)
args = [
"--locality-advertise-addr=zone=${var.crdb_locality}@$(hostname -f)",
"--locality-advertise-addr=${locals.locality_args}@$(hostname -f)",
"--advertise-addr=$${HOSTNAME##*-}.${var.crdb_hostname_suffix}"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resource "local_file" "tanka_config_main" {
VAR_ENABLE_SCD = var.enable_scd
VAR_CRDB_HOSTNAME_SUFFIX = var.crdb_hostname_suffix
VAR_CRDB_LOCALITY = var.crdb_locality
VAR_CRDB_REGION = var.crdb_region
VAR_CRDB_NODE_IPS = join(",", [for i in var.crdb_internal_nodes[*].ip : "'${i}'"])
VAR_INGRESS_NAME = var.ip_gateway
VAR_CRDB_EXTERNAL_NODES = join(",", [for a in var.crdb_external_nodes : "'${a}'"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local metadata = metadataBase {
image: '${VAR_CRDB_DOCKER_IMAGE_NAME}',
hostnameSuffix: '${VAR_CRDB_HOSTNAME_SUFFIX}',
locality: '${VAR_CRDB_LOCALITY}',
region: '${VAR_CRDB_REGION}',
nodeIPs: [${VAR_CRDB_NODE_IPS}],
shouldInit: ${VAR_SHOULD_INIT},
JoinExisting: [${VAR_CRDB_EXTERNAL_NODES}],
Expand Down
1 change: 1 addition & 0 deletions deploy/infrastructure/modules/terraform-aws-dss/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module "terraform-commons-dss" {
should_init = var.should_init
authorization = var.authorization
crdb_locality = var.crdb_locality
crdb_region = var.crdb_region
crdb_external_nodes = var.crdb_external_nodes
crdb_internal_nodes = module.terraform-aws-kubernetes.crdb_nodes
ip_gateway = module.terraform-aws-kubernetes.ip_gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ should_init = true
crdb_image_tag = "v24.1.3"
crdb_cluster_name = "interuss_example"
crdb_locality = "interuss_dss-aws-ew1"
crdb_region = "eu-west-1"
crdb_external_nodes = []
1 change: 1 addition & 0 deletions deploy/infrastructure/modules/terraform-google-dss/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module "terraform-commons-dss" {
should_init = var.should_init
authorization = var.authorization
crdb_locality = var.crdb_locality
crdb_region = var.crdb_region
image_pull_secret = var.image_pull_secret
crdb_external_nodes = var.crdb_external_nodes
kubernetes_api_endpoint = module.terraform-google-kubernetes.kubernetes_api_endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ should_init = true
crdb_image_tag = "v24.1.3"
crdb_cluster_name = "interuss_example"
crdb_locality = "interuss_dss-dev-w6a"
crdb_region = "europe-west6-a"
crdb_external_nodes = []
14 changes: 14 additions & 0 deletions deploy/infrastructure/utils/definitions/crdb_region.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "crdb_region" {
type = string
description = <<-EOT
Region of your DSS instance. Regions are a high-level abstraction of a geographic region,
and are meant to correspond directly to the region terminology used by cloud providers.
Each region is broken into multiple zones. Regions are used to achieve varying survival
goals in the face of database failure. More info at
https://www.cockroachlabs.com/docs/stable/multiregion-overview.

Example: <us-east1>
EOT

default = ""
}
1 change: 1 addition & 0 deletions deploy/infrastructure/utils/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"crdb_image_tag",
"crdb_cluster_name",
"crdb_locality",
"crdb_region",
"crdb_external_nodes",
"kubernetes_namespace",
]
Expand Down
1 change: 1 addition & 0 deletions deploy/operations/ci/aws-1/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module "terraform-aws-dss" {
crdb_cluster_name = var.crdb_cluster_name
crdb_hostname_suffix = var.crdb_hostname_suffix
crdb_locality = var.crdb_locality
crdb_region = var.crdb_region
crdb_external_nodes = var.crdb_external_nodes
image = var.image
kubernetes_version = var.kubernetes_version
Expand Down
1 change: 1 addition & 0 deletions deploy/operations/ci/aws-1/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ should_init = true
crdb_image_tag = "v24.1.3"
crdb_cluster_name = "interuss-ci"
crdb_locality = "interuss_dss-ci-aws-ue1"
crdb_region = "us-east-1"
crdb_external_nodes = []

aws_iam_permissions_boundary = "arn:aws:iam::301042233698:policy/GithubCIPermissionBoundaries20231130225039606500000001"
Expand Down
2 changes: 1 addition & 1 deletion deploy/services/tanka/cockroachdb.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ local volumes = import 'volumes.libsonnet';
join: std.join(',', ['cockroachdb-0.cockroachdb'] +
if metadata.single_cluster then [] else metadata.cockroach.JoinExisting),
logtostderr: true,
locality: 'zone=' + metadata.cockroach.locality,
locality: if std.objectHas(metadata.cockroach, 'region') then std.join(',', ['region=' + metadata.cockroach.region, 'zone=' + metadata.cockroach.locality]) else 'zone=' + metadata.cockroach.locality,
'locality-advertise-addr': 'zone=' + metadata.cockroach.locality + '@$(hostname -f)',
'http-addr': '0.0.0.0',
cache: '25%',
Expand Down
Loading