From b9d40b6ab3c2b237ec20a8c090da3455ec53b0be Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Fri, 21 Jun 2024 11:02:55 -0400 Subject: [PATCH] feat: gcp cloud provider Support GCP as a cloud provider. To ensure backwards compatibility, the default is configured for AWS. Signed-off-by: Chris Gianelloni --- bootstrap/main.tf | 10 ++++---- bootstrap/proxy/main.tf | 4 ++++ bootstrap/proxy/service.tf | 35 ++++++++++++++++++++++++++- bootstrap/relay/main.tf | 49 +++++++++++++++++++++++++++++++++++++- bootstrap/variables.tf | 5 ++++ 5 files changed, 97 insertions(+), 6 deletions(-) diff --git a/bootstrap/main.tf b/bootstrap/main.tf index 912d3ea..b43df61 100644 --- a/bootstrap/main.tf +++ b/bootstrap/main.tf @@ -29,6 +29,7 @@ module "node_v1_proxy_blue" { resources = var.proxy_resources instances_namespace = var.proxy_blue_instances_namespace healthcheck_port = var.proxy_blue_healthcheck_port + cloud_provider = var.cloud_provider environment = "blue" name = "proxy-blue" } @@ -44,6 +45,7 @@ module "node_v1_proxy_green" { resources = var.proxy_resources instances_namespace = var.proxy_green_instances_namespace healthcheck_port = var.proxy_green_healthcheck_port + cloud_provider = var.cloud_provider environment = "green" name = "proxy-green" } @@ -84,7 +86,6 @@ module "instances" { is_relay = coalesce(each.value.is_relay, false) } - module "custom_configs" { depends_on = [kubernetes_namespace.namespace] source = "./configs" @@ -111,7 +112,8 @@ module "services" { } module "node_relay" { - depends_on = [kubernetes_namespace.namespace] - source = "./relay" - namespace = var.namespace + depends_on = [kubernetes_namespace.namespace] + source = "./relay" + namespace = var.namespace + cloud_provider = var.cloud_provider } diff --git a/bootstrap/proxy/main.tf b/bootstrap/proxy/main.tf index ab37c9d..77dd50d 100644 --- a/bootstrap/proxy/main.tf +++ b/bootstrap/proxy/main.tf @@ -85,3 +85,7 @@ variable "dns_zone" { variable "healthcheck_port" { type = number } + +variable "cloud_provider" { + type = string +} diff --git a/bootstrap/proxy/service.tf b/bootstrap/proxy/service.tf index 9d3e8dc..b36f76c 100644 --- a/bootstrap/proxy/service.tf +++ b/bootstrap/proxy/service.tf @@ -1,4 +1,5 @@ -resource "kubernetes_service_v1" "proxy_service" { +resource "kubernetes_service_v1" "proxy_service_aws" { + for_each = toset([for n in toset(["loadbalancer"]) : n if var.cloud_provider == "aws"]) metadata { name = local.name namespace = var.namespace @@ -33,3 +34,35 @@ resource "kubernetes_service_v1" "proxy_service" { type = "LoadBalancer" } } + +resource "kubernetes_service_v1" "proxy_service_gcp" { + for_each = toset([for n in toset(["loadbalancer"]) : n if var.cloud_provider == "gcp"]) + metadata { + name = local.name + namespace = var.namespace + annotations = { + "cloud.google.com/l4-rbs" : "enabled" + } + } + + spec { + external_traffic_policy = "Local" + selector = local.proxy_labels + + port { + name = "proxy" + port = 9443 + target_port = local.proxy_port + protocol = "TCP" + } + + port { + name = "health" + port = 80 + target_port = local.prometheus_port + protocol = "TCP" + } + + type = "LoadBalancer" + } +} diff --git a/bootstrap/relay/main.tf b/bootstrap/relay/main.tf index 2befdc0..8589949 100644 --- a/bootstrap/relay/main.tf +++ b/bootstrap/relay/main.tf @@ -2,7 +2,13 @@ variable "namespace" { description = "the namespace where the resources will be created" } -resource "kubernetes_service_v1" "node-relay-n2n" { +variable "cloud_provider" { + type = string + default = "aws" +} + +resource "kubernetes_service_v1" "node-relay-n2n-aws" { + for_each = toset([for n in toset(["loadbalancer"]) : n if var.cloud_provider == "aws"]) metadata { name = "node-relay-n2n" namespace = var.namespace @@ -43,3 +49,44 @@ resource "kubernetes_service_v1" "node-relay-n2n" { } } } + +resource "kubernetes_service_v1" "node-relay-n2n-gcp" { + for_each = toset([for n in toset(["loadbalancer"]) : n if var.cloud_provider == "gcp"]) + metadata { + name = "node-relay-n2n" + namespace = var.namespace + annotations = { + "cloud.google.com/l4-rbs" : "enabled" + } + } + + spec { + type = "LoadBalancer" + external_traffic_policy = "Local" + + selector = { + "role" = "node" + } + + port { + name = "mainnet" + protocol = "TCP" + port = 3000 + target_port = "n2n-mainnet" + } + + port { + name = "preprod" + protocol = "TCP" + port = 3001 + target_port = "n2n-preprod" + } + + port { + name = "preview" + protocol = "TCP" + port = 3002 + target_port = "n2n-preview" + } + } +} diff --git a/bootstrap/variables.tf b/bootstrap/variables.tf index 90574d5..914bffb 100644 --- a/bootstrap/variables.tf +++ b/bootstrap/variables.tf @@ -1,3 +1,8 @@ +variable "cloud_provider" { + type = string + default = "aws" +} + variable "namespace" { type = string }