Skip to content

Commit

Permalink
Refactor shards-related variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tschneider-aneo committed Sep 2, 2024
1 parent 3ab0cde commit 7a399a0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
14 changes: 7 additions & 7 deletions storage/onpremise/mongodb-sharded/example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module "sharded_mongodb" {
image_pull_secrets = [""]
node_selector = {}
registry = "docker.io"
replicas = 1
tag = "7.0.14-debian-12-r0"
}

sharding = {
shards = {
quantity = 1
replicas = 1
}

Expand Down Expand Up @@ -79,11 +79,11 @@ module "sharded_mongodb" {
}
}

router = {
requests = {
"cpu" = "400m"
"memory" = "700Mi"
}
}
# router = {
# requests = {
# "cpu" = "400m"
# "memory" = "700Mi"
# }
# }
}
}
12 changes: 6 additions & 6 deletions storage/onpremise/mongodb-sharded/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resource "helm_release" "mongodb" {
values = [
yamlencode({
"commonLabels" = var.labels
"shards" = var.sharding.shards
"shards" = var.sharding.shards.quantity

"image" = {
"registry" = var.mongodb.registry
Expand Down Expand Up @@ -75,7 +75,7 @@ resource "helm_release" "mongodb" {
] : []

"podLabels" = var.labels
"resources" = try(var.resources.configsvr, {})
"resources" = var.resources.configsvr

"persistentVolumeClaimRetentionPolicy" = {
"enabled" = true
Expand All @@ -96,12 +96,12 @@ resource "helm_release" "mongodb" {
] : []

"podLabels" = var.labels
"resources" = try(var.resources.router, null)
"resources" = var.resources.router
}

"shardsvr" = {
"dataNode" = {
"replicaCount" = var.mongodb.replicas
"replicaCount" = var.sharding.shards.replicas
"mongodbExtraFlags" = local.mongodb_extra_flags
"nodeSelector" = local.shards_node_selector

Expand All @@ -113,7 +113,7 @@ resource "helm_release" "mongodb" {
] : []

"podLabels" = var.labels
"resources" = try(var.resources.shards, null)
"resources" = var.resources.shards
}

"persistentVolumeClaimRetentionPolicy" = {
Expand All @@ -140,7 +140,7 @@ resource "helm_release" "mongodb" {
}]

"podLabels" = var.labels
"resources" = try(var.resources.arbiter, null)
"resources" = var.resources.arbiter
}

# "metrics" = {
Expand Down
2 changes: 1 addition & 1 deletion storage/onpremise/mongodb-sharded/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ output "url" {

output "number_of_replicas" {
description = "Number of replicas for each shard"
value = var.mongodb.replicas
value = var.sharding.shards.replicas
}

output "number_of_shards" {
Expand Down
5 changes: 3 additions & 2 deletions storage/onpremise/mongodb-sharded/secrets.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
data "kubernetes_secret" "mongodb_credentials" {
metadata {
name = "${helm_release.mongodb.name}"
name = helm_release.mongodb.name
namespace = var.namespace
}
}
Expand Down Expand Up @@ -41,6 +41,7 @@ resource "kubernetes_secret" "mongodb" {
host = local.mongodb_dns
port = var.mongodb.service_port
url = local.mongodb_url
number_of_replicas = var.mongodb.replicas
number_of_replicas = var.sharding.shards.replicas
number_of_shards = var.sharding.shards.quantity
}
}
32 changes: 13 additions & 19 deletions storage/onpremise/mongodb-sharded/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ variable "mongodb" {
image_pull_secrets = optional(any, [""]) # can be a string or a list of strings
node_selector = optional(map(string), {})
registry = optional(string)
replicas = optional(number, 2)
service_port = optional(number, 27017)
tag = string
})
Expand All @@ -47,9 +46,13 @@ variable "sharding" {
description = "Parameters specific to the sharded architecture"
type = object({
shards = optional(object({
replicas = optional(number, 2)
quantity = optional(number, 2)
replicas = optional(number, 1)
node_selector = optional(map(string))
}))
}), {
quantity = 2
replicas = 1
})

arbiter = optional(object({
node_selector = optional(map(string))
Expand All @@ -71,7 +74,8 @@ variable "sharding" {
})
default = {
shards = {
replicas = 2
replicas = 1
quantity = 2
}
router = {
replicas = 1
Expand All @@ -88,22 +92,22 @@ variable "resources" {
shards = optional(object({
limits = optional(map(string))
requests = optional(map(string))
}))
}), null)

arbiter = optional(object({
limits = optional(map(string))
requests = optional(map(string))
}))
}), null)

configsvr = optional(object({
limits = optional(map(string))
requests = optional(map(string))
}))
}), null)

router = optional(object({
limits = optional(map(string))
requests = optional(map(string))
}))
}), null)
})
default = null
}
Expand Down Expand Up @@ -160,18 +164,8 @@ variable "security_context" {
}
}

# variable "mtls" {
# description = "Whether to deploy MongoDB with mTLS"
# type = bool
# default = false
# validation {
# condition = !var.mtls
# error_message = "For now, 'mTLSEnabled' must be false as mTLS is not supported yet"
# }
# }

variable "timeout" {
description = "Timeout limit in seconds per replica for the helm release creation"
description = "Timeout limit in seconds per replica (shards.quantity/) for the helm release creation"
type = number
default = 480 # 8 minutes
}
Expand Down

0 comments on commit 7a399a0

Please sign in to comment.