From fcdcb0102d88f52fb25d59c50ca5994ea8b49f8a Mon Sep 17 00:00:00 2001 From: pierre Date: Tue, 6 May 2025 12:00:37 +0100 Subject: [PATCH] find a way to connect to another namespace without conflict found yet --- module.tf | 66 +++++++++++++++++++++++++++---------------- variables.auto.tfvars | 34 ++++++++++++++++++---- 2 files changed, 69 insertions(+), 31 deletions(-) diff --git a/module.tf b/module.tf index 47055fc..cf5be14 100644 --- a/module.tf +++ b/module.tf @@ -30,27 +30,30 @@ variable "kubernetes" { }) })) }))) - replicas = optional(number, 1) - namespace = optional(string) - block_namespace_creation = optional(bool, false) - service_port = optional(number) - service_type = optional(string, "ClusterIP") - service_name = optional(string) - liveness_tcp_socket = optional(number) - liveness_http_get = optional(string) - liveness_http_get_path = optional(string) - database = optional(map(string)) - redis = optional(map(string)) - enabled = optional(bool, true) - secret_ref = optional(list(string)) - config_map_ref = optional(list(string)) - extra_manifest = optional(list(string)) - requirements = optional(map(string), { - limits-cpu = "800m" - limits-memory = "500Mi" - requests-cpu = "200m" - requests-memory = "200Mi" - }) + replicas = optional(number, 1) + namespace = optional(string) + connected_namespace = optional(string, "") +# namespace = optional(string,coalesce(connected_namespace,"")) + #block_namespace_creation = optional(bool, false) + service_port = optional(number) + service_type = optional(string, "ClusterIP") + service_name = optional(string) + liveness_tcp_socket = optional(number) + liveness_http_get = optional(string) + liveness_http_get_path = optional(string) + database = optional(map(string)) + redis = optional(map(string)) + enabled = optional(bool, true) + secret_ref = optional(list(string)) + config_map_ref = optional(list(string)) + extra_manifest = optional(list(string)) + requirements = optional(map(string)) + # requirements = optional(map(string), { + # limits-cpu = "800m" + # limits-memory = "500Mi" + # requests-cpu = "200m" + # requests-memory = "200Mi" + # }) environment_variables = optional(map(string), { name = "value" }) })) @@ -85,8 +88,8 @@ locals { data "kubernetes_all_namespaces" "allns" {} resource "kubernetes_namespace" "automatic" { - # for_each = { for key, value in var.kubernetes : key => value if value.enabled == true && !(value.block_namespace_creation) } - for_each = { for key, value in var.kubernetes : key => value if value.enabled == true } + # for_each = { for key, value in var.kubernetes : key => value if value.enabled == true && !(value.block_namespace_creation) } + for_each = { for key, value in var.kubernetes : key => value if value.enabled == true && value.connected_namespace == "" } metadata { annotations = { name = coalesce(each.value.namespace, each.key) @@ -187,7 +190,7 @@ resource "kubernetes_service" "automatic_service" { for_each = { for key, value in var.kubernetes : key => value if value.service_port != null && value.enabled == true } metadata { name = "${each.key}-svc" - namespace = coalesce(each.value.namespace, each.key) + namespace = coalesce(each.value.namespace,each.value.connected_namespace, each.key) labels = { deployment_method = "Terraform" } @@ -264,7 +267,7 @@ resource "kubernetes_service" "automatic_service_redis" { resource "kubernetes_deployment_v1" "automatic" { for_each = { for key, value in var.kubernetes : key => value if value.enabled == true } metadata { - namespace = coalesce(each.value.namespace, each.key) + namespace = coalesce(each.value.namespace,each.value.connected_namespace, each.key) name = coalesce(each.value.name, each.key) labels = { @@ -357,7 +360,20 @@ resource "kubernetes_deployment_v1" "automatic" { } } + dynamic "resources" { + for_each = each.value.requirements != null ? [1] : [] + content { + limits = { + cpu = each.value.requirements.limits-cpu + memory = each.value.requirements.limits-memory + } + requests = { + cpu = each.value.requirements.requests-cpu + memory = each.value.requirements.requests-memory + } + } + } # resources { # limits = { diff --git a/variables.auto.tfvars b/variables.auto.tfvars index a0fa3ce..10d22f5 100644 --- a/variables.auto.tfvars +++ b/variables.auto.tfvars @@ -86,9 +86,9 @@ kubernetes = { } } requirements = { - limits-cpu = "900m" - limits-memory = "600Mi" - requests-cpu = "300m" + limits-cpu = "1000m" + limits-memory = "1Gi" + requests-cpu = "500m" requests-memory = "400Mi" } pvc = { @@ -134,7 +134,7 @@ kubernetes = { stash = { - enabled = false + # enabled = false replicas = 0 name = "stash" image = "stashapp/stash:latest" @@ -349,7 +349,7 @@ kubernetes = { paper = { - # enabled = false + enabled = false namespace = "paper" image = "ghcr.io/paperless-ngx/paperless-ngx:latest" service_port = 8000 @@ -468,7 +468,7 @@ kubernetes = { } } gotenberg = { - # enabled = false + enabled = false name = "gotenberg" namespace = "paper" block_namespace_creation = true @@ -761,4 +761,26 @@ kubernetes = { } } + jobspy = { + enabled = false + connected_namespace = "stash" + image = "rainmanjam/jobspy-api:latest" + service_port = 8000 + environment = { + ENABLE_API_KEY_AUTH = { + value = "true" + } + API_KEYS = { + value = "true" + } + } + requirements = { + limits-cpu = "900m" + limits-memory = "600Mi" + requests-cpu = "300m" + requests-memory = "400Mi" + } + + } + }