From f4aadf711c33a1b07063159eeda871ea4d0b61c1 Mon Sep 17 00:00:00 2001 From: Daniel De Vera Date: Tue, 12 Aug 2025 14:46:44 -0300 Subject: [PATCH] Use K8S depedent env vars instead of custom ExpandNamespace --- k8s/base/driver.yaml | 10 +++++----- k8s/base/frontend.yaml | 10 +++++----- k8s/base/location.yaml | 8 ++++---- k8s/base/route.yaml | 4 ++-- pkg/config/kafka.go | 2 +- pkg/config/location.go | 2 +- pkg/config/mysql.go | 2 +- pkg/config/namespace.go | 13 ------------- pkg/config/otel.go | 2 +- pkg/config/redis.go | 2 +- pkg/config/route.go | 2 +- 11 files changed, 22 insertions(+), 35 deletions(-) delete mode 100644 pkg/config/namespace.go diff --git a/k8s/base/driver.yaml b/k8s/base/driver.yaml index 4443dfde..0c2777bd 100644 --- a/k8s/base/driver.yaml +++ b/k8s/base/driver.yaml @@ -32,17 +32,17 @@ spec: fieldPath: metadata.namespace - name: SIGNADOT_BASELINE_NAME value: "driver" - # service dependencies ( get replaced at runtime by the app) + # service dependencies - name: SIGNADOT_ROUTESERVER value: routeserver.signadot.svc:7777 - name: ROUTE_ADDR - value: route.:8083 + value: route.$(SIGNADOT_BASELINE_NAMESPACE):8083 - name: REDIS_ADDR - value: redis.:6379 + value: redis.$(SIGNADOT_BASELINE_NAMESPACE):6379 - name: KAFKA_BROKER_ADDR - value: kafka-headless.:9092 + value: kafka-headless.$(SIGNADOT_BASELINE_NAMESPACE):9092 - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://jaeger.:4318 + value: http://jaeger.$(SIGNADOT_BASELINE_NAMESPACE):4318 image: signadot/hotrod:latest imagePullPolicy: Always readinessProbe: diff --git a/k8s/base/frontend.yaml b/k8s/base/frontend.yaml index 6c2ff03d..d01cf355 100644 --- a/k8s/base/frontend.yaml +++ b/k8s/base/frontend.yaml @@ -32,15 +32,15 @@ spec: fieldPath: metadata.namespace - name: SIGNADOT_BASELINE_NAME value: "frontend" - # service dependencies ( get replaced at runtime by the app) + # service dependencies - name: LOCATION_ADDR - value: location.:8081 + value: location.$(SIGNADOT_BASELINE_NAMESPACE):8081 - name: REDIS_ADDR - value: redis.:6379 + value: redis.$(SIGNADOT_BASELINE_NAMESPACE):6379 - name: KAFKA_BROKER_ADDR - value: kafka-headless.:9092 + value: kafka-headless.$(SIGNADOT_BASELINE_NAMESPACE):9092 - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://jaeger.:4318 + value: http://jaeger.$(SIGNADOT_BASELINE_NAMESPACE):4318 image: signadot/hotrod:latest imagePullPolicy: Always ports: diff --git a/k8s/base/location.yaml b/k8s/base/location.yaml index 10d53b43..8bdf45e8 100644 --- a/k8s/base/location.yaml +++ b/k8s/base/location.yaml @@ -31,15 +31,15 @@ spec: fieldPath: metadata.namespace - name: SIGNADOT_BASELINE_NAME value: location - # service dependencies ( get replaced at runtime by the app) + # service dependencies - name: MYSQL_ADDR - value: mysql.:3306 + value: mysql.$(SIGNADOT_BASELINE_NAMESPACE):3306 - name: MYSQL_PASS value: abc - name: REDIS_ADDR - value: redis.:6379 + value: redis.$(SIGNADOT_BASELINE_NAMESPACE):6379 - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://jaeger.:4318 + value: http://jaeger.$(SIGNADOT_BASELINE_NAMESPACE):4318 image: signadot/hotrod:latest imagePullPolicy: Always ports: diff --git a/k8s/base/route.yaml b/k8s/base/route.yaml index 356c99ec..9ddef1a1 100644 --- a/k8s/base/route.yaml +++ b/k8s/base/route.yaml @@ -33,9 +33,9 @@ spec: value: "route" # service dependencies - name: REDIS_ADDR - value: redis.:6379 + value: redis.$(SIGNADOT_BASELINE_NAMESPACE):6379 - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://jaeger.:4318 + value: http://jaeger.$(SIGNADOT_BASELINE_NAMESPACE):4318 image: signadot/hotrod:latest imagePullPolicy: Always ports: diff --git a/pkg/config/kafka.go b/pkg/config/kafka.go index c5a5af39..7738f5ac 100644 --- a/pkg/config/kafka.go +++ b/pkg/config/kafka.go @@ -1,7 +1,7 @@ package config func GetKafkaBrokerAddr() string { - return ExpandNamespace(EnvDefault("KAFKA_BROKER_ADDR", "kafka-headless:9092")) + return EnvDefault("KAFKA_BROKER_ADDR", "kafka-headless:9092") } func GetKafkaBrokers() []string { diff --git a/pkg/config/location.go b/pkg/config/location.go index 1a3ca49b..4d81d2eb 100644 --- a/pkg/config/location.go +++ b/pkg/config/location.go @@ -5,5 +5,5 @@ func GetLocationBindPort() string { } func GetLocationAddr() string { - return ExpandNamespace(EnvDefault("LOCATION_ADDR", "location:8081")) + return EnvDefault("LOCATION_ADDR", "location:8081") } diff --git a/pkg/config/mysql.go b/pkg/config/mysql.go index 77aacf8b..0e5e8c5f 100644 --- a/pkg/config/mysql.go +++ b/pkg/config/mysql.go @@ -6,7 +6,7 @@ import ( ) func GetMySQLAddr() string { - return ExpandNamespace(EnvDefault("MYSQL_ADDR", "mysql:3306")) + return EnvDefault("MYSQL_ADDR", "mysql:3306") } func GetMySQLUser() string { diff --git a/pkg/config/namespace.go b/pkg/config/namespace.go deleted file mode 100644 index 50caf142..00000000 --- a/pkg/config/namespace.go +++ /dev/null @@ -1,13 +0,0 @@ -package config - -import ( - "strings" -) - -func GetNamespace() string { - return EnvDefault("SIGNADOT_BASELINE_NAMESPACE", "hotrod") -} - -func ExpandNamespace(v string) string { - return strings.ReplaceAll(v, "", GetNamespace()) -} diff --git a/pkg/config/otel.go b/pkg/config/otel.go index 9aa31be8..cad66a6f 100644 --- a/pkg/config/otel.go +++ b/pkg/config/otel.go @@ -13,5 +13,5 @@ func InitOtelExporter() { if addr == "" { return } - os.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", ExpandNamespace(addr)) + os.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", addr) } diff --git a/pkg/config/redis.go b/pkg/config/redis.go index 2ea20b92..5bd61adb 100644 --- a/pkg/config/redis.go +++ b/pkg/config/redis.go @@ -1,7 +1,7 @@ package config func GetRedisAddr() string { - return ExpandNamespace(EnvDefault("REDIS_ADDR", "redis:6379")) + return EnvDefault("REDIS_ADDR", "redis:6379") } func GetRedisPassword() string { diff --git a/pkg/config/route.go b/pkg/config/route.go index 6b2d8487..bb215bd0 100644 --- a/pkg/config/route.go +++ b/pkg/config/route.go @@ -6,7 +6,7 @@ import ( ) func GetRouteAddr() string { - return ExpandNamespace(EnvDefault("ROUTE_ADDR", "route:8083")) + return EnvDefault("ROUTE_ADDR", "route:8083") } func GetRouteBindPort() string {