From 8ed1b104cea39856a51b67d31c6782031c89f642 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 9 Sep 2025 08:48:34 -0700 Subject: [PATCH] =?UTF-8?q?WEED=5FCLUSTER=5FSW=5F*=20Environment=20Variabl?= =?UTF-8?q?es=20should=20not=20be=20passed=20to=20allIn=E2=80=A6=20(#7217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * WEED_CLUSTER_SW_* Environment Variables should not be passed to allInOne config * address comment * address comments Fixed filtering logic: Replaced specific key matching with regex patterns that catch ALL WEED_CLUSTER_*_MASTER and WEED_CLUSTER_*_FILER variables: } Corrected merge precedence: Fixed the merge order so global environment variables properly override allInOne variables: * refactoring --- .../all-in-one/all-in-one-deployment.yaml | 15 ++++++++++++ .../seaweedfs/templates/shared/_helpers.tpl | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/k8s/charts/seaweedfs/templates/all-in-one/all-in-one-deployment.yaml b/k8s/charts/seaweedfs/templates/all-in-one/all-in-one-deployment.yaml index 86bb45a8e..8700a8a69 100644 --- a/k8s/charts/seaweedfs/templates/all-in-one/all-in-one-deployment.yaml +++ b/k8s/charts/seaweedfs/templates/all-in-one/all-in-one-deployment.yaml @@ -79,6 +79,12 @@ spec: image: {{ template "master.image" . }} imagePullPolicy: {{ default "IfNotPresent" .Values.global.imagePullPolicy }} env: + {{- /* Determine default cluster alias and the corresponding env var keys to avoid conflicts */}} + {{- $envMerged := merge (.Values.global.extraEnvironmentVars | default dict) (.Values.allInOne.extraEnvironmentVars | default dict) }} + {{- $clusterDefault := default "sw" (index $envMerged "WEED_CLUSTER_DEFAULT") }} + {{- $clusterUpper := upper $clusterDefault }} + {{- $clusterMasterKey := printf "WEED_CLUSTER_%s_MASTER" $clusterUpper }} + {{- $clusterFilerKey := printf "WEED_CLUSTER_%s_FILER" $clusterUpper }} - name: POD_IP valueFrom: fieldRef: @@ -95,6 +101,7 @@ spec: value: "{{ template "seaweedfs.name" . }}" {{- if .Values.allInOne.extraEnvironmentVars }} {{- range $key, $value := .Values.allInOne.extraEnvironmentVars }} + {{- if and (ne $key $clusterMasterKey) (ne $key $clusterFilerKey) }} - name: {{ $key }} {{- if kindIs "string" $value }} value: {{ $value | quote }} @@ -104,8 +111,10 @@ spec: {{- end }} {{- end }} {{- end }} + {{- end }} {{- if .Values.global.extraEnvironmentVars }} {{- range $key, $value := .Values.global.extraEnvironmentVars }} + {{- if and (ne $key $clusterMasterKey) (ne $key $clusterFilerKey) }} - name: {{ $key }} {{- if kindIs "string" $value }} value: {{ $value | quote }} @@ -115,6 +124,12 @@ spec: {{- end }} {{- end }} {{- end }} + {{- end }} + # Inject computed cluster endpoints for the default cluster + - name: {{ $clusterMasterKey }} + value: {{ include "seaweedfs.cluster.masterAddress" . | quote }} + - name: {{ $clusterFilerKey }} + value: {{ include "seaweedfs.cluster.filerAddress" . | quote }} command: - "/bin/sh" - "-ec" diff --git a/k8s/charts/seaweedfs/templates/shared/_helpers.tpl b/k8s/charts/seaweedfs/templates/shared/_helpers.tpl index 404981976..d22d14224 100644 --- a/k8s/charts/seaweedfs/templates/shared/_helpers.tpl +++ b/k8s/charts/seaweedfs/templates/shared/_helpers.tpl @@ -222,3 +222,27 @@ or generate a new random password if it doesn't exist. {{- randAlphaNum $length -}} {{- end -}} {{- end -}} + +{{/* +Compute the master service address to be used in cluster env vars. +If allInOne is enabled, point to the all-in-one service; otherwise, point to the master service. +*/}} +{{- define "seaweedfs.cluster.masterAddress" -}} +{{- $serviceNameSuffix := "-master" -}} +{{- if .Values.allInOne.enabled -}} +{{- $serviceNameSuffix = "-all-in-one" -}} +{{- end -}} +{{- printf "%s%s.%s:%d" (include "seaweedfs.name" .) $serviceNameSuffix .Release.Namespace (int .Values.master.port) -}} +{{- end -}} + +{{/* +Compute the filer service address to be used in cluster env vars. +If allInOne is enabled, point to the all-in-one service; otherwise, point to the filer-client service. +*/}} +{{- define "seaweedfs.cluster.filerAddress" -}} +{{- $serviceNameSuffix := "-filer-client" -}} +{{- if .Values.allInOne.enabled -}} +{{- $serviceNameSuffix = "-all-in-one" -}} +{{- end -}} +{{- printf "%s%s.%s:%d" (include "seaweedfs.name" .) $serviceNameSuffix .Release.Namespace (int .Values.filer.port) -}} +{{- end -}}