diff --git a/.ci/tests/integration/cases/global-and-namespaced-config/manifests.yaml b/.ci/tests/integration/cases/global-and-namespaced-config/manifests.yaml index d298d20c..9bf4ea09 100644 --- a/.ci/tests/integration/cases/global-and-namespaced-config/manifests.yaml +++ b/.ci/tests/integration/cases/global-and-namespaced-config/manifests.yaml @@ -15,6 +15,10 @@ spec: topics: - persistent://public/default/input-java-topic typeClassName: java.lang.String + pod: + env: + - name: "podenv" + value: "podvalue" output: topic: persistent://public/default/output-java-topic typeClassName: java.lang.String diff --git a/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml b/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml index e4d48787..f691f91f 100644 --- a/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml +++ b/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml @@ -7,6 +7,7 @@ spec: env: namespaced1: namespacedvalue1 shared1: fromnamespace + podenv: backendconfigvalue pod: liveness: initialDelaySeconds: 30 diff --git a/.ci/tests/integration/cases/global-and-namespaced-config/verify.sh b/.ci/tests/integration/cases/global-and-namespaced-config/verify.sh index 1363b0d9..ad32acd6 100644 --- a/.ci/tests/integration/cases/global-and-namespaced-config/verify.sh +++ b/.ci/tests/integration/cases/global-and-namespaced-config/verify.sh @@ -48,6 +48,15 @@ if [ $? -ne 0 ]; then exit 1 fi +# if the function defines the same env, it will use the value from the function instead of the backend config +verify_env_result=$(ci::verify_env "function-sample-env" podenv podenv=podvalue 2>&1) +if [ $? -ne 0 ]; then + echo "$verify_env_result" + kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1 + kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true + exit 1 +fi + verify_env_result=$(ci::verify_env "function-sample-env" global1 global1=globalvalue1 2>&1) if [ $? -ne 0 ]; then echo "$verify_env_result" diff --git a/controllers/spec/common.go b/controllers/spec/common.go index 25ca428e..5a2915d0 100644 --- a/controllers/spec/common.go +++ b/controllers/spec/common.go @@ -341,10 +341,7 @@ func PatchStatefulSet(ctx context.Context, cli client.Client, namespace string, } // merge env - if len(envData) == 0 { - return globalBackendConfigVersion, namespacedBackendConfigVersion, nil - } - globalEnvs := make([]corev1.EnvVar, 0, len(envData)) + var globalEnvs []corev1.EnvVar for key, val := range envData { globalEnvs = append(globalEnvs, corev1.EnvVar{ Name: key, @@ -353,7 +350,9 @@ func PatchStatefulSet(ctx context.Context, cli client.Client, namespace string, } for i := range statefulSet.Spec.Template.Spec.Containers { container := &statefulSet.Spec.Template.Spec.Containers[i] - container.Env = append(container.Env, globalEnvs...) + if globalEnvs != nil { + container.Env = append(globalEnvs, container.Env...) + } // configs which only work for the workload container switch container.Name {